Skip to content

Commit

Permalink
Merge pull request #148 from wordpress-mobile/fix/android-html-text-i…
Browse files Browse the repository at this point in the history
…nput

Fix Android html text input
  • Loading branch information
etoledom authored Sep 19, 2018
2 parents 776bb23 + 8bcdb5e commit f36fd5e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/block-management/block-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type StateType = {
inspectBlocks: boolean,
blockTypePickerVisible: boolean,
selectedBlockType: string,
html: string,
};

export default class BlockManager extends React.Component<PropsType, StateType> {
Expand All @@ -51,6 +52,7 @@ export default class BlockManager extends React.Component<PropsType, StateType>
inspectBlocks: false,
blockTypePickerVisible: false,
selectedBlockType: 'core/paragraph', // just any valid type to start from
html: '', // This is used to hold the Android html text input state.
};
}

Expand Down Expand Up @@ -219,7 +221,8 @@ export default class BlockManager extends React.Component<PropsType, StateType>
} }
onValueSelected={ ( itemValue ) => {
this.onBlockTypeSelected( itemValue );
} } />
} }
/>
);

return (
Expand Down Expand Up @@ -252,8 +255,8 @@ export default class BlockManager extends React.Component<PropsType, StateType>
const html = this._htmlTextInput._lastNativeText;
this.parseHTML( html );
}

this.setState( { showHtml } );
const html = this.serializeToHtml();
this.setState( { showHtml, html } );
}

handleInspectBlocksChanged = ( inspectBlocks: boolean ) => {
Expand Down Expand Up @@ -286,9 +289,16 @@ export default class BlockManager extends React.Component<PropsType, StateType>
);
}

onChangeHTML = ( html: string ) => {
if ( Platform.OS === 'android' ) {
this.setState( { html } );
}
}

renderHTML() {
const behavior = Platform.OS === 'ios' ? 'padding' : null;
const htmlInputRef = ( el ) => this._htmlTextInput = el;

return (
<KeyboardAvoidingView style={ { flex: 1 } } behavior={ behavior }>
<TextInput
Expand All @@ -297,7 +307,9 @@ export default class BlockManager extends React.Component<PropsType, StateType>
ref={ htmlInputRef }
numberOfLines={ 0 }
style={ styles.htmlView }
value={ this.serializeToHtml() } />
value={ this.state.html }
onChangeText={ ( html ) => this.onChangeHTML( html ) }
/>
</KeyboardAvoidingView>
);
}
Expand Down

0 comments on commit f36fd5e

Please sign in to comment.