From 6c9110f19f5c85492863a55ce7dbb07c68f78d07 Mon Sep 17 00:00:00 2001 From: Chip Snyder Date: Fri, 7 Feb 2020 08:01:17 -0500 Subject: [PATCH 1/3] Add flag for determining if running on Android --- packages/block-editor/src/components/plain-text/index.native.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/block-editor/src/components/plain-text/index.native.js b/packages/block-editor/src/components/plain-text/index.native.js index aeebb66b567d2a..651f69600c359f 100644 --- a/packages/block-editor/src/components/plain-text/index.native.js +++ b/packages/block-editor/src/components/plain-text/index.native.js @@ -17,6 +17,7 @@ export default class PlainText extends Component { constructor() { super( ...arguments ); this.isIOS = Platform.OS === 'ios'; + this.isAndroid = Platform.OS === 'android'; } componentDidMount() { From ca7e0274a6257801688e37733822ec508f55b7f5 Mon Sep 17 00:00:00 2001 From: Chip Snyder Date: Fri, 7 Feb 2020 08:41:31 -0500 Subject: [PATCH 2/3] Enable Dismiss button on PlainText. Enable show keyboard in Android on PlainText mount --- .../src/components/plain-text/index.native.js | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/components/plain-text/index.native.js b/packages/block-editor/src/components/plain-text/index.native.js index 651f69600c359f..51586c9659acc6 100644 --- a/packages/block-editor/src/components/plain-text/index.native.js +++ b/packages/block-editor/src/components/plain-text/index.native.js @@ -16,26 +16,39 @@ import styles from './style.scss'; export default class PlainText extends Component { constructor() { super( ...arguments ); - this.isIOS = Platform.OS === 'ios'; this.isAndroid = Platform.OS === 'android'; } 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(); + if ( this._input.isFocused() === false && this.props.isSelected ) { + if ( this.isAndroid ) { + /* + * There seems to be an issue in React Native where the keyboard doesn't show if called shortly after rendering. + * As a common work around this delay is used. + * https://github.com/facebook/react-native/issues/19366#issuecomment-400603928 + */ + this.timeoutID = setTimeout( () => { + this._input.focus(); + }, 100 ); + } else { + this._input.focus(); + } } } componentDidUpdate( prevProps ) { - if ( ! this.props.isSelected && prevProps.isSelected && this.isIOS ) { + if ( ! this.props.isSelected && prevProps.isSelected ) { this._input.blur(); } } + componentWillUnmount() { + if ( this.isAndroid ) { + clearTimeout(this.timeoutID); + } + } + focus() { this._input.focus(); } From fe72b229529227218fff89b7464abdda1ad19853 Mon Sep 17 00:00:00 2001 From: Chip Snyder Date: Fri, 7 Feb 2020 08:41:31 -0500 Subject: [PATCH 3/3] Enable Dismiss button on PlainText. Enable show keyboard in Android on PlainText mount --- packages/block-editor/src/components/plain-text/index.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/plain-text/index.native.js b/packages/block-editor/src/components/plain-text/index.native.js index 51586c9659acc6..9ddb1fba7465c1 100644 --- a/packages/block-editor/src/components/plain-text/index.native.js +++ b/packages/block-editor/src/components/plain-text/index.native.js @@ -45,7 +45,7 @@ export default class PlainText extends Component { componentWillUnmount() { if ( this.isAndroid ) { - clearTimeout(this.timeoutID); + clearTimeout( this.timeoutID ); } }