Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNmobile] Bring Placeholder text back working on Heading blocks #14404

Merged
16 changes: 2 additions & 14 deletions packages/block-editor/src/components/rich-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,30 +501,18 @@ export class RichText extends Component {
style,
formattingControls,
isSelected,
sendEmptyTag,
} = this.props;

const record = this.getRecord();
// Save back to HTML from React tree
const value = this.valueToFormat( record );
let html = `<${ tagName }>${ value }</${ tagName }>`;
// We need to check if the value is undefined or empty, and then assign it properly otherwise the placeholder is not visible

if ( value === undefined || value === '' ) {
// PR for placeholder fix https://github.com/WordPress/gutenberg/pull/13699/
// has introduced heading issue on Android https://github.com/wordpress-mobile/gutenberg-mobile/issues/627
// ( If a new heading block is created on Android device
// it will be without default formatting ( <h2> currently ) ) .
// Fix for heading issue is to skip reset of html variable if tag is heading and platform is Android.
// This fix will intentionally introduce original issue with placeholder (on Android)
// which has lower priority then heading issue .
// New issue is raised : https://github.com/wordpress-mobile/gutenberg-mobile/issues/707
if ( ! sendEmptyTag ) {
html = '';
}

html = '';
this.lastEventCount = undefined; // force a refresh on the native side
}

let minHeight = styles[ 'editor-rich-text' ].minHeight;
if ( style && style.minHeight ) {
minHeight = style.minHeight;
Expand Down
11 changes: 6 additions & 5 deletions packages/block-library/src/heading/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import { Component } from '@wordpress/element';
import { RichText, BlockControls } from '@wordpress/block-editor';
import { createBlock } from '@wordpress/blocks';

import styles from './editor.scss';

const name = 'core/heading';

class HeadingEdit extends Component {
constructor( props ) {
super( props );

this.splitBlock = this.splitBlock.bind( this );
this.isAndroid = Platform.OS === 'android';
}

/**
Expand Down Expand Up @@ -94,17 +95,17 @@ class HeadingEdit extends Component {
tagName={ tagName }
value={ content }
isSelected={ this.props.isSelected }
style={ style }
style={ {
...style,
minHeight: styles['wp-block-heading'].minHeight,
} }
onFocus={ this.props.onFocus } // always assign onFocus as a props
onBlur={ this.props.onBlur } // always assign onBlur as a props
onCaretVerticalPositionChange={ this.props.onCaretVerticalPositionChange }
onChange={ ( value ) => setAttributes( { content: value } ) }
onMerge={ mergeBlocks }
onSplit={ this.splitBlock }
placeholder={ placeholder || __( 'Write heading…' ) }
// Fix for heading issue on Android https://github.com/wordpress-mobile/gutenberg-mobile/issues/627
// Intentionally introduces missing pleceholder issue on Android https://github.com/wordpress-mobile/gutenberg-mobile/issues/707
sendEmptyTag={ this.isAndroid }
/>
</View>
);
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/heading/editor.native.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

.wp-block-heading {
min-height: $min-height-heading;
}