question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onSubmitEditing event is firing twice on android

See original GitHub issue

Issue 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:closed
  • Created 7 years ago
  • Reactions:15
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
rangavcommented, Jan 21, 2017

setting blurOnSubmit={false} worked for me on android

1reaction
renewebcommented, Nov 13, 2016

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:

  • We pass the actionId to the JS side, such that the user can filter based on that. This would still leave it inconsistent to IOS and rather unintuitive, since there would still be two calls.
  • We filter on the Android side and only fire 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found