Skip to content
Merged
Changes from all 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
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