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] Fix crash editing More blocks #12620

Merged
merged 4 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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
67 changes: 44 additions & 23 deletions packages/block-library/src/more/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,56 @@ import { View, Text } from 'react-native';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component } from '@wordpress/element';

/**
* Internal dependencies
*/
import { PlainText } from '@wordpress/editor';
import styles from './editor.scss';

export default function MoreEdit( props ) {
const { attributes, setAttributes, onFocus, onBlur } = props;
const { customText } = attributes;
const defaultText = __( 'Read more' );
const value = customText !== undefined ? customText : defaultText;
export default class MoreEdit extends Component {
constructor() {
super( ...arguments );
this.onChangeInput = this.onChangeInput.bind( this );

return (
<View style={ styles[ 'block-library-more__container' ] }>
<View style={ styles[ 'block-library-more__sub-container' ] }>
<Text style={ styles[ 'block-library-more__left-marker' ] }>&lt;!--</Text>
<PlainText
style={ styles[ 'block-library-more__plain-text' ] }
value={ value }
multiline={ true }
underlineColorAndroid="transparent"
onChange={ ( newValue ) => setAttributes( { customText: newValue } ) }
placeholder={ defaultText }
isSelected={ props.isSelected }
onFocus={ onFocus }
onBlur={ onBlur }
/>
<Text style={ styles[ 'block-library-more__right-marker' ] }>--&gt;</Text>
</View>
</View> );
this.state = {
defaultText: __( 'Read more' ),
};
}

onChangeInput( newValue ) {
// Set defaultText to an empty string, allowing the user to clear/replace the input field's text
this.setState( {
defaultText: '',
} );
const value = newValue.length === 0 ? undefined : newValue;
this.props.setAttributes( { customText: value } );
}

render() {
const { attributes, onFocus, onBlur } = this.props;
const { customText } = attributes;
const defaultText = __( 'Read more' );
const value = customText !== undefined ? customText : defaultText;

return (
<View style={ styles[ 'block-library-more__container' ] }>
<View style={ styles[ 'block-library-more__sub-container' ] }>
<Text style={ styles[ 'block-library-more__left-marker' ] }>&lt;!--</Text>
<PlainText
style={ styles[ 'block-library-more__plain-text' ] }
value={ value }
multiline={ true }
underlineColorAndroid="transparent"
onChange={ this.onChangeInput }
placeholder={ defaultText }
isSelected={ this.props.isSelected }
onFocus={ onFocus }
onBlur={ onBlur }
/>
<Text style={ styles[ 'block-library-more__right-marker' ] }>--&gt;</Text>
</View>
</View> );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super minor but ); could be on a new line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved! Even though I checked this PR with the lint-js task and didn't find anything wrong.

}
}
6 changes: 4 additions & 2 deletions packages/editor/src/components/plain-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ export default class PlainText extends Component {
render() {
return (
<TextInput
{ ...this.props }
ref={ ( x ) => this._input = x }
className={ [ styles[ 'editor-plain-text' ], this.props.className ] }
onChangeText={ ( text ) => this.props.onChange( text ) }
onChange={ ( event ) => {
this.props.onChange( event.nativeEvent.text );
} }
onFocus={ this.props.onFocus } // always assign onFocus as a props
onBlur={ this.props.onBlur } // always assign onBlur as a props
{ ...this.props }
/>
);
}
Expand Down