-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RNMobile] Enable Dismiss on PlainText in Android #20095
Merged
chipsnyder
merged 3 commits into
rnmobile/release-v1.22.0
from
rnmobile/1864-shortcode-keyboard
Feb 7, 2020
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the hide keyboard button is selected componentDidUpdate is called with the changes of isSelected toggling from true to false the is iOS flag here was preventing android from getting the blur call to dismiss the keyboard |
||
if ( ! this.props.isSelected && prevProps.isSelected ) { | ||
this._input.blur(); | ||
} | ||
} | ||
|
||
componentWillUnmount() { | ||
if ( this.isAndroid ) { | ||
clearTimeout( this.timeoutID ); | ||
} | ||
} | ||
|
||
focus() { | ||
this._input.focus(); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Android TextInput has a bug where the keyboard doesn't pop when autoselecting a view in componentDidMount. to get around this a small timeout is set. This is an issue with ReactNative that seems to be opened then closed multiple times due to inactivity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think that this is a core Android bug where you can't focus an EditText if the view isn't active, so you need to wait with a timeout 😄