react-native: keyboardDismissMode = "on-drag" on ScrollView not working with Android

šŸ› Bug Report

When scrolling in ScrollView when device keyboard active, on Android emulator keyboardDismissMode = "on-drag" does not close the keyboard

To Reproduce

<ScrollView keyboardDismissMode = "on-drag"> {content} </ScrollView>

Expected Behavior

Keyboard should close when scrolling on Android device.

Code Example

Minimal Expo example https://snack.expo.io/@hakkikonu/scrollview-bug

Environment

react-native info output: React Native Environment Info: System: OS: macOS 10.14.2 CPU: (8) x64 IntelĀ® Coreā„¢ i7-4770HQ CPU @ 2.20GHz Memory: 369.48 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 10.15.1 - /usr/local/bin/node Yarn: 1.13.0 - /usr/local/bin/yarn npm: 6.5.0 - /usr/local/bin/npm SDKs: iOS SDK: Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1 Android SDK: API Levels: 15, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 Build Tools: 19.1.0, 20.0.0, 21.1.2, 22.0.1, 25.0.0, 26.0.2, 27.0.0, 28.0.3 System Images: android-15 | Intel x86 Atom, android-19 | ARM EABI v7a, android-19 | Intel x86 Atom, android-21 | Android TV ARM EABI v7a, android-21 | Android TV Intel x86 Atom, android-21 | Android Wear ARM EABI v7a, android-21 | Android Wear Intel x86 Atom, android-21 | ARM EABI v7a, android-21 | Intel x86 Atom, android-21 | Intel x86 Atom_64, android-21 | Google APIs ARM EABI v7a, android-21 | Google APIs Intel x86 Atom, android-21 | Google APIs Intel x86 Atom_64, android-22 | ARM EABI v7a, android-22 | Intel x86 Atom, android-22 | Intel x86 Atom_64, android-22 | Google APIs ARM EABI v7a, android-22 | Google APIs Intel x86 Atom, android-22 | Google APIs Intel x86 Atom_64, android-23 | Google APIs ARM EABI v7a, android-23 | Google APIs Intel x86 Atom_64, android-25 | Google APIs Intel x86 Atom_64, android-25 | Google Play Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-27 | Google APIs Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom IDEs: Android Studio: 3.3 AI-182.5107.16.33.5199772 Xcode: 10.1/10B61 - /usr/bin/xcodebuild npmPackages: react: 16.6.3 => 16.6.3 react-native: 0.58.4 => 0.58.4 npmGlobalPackages: react-native-cli: 2.0.1

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 32
  • Comments: 28 (1 by maintainers)

Commits related to this issue

Most upvoted comments

@yasir-netlinks this is the current workaround

onScrollBeginDrag={Keyboard.dismiss}

Not fixed, stupid bot

TLDR

This functionality was never implemented for android and this is a feature request

LONG VERIONS

I think this functionality was never implemented on android

https://github.com/facebook/react-native/blob/9263eb5d3864a42925b699343db2c09cc8934ed0/ReactAndroid/src/main/java/com/facebook/react/views/drawer/ReactDrawerLayoutManager.java#L155

but somehow was included in the documents which should be updatedā€¦

The best way to have functionalities like this is using this workaround from @shyaniv7

const keyboardDismissProp = Platform.OS === "ios" ? { keyboardDismissMode: "on-drag" } : { onScrollEndDrag: Keyboard.dismiss };

as the workaround is easy to implement, while getting a pull request reviewed it is very hardā€¦ I would not consider writing a pr for this

my react-native+0.63.2.patch based on #26422


diff --git a/node_modules/react-native/Libraries/Components/ScrollView/ScrollView.js b/node_modules/react-native/Libraries/Components/ScrollView/ScrollView.js
index c344ac4..0f34d3c 100644
--- a/node_modules/react-native/Libraries/Components/ScrollView/ScrollView.js
+++ b/node_modules/react-native/Libraries/Components/ScrollView/ScrollView.js
@@ -969,6 +969,16 @@ class ScrollView extends React.Component<Props, State> {
     }
   }
 
+  _handleBeginScroll = (e: ScrollEvent) => {
+    if (
+      this.props.keyboardDismissMode === 'on-drag' &&
+      Platform.OS === 'android'
+    ) {
+      dismissKeyboard();
+    }
+    this._scrollResponder.scrollResponderHandleScrollBeginDrag(e);
+  };
+
   _handleScroll = (e: ScrollEvent) => {
     if (__DEV__) {
       if (
@@ -985,14 +995,6 @@ class ScrollView extends React.Component<Props, State> {
         );
       }
     }
-    if (Platform.OS === 'android') {
-      if (
-        this.props.keyboardDismissMode === 'on-drag' &&
-        this.state.isTouching
-      ) {
-        dismissKeyboard();
-      }
-    }
     this._scrollResponder.scrollResponderHandleScroll(e);
   };
 
@@ -1175,8 +1177,7 @@ class ScrollView extends React.Component<Props, State> {
         .scrollResponderHandleResponderRelease,
       onResponderTerminationRequest: this._scrollResponder
         .scrollResponderHandleTerminationRequest,
-      onScrollBeginDrag: this._scrollResponder
-        .scrollResponderHandleScrollBeginDrag,
+      onScrollBeginDrag: this._handleBeginScroll,
       onScrollEndDrag: this._scrollResponder.scrollResponderHandleScrollEndDrag,
       onScrollShouldSetResponder: this._scrollResponder
         .scrollResponderHandleScrollShouldSetResponder,

my workaround for now is to call Keyboard.dismiss() in my onScroll function. Its definitely annoying

Hi, same problem here. It still presents on React Native 0.61.5

No bot.

And no, thereā€™s already PR which fixes it: https://github.com/facebook/react-native/pull/26422

Iā€™m using by monkey patching with patch-package, and it works. So merging that would be nice.

RN 0.59.8 still has the same issue here on Android.