Skip to content

Commit

Permalink
Avoid to reset html to empty string if block is heading and platform …
Browse files Browse the repository at this point in the history
…is android (#14301)

* Avoid to reset html to empty string if block is heading on android platform

* Send empty tag flag from heading block to RichText
  • Loading branch information
marecar3 authored and hypest committed Mar 8, 2019
1 parent eb59a11 commit 60fbafb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
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

0 comments on commit 60fbafb

Please sign in to comment.