From 370bbd705b21947f1c334e158816c812825546d4 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 7 Oct 2022 07:20:33 -0700 Subject: [PATCH] Fix ScrollView blurring TextInput when changing focus between inputs 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 --- Libraries/Components/ScrollView/ScrollView.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 134f74a526d88f..0c2ecf2f16846a 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -1382,6 +1382,7 @@ class ScrollView extends React.Component { // if another touch occurs outside of it const currentlyFocusedTextInput = TextInputState.currentlyFocusedInput(); if ( + currentlyFocusedTextInput != null && this.props.keyboardShouldPersistTaps !== true && this.props.keyboardShouldPersistTaps !== 'always' && this._keyboardIsDismissible() && @@ -1457,7 +1458,6 @@ class ScrollView extends React.Component { } const currentlyFocusedInput = TextInputState.currentlyFocusedInput(); - if ( this.props.keyboardShouldPersistTaps === 'handled' && this._keyboardIsDismissible() && @@ -1583,12 +1583,16 @@ class ScrollView extends React.Component { // 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);