From ef77a4218db5bafd45ac844cd06e33e229ea534a Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Tue, 23 Aug 2022 05:46:58 -0700 Subject: [PATCH] Stop special-casing Android 11+ from large form-factor `keyboardShouldPersistTaps` behavior Summary: ScrollView has special-case logic to dismiss keyboard on tap, controlled via the `keyboardShouldPersistTaps` property. The first click does not propagate to children of the scrollview if the tap causes the keyboard to be dismissed. This behavior is motivated by a soft keyboard on phones which takes away space from the viewport. ScrollView historically determined if a soft-keyboard was open via querying if there was a focused TextInput. This meant that clicks to a ScrollView would be eaten, even on form factors using phsyical keyboards. A couple years ago I added https://github.com/facebook/react-native/pull/30374 to only eat clicks when keyboard events have indicated that a soft keyboard is present. I special-cased Android out of the change, because of platform issues with its reliability of keyboard events. After D38500859 (https://github.com/facebook/react-native/commit/1e48274223ee647ac4fc2c21822b5240f3c47e4c) rolls out we can start to remove that special-casing, of devices which report "android" for Platform.OS. Reviewed By: javache Differential Revision: D38528887 fbshipit-source-id: a745b478b18abe4ef32cbdd8a14ca6dfdb5e738f --- Libraries/Components/ScrollView/ScrollView.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index bd04e7d61fc52f..9746c80ddc78fb 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -1545,10 +1545,9 @@ class ScrollView extends React.Component { // Even if an input is focused, we may not have a keyboard to dismiss. E.g // when using a physical keyboard. Ensure we have an event for an opened - // keyboard, except on Android where setting windowSoftInputMode to - // adjustNone leads to missing keyboard events. + // keyboard. const softKeyboardMayBeOpen = - this._keyboardMetrics != null || Platform.OS === 'android'; + this._keyboardMetrics != null || this._keyboardEventsAreUnreliable(); return hasFocusedTextInput && softKeyboardMayBeOpen; }; @@ -1562,6 +1561,12 @@ class ScrollView extends React.Component { return this._keyboardMetrics != null && this._keyboardMetrics.height === 0; }; + _keyboardEventsAreUnreliable: () => boolean = () => { + // Android versions prior to API 30 rely on observing layout changes when + // `android:windowSoftInputMode` is set to `adjustResize` or `adjustPan`. + return Platform.OS === 'android' && Platform.Version < 30; + }; + /** * Invoke this from an `onTouchEnd` event. *