Skip to content

Commit

Permalink
Merge pull request #115 from wordpress-mobile/feature/html-input-view…
Browse files Browse the repository at this point in the history
…-ux-vol02

Fix jumpy html text input on iOS
  • Loading branch information
etoledom authored Sep 10, 2018
2 parents fb6d1f3 + 5e3c1d1 commit ba7bceb
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/block-management/block-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ type StateType = {
inspectBlocks: boolean,
blockTypePickerVisible: boolean,
selectedBlockType: string,
html: string,
};

export default class BlockManager extends React.Component<PropsType, StateType> {
_htmlTextInput: TextInput = null;

constructor( props: PropsType ) {
super( props );
this.state = {
Expand All @@ -50,7 +51,6 @@ export default class BlockManager extends React.Component<PropsType, StateType>
inspectBlocks: false,
blockTypePickerVisible: false,
selectedBlockType: 'core/paragraph', // just any valid type to start from
html: '',
};
}

Expand Down Expand Up @@ -152,9 +152,8 @@ export default class BlockManager extends React.Component<PropsType, StateType>
}, '' );
}

parseHTML() {
parseHTML( html: string ) {
const { parseBlocksAction } = this.props;
const { html } = this.state;
parseBlocksAction( html );
}

Expand Down Expand Up @@ -249,11 +248,9 @@ export default class BlockManager extends React.Component<PropsType, StateType>
}

handleSwitchEditor = ( showHtml: boolean ) => {
if ( showHtml ) {
const html = this.serializeToHtml();
this.handleHTMLUpdate( html );
} else {
this.parseHTML();
if ( ! showHtml ) {
const html = this._htmlTextInput._lastNativeText;
this.parseHTML( html );
}

this.setState( { showHtml } );
Expand All @@ -263,10 +260,6 @@ export default class BlockManager extends React.Component<PropsType, StateType>
this.setState( { inspectBlocks } );
}

handleHTMLUpdate = ( html: string ) => {
this.setState( { html } );
}

renderItem( value: { item: BlockType, clientId: string } ) {
const insertHere = (
<View style={ styles.containerStyleAddHere } >
Expand Down Expand Up @@ -295,16 +288,16 @@ export default class BlockManager extends React.Component<PropsType, StateType>

renderHTML() {
const behavior = Platform.OS === 'ios' ? 'padding' : null;
const htmlInputRef = ( el ) => this._htmlTextInput = el;
return (
<KeyboardAvoidingView style={ { flex: 1 } } behavior={ behavior }>
<TextInput
textAlignVertical="top"
multiline
ref={ htmlInputRef }
numberOfLines={ 0 }
style={ styles.htmlView }
value={ this.state.html }
onChangeText={ this.handleHTMLUpdate }>
</TextInput>
value={ this.serializeToHtml() } />
</KeyboardAvoidingView>
);
}
Expand Down

0 comments on commit ba7bceb

Please sign in to comment.