Skip to content

Commit

Permalink
Fix ScrollView blurring TextInput when changing focus between inputs
Browse files Browse the repository at this point in the history
Summary:
On some platforms, when two inputs are in a scrollview, trying to switch focus to another textinput doesn't work and requires two taps. This is because from `_handleTouchEnd` we blur the currently focused input, even if that input had only just become focused from the same touch event. Instead, only blur when the event did not target the current textinput.

Changelog: [Android][Fixed] TextInputs may not get focused when switching inputs in a ScrollView

Reviewed By: jehartzog

Differential Revision: D40159333

fbshipit-source-id: 388f85dff5ac8f24d7e2590e887635391c52d72f
  • Loading branch information
javache authored and facebook-github-bot committed Oct 7, 2022
1 parent 21dc5c8 commit 370bbd7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Libraries/Components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,7 @@ class ScrollView extends React.Component<Props, State> {
// if another touch occurs outside of it
const currentlyFocusedTextInput = TextInputState.currentlyFocusedInput();
if (
currentlyFocusedTextInput != null &&
this.props.keyboardShouldPersistTaps !== true &&
this.props.keyboardShouldPersistTaps !== 'always' &&
this._keyboardIsDismissible() &&
Expand Down Expand Up @@ -1457,7 +1458,6 @@ class ScrollView extends React.Component<Props, State> {
}

const currentlyFocusedInput = TextInputState.currentlyFocusedInput();

if (
this.props.keyboardShouldPersistTaps === 'handled' &&
this._keyboardIsDismissible() &&
Expand Down Expand Up @@ -1583,12 +1583,16 @@ class ScrollView extends React.Component<Props, State> {

// Dismiss the keyboard now if we didn't become responder in capture phase
// to eat presses, but still want to dismiss on interaction.
// Don't do anything if the target of the touch event is the current input.
const currentlyFocusedTextInput = TextInputState.currentlyFocusedInput();
if (
currentlyFocusedTextInput != null &&
e.target !== currentlyFocusedTextInput &&
this._softKeyboardIsDetached() &&
this._keyboardIsDismissible() &&
keyboardNeverPersistsTaps
) {
TextInputState.blurTextInput(TextInputState.currentlyFocusedInput());
TextInputState.blurTextInput(currentlyFocusedTextInput);
}

this.props.onTouchEnd && this.props.onTouchEnd(e);
Expand Down

0 comments on commit 370bbd7

Please sign in to comment.