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

Avoid to reset html to empty string if block is heading and platform is android #14301

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/block-library/src/heading/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import HeadingToolbar from './heading-toolbar';
/**
* External dependencies
*/
import { View } from 'react-native';
import { View, Platform } from 'react-native';

/**
* WordPress dependencies
Expand All @@ -23,6 +23,7 @@ class HeadingEdit extends Component {
super( props );

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

/**
Expand Down Expand Up @@ -101,6 +102,9 @@ class HeadingEdit extends Component {
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
15 changes: 14 additions & 1 deletion packages/editor/src/components/rich-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,15 +496,28 @@ 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 === '' ) {
html = '';
// 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 = '';
}

this.lastEventCount = undefined; // force a refresh on the native side
}
let minHeight = 0;
Expand Down