Skip to content

Commit

Permalink
block-manager: remove state.html in favor of getting the text from th…
Browse files Browse the repository at this point in the history
…e TextInput component itself.
  • Loading branch information
etoledom committed Aug 14, 2018
1 parent 1b79efb commit 2c38845
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/block-management/block-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,17 @@ type PropsType = BlockListType;
type StateType = {
dataSource: DataSource,
showHtml: boolean,
html: string,
};

export default class BlockManager extends React.Component<PropsType, StateType> {
_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: '',
};
}

Expand Down Expand Up @@ -99,9 +98,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 @@ -168,20 +166,14 @@ 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 } );
}

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

renderItem( value: { item: BlockType, clientId: string } ) {
return (
<BlockHolder
Expand All @@ -198,16 +190,15 @@ 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
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 2c38845

Please sign in to comment.