onSubmitEditing event is firing twice on android
See original GitHub issueIssue Description
onSubmitEditing event is firing twice on android.
Steps to Reproduce / Code Snippets
Create the following code:
_onChangeText(text) {
this.setState({
text
});
}
_onSubmit(event) {
this.props.onSubmit(this.state.text);
}
<TextInput
ref='txtSearch'
maxLength={20}
returnKeyType='search'
placeholder={'Search here'}
underlineColorAndroid='rgba(0,0,0,0)'
onChangeText={text => this._onChangeText(text)}
onSubmitEditing={event => this._onSubmit(event)}></TextInput>
Then, tap on the field, type something and tap the search button on keyboard.
Expected Results
On iOS it works perfectly (the _onSubmit method is called only one time) but on Android it is calling two times.
Additional Information
- React Native version: 0.35.0
- Platform(s) (iOS, Android, or both?): Android
- Operating System (macOS, Linux, or Windows?): macOS
Issue Analytics
- State:
- Created 7 years ago
- Reactions:15
- Comments:12 (1 by maintainers)
Top Results From Across the Web
onSubmitEditing is called twice when keyboard is dismissed
I want to get current text from TextInput when keyboard is dismissed by pressing search button. In order to get the text, I...
Read more >UICamera.onClick firing twice on Android
All UICamera.onClick events appear to be firing twice within the same frame. This issue popped up when debugging a new button press and...
Read more >TextInput - React Native
A foundational component for inputting text into the app via a keyboard. Props provide configurability for several features, ...
Read more >OnSubmitEditing is not firing nor is onEndEditing-React Native
Coding example for the question OnSubmitEditing is not firing nor is onEndEditing-React Native.
Read more >Onsubmitediting react native. We are going to use these ...
will not be applied if multiline=true onSubmitEditing event is firing twice on android · Issue #10443 · facebook/react-native · GitHub New issue ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
setting blurOnSubmit={false} worked for me on android
The problem is that Android fires two
EditorAction
events when pressing the search button. It will fire one for the enter/submit action and another one for search action (https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java#L695). In Android these will have different id’s (actionId) and this can be used to filter only for the relevant events and therefore only handle the action once. However, it seems like we do not pass that information to the JS side, so there is no easy way to differentiate between these event types.Generally I see two options to fix the issue:
enter action
events from there, so we end up with only one event being fired. For this, we will need to make sure that this will work as desired in every case.I will dig a little further into the second option, as this one would create a consistent experience, and see if that works, unless, of course, someone has a better idea how to fix it.