Skip to content

Commit

Permalink
[RNMobile] Enable Dismiss on PlainText in Android (#20095)
Browse files Browse the repository at this point in the history
* Add flag for determining if running on Android

* Enable Dismiss button on PlainText. Enable show keyboard in Android on PlainText mount

* Enable Dismiss button on PlainText. Enable show keyboard in Android on PlainText mount
  • Loading branch information
chipsnyder authored Feb 7, 2020
1 parent 49e109c commit fac5718
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions packages/block-editor/src/components/plain-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +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();
}
Expand Down

0 comments on commit fac5718

Please sign in to comment.