Skip to content

Commit

Permalink
Revert "Remove the call that does blur the undelying native compone…
Browse files Browse the repository at this point in the history
…nt (#12946)

* Revert "Remove the call that does `blur` the undelying native component when deselecting RichText or PlainText. (#12886)"

This reverts commit d9fe45e.

* Blur only if it is iOS

* Fix imports
  • Loading branch information
pinarol authored Dec 18, 2018
1 parent 06f3cd5 commit b208ea4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/editor/src/components/plain-text/index.native.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { TextInput } from 'react-native';
import { TextInput, Platform } from 'react-native';

/**
* WordPress dependencies
Expand All @@ -14,13 +14,21 @@ import { Component } from '@wordpress/element';
import styles from './style.scss';

export default class PlainText extends Component {
isIOS: boolean = Platform.OS === 'ios';

componentDidMount() {
// if isSelected is true, we should request the focus on this TextInput
if ( ( this._input.isFocused() === false ) && ( this._input.props.isSelected === true ) ) {
this.focus();
}
}

componentDidUpdate( prevProps ) {
if ( ! this.props.isSelected && prevProps.isSelected && this.isIOS ) {
this._input.blur();
}
}

focus() {
this._input.focus();
}
Expand Down
6 changes: 5 additions & 1 deletion packages/editor/src/components/rich-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import RCTAztecView from 'react-native-aztec';
import { View } from 'react-native';
import { View, Platform } from 'react-native';
import {
forEach,
merge,
Expand Down Expand Up @@ -64,6 +64,8 @@ export function getFormatValue( formatName ) {
}

export class RichText extends Component {
isIOS: boolean = Platform.OS === 'ios';

constructor() {
super( ...arguments );
this.onChange = this.onChange.bind( this );
Expand Down Expand Up @@ -292,6 +294,8 @@ export class RichText extends Component {
componentDidUpdate( prevProps ) {
if ( this.props.isSelected && ! prevProps.isSelected ) {
this._editor.focus();
} else if ( ! this.props.isSelected && prevProps.isSelected && this.isIOS ) {
this._editor.blur();
}
}

Expand Down

0 comments on commit b208ea4

Please sign in to comment.