From 2c38845fd547bb241ef0498aaca1490659fdc0f9 Mon Sep 17 00:00:00 2001 From: etoledom Date: Tue, 14 Aug 2018 11:30:59 -0600 Subject: [PATCH] block-manager: remove state.html in favor of getting the text from the TextInput component itself. --- src/block-management/block-manager.js | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/block-management/block-manager.js b/src/block-management/block-manager.js index cc1503f03ff146..057d2f1f4d5523 100644 --- a/src/block-management/block-manager.js +++ b/src/block-management/block-manager.js @@ -32,18 +32,17 @@ type PropsType = BlockListType; type StateType = { dataSource: DataSource, showHtml: boolean, - html: string, }; export default class BlockManager extends React.Component { _recycler = null; + _htmlTextInput: TextInput = null; constructor( props: PropsType ) { super( props ); this.state = { dataSource: new DataSource( this.props.blocks, ( item: BlockType ) => item.clientId ), showHtml: false, - html: '', }; } @@ -99,9 +98,8 @@ export default class BlockManager extends React.Component }, '' ); } - parseHTML() { + parseHTML( html: string ) { const { parseBlocksAction } = this.props; - const { html } = this.state; parseBlocksAction( html ); } @@ -168,20 +166,14 @@ export default class BlockManager extends React.Component } 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 } ); } - handleHTMLUpdate = ( html: string ) => { - this.setState( { html } ); - } - renderItem( value: { item: BlockType, clientId: string } ) { return ( renderHTML() { const behavior = Platform.OS === 'ios' ? 'padding' : null; + const htmlInputRef = ( el ) => this._htmlTextInput = el; return ( - - + value={ this.serializeToHtml() } /> ); }