Skip to content
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

TextInput: Avoid firing onSubmitEditing twice on Android #11006

Closed
wants to merge 1 commit into from

Conversation

reneweb
Copy link
Contributor

@reneweb reneweb commented Nov 18, 2016

For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes #10443

Test plan

  1. Create view with TextInput having 'go', 'search' or 'send as returnKeyType
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>


         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
  1. Input some text and click submit button in soft keyboard
  2. See event fired only once instead of two times

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @rigdern and @janicduplessis to be potential reviewers.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Nov 18, 2016
@mkonicek mkonicek changed the title Avoid firing onSubmitEditing twice on android TextInput: Avoid firing onSubmitEditing twice on android Nov 22, 2016
@mkonicek mkonicek changed the title TextInput: Avoid firing onSubmitEditing twice on android TextInput: Avoid firing onSubmitEditing twice on Android Nov 22, 2016
List<Integer> actionsToIgnore = Arrays.asList(
EditorInfo.IME_ACTION_GO, EditorInfo.IME_ACTION_SEARCH, EditorInfo.IME_ACTION_SEND
);
if (((actionId & EditorInfo.IME_MASK_ACTION) > 0 && (!actionsToIgnore.contains(actionId) || !editText.getBlurOnSubmit())) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why !editText.getBlurOnSubmit()?

@mkonicek
Copy link
Contributor

Can it happen that some versions of Android or some devices emit EditorInfo.IME_ACTION_GO just once and nothing else? In this case we will never send the event.

// Any 'Enter' action will do
if ((actionId & EditorInfo.IME_MASK_ACTION) > 0 ||
actionId == EditorInfo.IME_NULL) {
// Any 'Enter' action will do, except if second action call for same user interaction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: except if the action is called twice for same user interaction

@reneweb
Copy link
Contributor Author

reneweb commented Nov 22, 2016

This was my main concern as well. I have checked a few different Android version, but that doesn't prove that it will never happen. I looked a little more into it and it seems there is a better solution. If we always return true in the onEditorAction it won't fire any subsequent events. The only problem is that it doesn't remove the soft keybaord/ focus automatically, but we can do that ourselves. So pretty much as we already do for next and previous actions.
I will update the pr accordingly.

@lacker
Copy link
Contributor

lacker commented Dec 15, 2016

I think we need tests for this behavior - otherwise it seems very likely that it breaks.

For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction,
which causes no subsequent events to be fired by android.
@reneweb
Copy link
Contributor Author

reneweb commented Dec 18, 2016

I've added a test

@facebook-github-bot facebook-github-bot added GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. labels Jan 19, 2017
@facebook-github-bot
Copy link
Contributor

Something went wrong when importing this pull request. Please cc someone from the team at fb to help with importing this.

@facebook-github-bot facebook-github-bot added Import Failed and removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Jan 20, 2017
edmofro pushed a commit to edmofro/react-native that referenced this pull request Feb 6, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
nicktate pushed a commit to nicktate/react-native that referenced this pull request Feb 7, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
normanjoyner pushed a commit to nicktate/react-native that referenced this pull request Feb 9, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
nicktate pushed a commit to nicktate/react-native that referenced this pull request Feb 9, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
nicktate pushed a commit to nicktate/react-native that referenced this pull request Feb 9, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
nicktate pushed a commit to nicktate/react-native that referenced this pull request Feb 9, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
nicktate pushed a commit to nicktate/react-native that referenced this pull request Feb 9, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
nicktate pushed a commit to nicktate/react-native that referenced this pull request Feb 9, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
nicktate pushed a commit to nicktate/react-native that referenced this pull request Feb 9, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
nicktate pushed a commit to nicktate/react-native that referenced this pull request Feb 9, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
nicktate pushed a commit to nicktate/react-native that referenced this pull request Feb 9, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
nicktate pushed a commit to nicktate/react-native that referenced this pull request Feb 9, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
nicktate pushed a commit to nicktate/react-native that referenced this pull request Feb 9, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
nicktate pushed a commit to nicktate/react-native that referenced this pull request Feb 9, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
nicktate pushed a commit to nicktate/react-native that referenced this pull request Feb 9, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
nicktate pushed a commit to nicktate/react-native that referenced this pull request Feb 9, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
nicktate pushed a commit to nicktate/react-native that referenced this pull request Feb 9, 2017
Summary:
For returnKeyType 'go', 'search' and 'send' Android will call
onEditorAction twice, once with IME_NULL and another time with the respective IME_ACTION.
This change makes sure to only fire one onSubmitEditing by always returning true in onEditorAction, which causes no subsequent events to be fired by android.

Fixes facebook#10443

**Test plan**

1. Create view with TextInput having 'go', 'search' or 'send as `returnKeyType`
```javascript
<View>
           <TextInput
                returnKeyType='search'
                onSubmitEditing={event => console.log('submit search')}></TextInput>

           <TextInput
                returnKeyType='go'
                onSubmitEditing={event => console.log('submit go')}></TextInput>

         <TextInput
              returnKeyType='send'
              onSubmitEditing={event => console.log('submit send')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See event fired only once instead of two times
Closes facebook#11006

Differential Revision: D4439110

Pulled By: hramos

fbshipit-source-id: 5573b7f15f862b432600ddd3d61a0852ce51b2b3
facebook-github-bot pushed a commit that referenced this pull request Aug 28, 2017
Summary:
…ndroid

Android overrides the original set ime option when the EditText is a multiline one.
This change makes sure to set it back to the original one when blurOnSubmit is true,
which causes the button icon to be conforming to the set returnKeyType as well as
changing the behaviour of the button, such that it will blurOnSubmit correctly.

The reason not do it with blurOnSubmit being false is
because it then would not create new lines when pressing the submit button,
which would be inconsistent with IOS behaviour.

**Note** this change relies on this one #11006 because the app would crash if we don't expllicitly remove the focus (`editText.clearFocus();`)

Fixes #8778

**Test plan (required)**

1. Create view with TextInput with multiline and blurOnSubmit set to true
```javascript
<View>
           <TextInput
                returnKeyType='search'
                blurOnSubmit={true}
                multiline={true}
                onSubmitEditing={event => console.log('submit search')}></TextInput>
</View>
```

2. Input some text and click submit button in soft keyboard
3. See submit event fired and focus cleared / keyboard removed
Closes #11125

Differential Revision: D5718755

Pulled By: hramos

fbshipit-source-id: c403d61a8a879c04c3defb40ad0b6689a2329ce1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants