From 7edf9274cf6d3398075c19cd1cb020a5d6a346a2 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Thu, 2 Sep 2021 12:36:17 -0700 Subject: [PATCH] Fix keyboardDismissMode="on-drag" on Android (#31943) Summary: Fixes https://github.com/facebook/react-native/issues/23364 The current logic using `_isTouching` does not work because `_handleTouchCancel` is always called before scroll events begin. This means `_isTouching` is always false. To fix it I moved the logic to `_handleScrollBeginDrag` which is only called once when scroll drag beings. This accomplishes the expected behavior and is better than keeping it in onScroll where it would be called for each scroll event. ## Changelog [Android] [Fixed] - Fix keyboardDismissMode="on-drag" on Android Pull Request resolved: https://github.com/facebook/react-native/pull/31943 Test Plan: Tested in an app that on-drag does not work before and works after this patch. Reviewed By: sshic Differential Revision: D30674276 Pulled By: yungsters fbshipit-source-id: aa0bd605809fa01518f70fbf323c06e32c76ed1d --- Libraries/Components/ScrollView/ScrollView.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index e497288b1b7d92..696781ffbe3def 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -1178,11 +1178,6 @@ class ScrollView extends React.Component { ); } } - if (Platform.OS === 'android') { - if (this.props.keyboardDismissMode === 'on-drag' && this._isTouching) { - dismissKeyboard(); - } - } this._observedScrollSinceBecomingResponder = true; this.props.onScroll && this.props.onScroll(e); }; @@ -1299,6 +1294,14 @@ class ScrollView extends React.Component { */ _handleScrollBeginDrag: (e: ScrollEvent) => void = (e: ScrollEvent) => { FrameRateLogger.beginScroll(); // TODO: track all scrolls after implementing onScrollEndAnimation + + if ( + Platform.OS === 'android' && + this.props.keyboardDismissMode === 'on-drag' + ) { + dismissKeyboard(); + } + this.props.onScrollBeginDrag && this.props.onScrollBeginDrag(e); };