Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyboardDismissMode = "on-drag" on ScrollView not working with Android #23364

Closed
hakkikonu opened this issue Feb 11, 2019 · 28 comments
Closed

keyboardDismissMode = "on-drag" on ScrollView not working with Android #23364

hakkikonu opened this issue Feb 11, 2019 · 28 comments

Comments

@hakkikonu
Copy link

hakkikonu commented Feb 11, 2019

🐛 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(R) Core(TM) 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

@kelset
Copy link
Contributor

kelset commented May 3, 2019

👋 there

is this issue still present on RN 59? You posted a repro (thanks for that!) but it's on Snack, which is currently based on latest Expo which is using 0.57.

@Collin3
Copy link

Collin3 commented May 20, 2019

I'm seeing the same issue RN v0.59.5 on iOS and Android

@hakkikonu
Copy link
Author

@kelset Yes, still I'm seeing

@ChiwanAhn
Copy link

RN 0.59.8 still has the same issue here on Android.

@kelset
Copy link
Contributor

kelset commented May 31, 2019

Ok thanks everyone - we just released the first 0.60 RC, could anyone try the repro with that version?

@immortalx
Copy link

@kelset Still happening on 0.60 RC, keyboard will dismiss only on tap but not on scroll.
I don't know if its related but i'm unable to show the keyboard with input.focus() as well.
On iOS everything works fine.

@MUllman
Copy link

MUllman commented Jun 6, 2019

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

@williamliangwl
Copy link

Any plan for fixing this bug ?

@yasir-netlinks
Copy link

Hi, Im experiencing the issue too , im using 0.59.10 , any work arounds?

@andidev
Copy link

andidev commented Sep 10, 2019

@yasir-netlinks
this is the current workaround

onScrollBeginDrag={Keyboard.dismiss}

@fungilation
Copy link

Repro on RN 0.60.5. FlatList with keyboardDismissMode: 'on-drag' which does dismiss keyboard on drag on iOS, but does not on Android (emulator API 26)

@kelset
Copy link
Contributor

kelset commented Sep 30, 2019

What about 61?

@fungilation
Copy link

fungilation commented Oct 1, 2019

Yes, 0.61.1 too. Still need to monkey patch it. (with patch-package)

@SinLucifer
Copy link

@kelset hello , I found why this issues happened, because of the fix in Fix for scrollview android #18785 @mistenkt added the code
this.state.isTouching, but it always return false...

@sivashik98
Copy link

@kelset Hello, I have this problem too, it would like that this problem was solved, thanks.

@benjaminhay
Copy link

benjaminhay commented Dec 5, 2019

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

@romanakash
Copy link

Same problem with 0.61.5, but can confirm the current workaround works. Will be nice if it's fixed

@stale
Copy link

stale bot commented Mar 28, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 28, 2020
@fungilation
Copy link

Not fixed, stupid bot

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Mar 28, 2020
@lordAnari
Copy link

Not fixed. Need this to work. Any updates?

@kelset
Copy link
Contributor

kelset commented Apr 8, 2020

hello folks - it seems that this bug has been around for quite some time but no one attempted a PR to fix it. If you have time I'd recommend you create a PR with a proper fix and link it here.

@hakkikonu
Copy link
Author

still not fixed for 0.62

@fabOnReact
Copy link
Contributor

fabOnReact commented Jun 11, 2020

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

public void setKeyboardDismissMode(ReactDrawerLayout view, @Nullable String value) {}

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

@stale
Copy link

stale bot commented Sep 11, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Sep 11, 2020
@fungilation
Copy link

No bot.

And no, there's already PR which fixes it: #26422

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

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Sep 11, 2020
@raza2022
Copy link

raza2022 commented Oct 3, 2020

@fungilation it's working fine for both Android and IOS ? and if you can share the patch as sample it would be nice, as I am using the patch-package too

@fungilation
Copy link

fungilation commented Oct 3, 2020

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,

@andidev

This comment has been minimized.

facebook-github-bot pushed a commit that referenced this issue Mar 1, 2022
Summary:
This sync includes the following changes:
- **[17806594c](facebook/react@17806594c )**: Move createRoot/hydrateRoot to react-dom/client ([#23385](facebook/react#23385)) //<Sebastian Markbåge>//
- **[75662d6a7](facebook/react@75662d6a7 )**: Remove hacky stream.locked check, declare as byte stream instead ([#23387](facebook/react#23387)) //<Sebastian Markbåge>//
- **[a82ef6d40](facebook/react@a82ef6d40 )**: Add back skipUnmountedBoundaries flag only for www ([#23383](facebook/react#23383)) //<Andrew Clark>//
- **[f468816ef](facebook/react@f468816ef )**: Fix false positive hydration warnings ([#23364](facebook/react#23364)) //<Andrew Clark>//
- **[5d08a24c2](facebook/react@5d08a24c2 )**: useId: Use 'H' to separate main id from hook index ([#23363](facebook/react#23363)) //<Andrew Clark>//
- **[3a60844a0](facebook/react@3a60844a0 )**: Update error message for suspending at sync priority ([#23361](facebook/react#23361)) //<Andrew Clark>//
- **[efe4121ee](facebook/react@efe4121ee )**: Add : to beginning and end of every useId ([#23360](facebook/react#23360)) //<Andrew Clark>//
- **[42f15b324](facebook/react@42f15b324 )**: [DevTools][Transition Tracing] onTransitionComplete and onTransitionStart implmentation ([#23313](facebook/react#23313)) //<Luna Ruan>//
- **[a5b22155c](facebook/react@a5b22155c )**: Warn if renderSubtreeIntoContainer is called ([#23355](facebook/react#23355)) //<Andrew Clark>//
- **[52c393b5d](facebook/react@52c393b5d )**: Revert to client render on text mismatch ([#23354](facebook/react#23354)) //<Andrew Clark>//
- **[1ad8d8129](facebook/react@1ad8d8129 )**: Remove object-assign polyfill ([#23351](facebook/react#23351)) //<Sebastian Markbåge>//
- **[b3f3da205](facebook/react@b3f3da205 )**: Land warnOnSubscriptionInsideStartTransition flag ([#23353](facebook/react#23353)) //<Andrew Clark>//
- **[990098f88](facebook/react@990098f88 )**: Re-arrange main ReactFeatureFlags module ([#23350](facebook/react#23350)) //<Andrew Clark>//
- **[1f3f6db73](facebook/react@1f3f6db73 )**: Remove createMutableSource from stable exports ([#23352](facebook/react#23352)) //<Andrew Clark>//
- **[587e75930](facebook/react@587e75930 )**: Remove Numeric Fallback of Symbols ([#23348](facebook/react#23348)) //<Sebastian Markbåge>//
- **[40351575d](facebook/react@40351575d )**: Split writeChunk into void and return value ([#23343](facebook/react#23343)) //<Sebastian Markbåge>//
- **[2c693b2de](facebook/react@2c693b2de )**: Re-add reentrancy avoidance ([#23342](facebook/react#23342)) //<Sebastian Markbåge>//
- **[1760b27c0](facebook/react@1760b27c0 )**: Remove ./src/* export from public build ([#23262](facebook/react#23262)) //<Andrew Clark>//
- **[552c067bb](facebook/react@552c067bb )**: Remove public export for unstable-shared-subset.js ([#23261](facebook/react#23261)) //<Andrew Clark>//

Changelog:
[General][Changed] - React Native sync for revisions 4de99b3...1780659

jest_e2e[run_all_tests]

Reviewed By: rickhanlonii

Differential Revision: D34552175

fbshipit-source-id: f1c831a45f96d335a20c3b4113196e0a42cefc03
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this issue Jan 15, 2023
Summary:
This sync includes the following changes:
- **[17806594c](facebook/react@17806594c )**: Move createRoot/hydrateRoot to react-dom/client ([facebook#23385](facebook/react#23385)) //<Sebastian Markbåge>//
- **[75662d6a7](facebook/react@75662d6a7 )**: Remove hacky stream.locked check, declare as byte stream instead ([facebook#23387](facebook/react#23387)) //<Sebastian Markbåge>//
- **[a82ef6d40](facebook/react@a82ef6d40 )**: Add back skipUnmountedBoundaries flag only for www ([facebook#23383](facebook/react#23383)) //<Andrew Clark>//
- **[f468816ef](facebook/react@f468816ef )**: Fix false positive hydration warnings ([facebook#23364](facebook/react#23364)) //<Andrew Clark>//
- **[5d08a24c2](facebook/react@5d08a24c2 )**: useId: Use 'H' to separate main id from hook index ([facebook#23363](facebook/react#23363)) //<Andrew Clark>//
- **[3a60844a0](facebook/react@3a60844a0 )**: Update error message for suspending at sync priority ([facebook#23361](facebook/react#23361)) //<Andrew Clark>//
- **[efe4121ee](facebook/react@efe4121ee )**: Add : to beginning and end of every useId ([facebook#23360](facebook/react#23360)) //<Andrew Clark>//
- **[42f15b324](facebook/react@42f15b324 )**: [DevTools][Transition Tracing] onTransitionComplete and onTransitionStart implmentation ([facebook#23313](facebook/react#23313)) //<Luna Ruan>//
- **[a5b22155c](facebook/react@a5b22155c )**: Warn if renderSubtreeIntoContainer is called ([facebook#23355](facebook/react#23355)) //<Andrew Clark>//
- **[52c393b5d](facebook/react@52c393b5d )**: Revert to client render on text mismatch ([facebook#23354](facebook/react#23354)) //<Andrew Clark>//
- **[1ad8d8129](facebook/react@1ad8d8129 )**: Remove object-assign polyfill ([facebook#23351](facebook/react#23351)) //<Sebastian Markbåge>//
- **[b3f3da205](facebook/react@b3f3da205 )**: Land warnOnSubscriptionInsideStartTransition flag ([facebook#23353](facebook/react#23353)) //<Andrew Clark>//
- **[990098f88](facebook/react@990098f88 )**: Re-arrange main ReactFeatureFlags module ([facebook#23350](facebook/react#23350)) //<Andrew Clark>//
- **[1f3f6db73](facebook/react@1f3f6db73 )**: Remove createMutableSource from stable exports ([facebook#23352](facebook/react#23352)) //<Andrew Clark>//
- **[587e75930](facebook/react@587e75930 )**: Remove Numeric Fallback of Symbols ([facebook#23348](facebook/react#23348)) //<Sebastian Markbåge>//
- **[40351575d](facebook/react@40351575d )**: Split writeChunk into void and return value ([facebook#23343](facebook/react#23343)) //<Sebastian Markbåge>//
- **[2c693b2de](facebook/react@2c693b2de )**: Re-add reentrancy avoidance ([facebook#23342](facebook/react#23342)) //<Sebastian Markbåge>//
- **[1760b27c0](facebook/react@1760b27c0 )**: Remove ./src/* export from public build ([facebook#23262](facebook/react#23262)) //<Andrew Clark>//
- **[552c067bb](facebook/react@552c067bb )**: Remove public export for unstable-shared-subset.js ([facebook#23261](facebook/react#23261)) //<Andrew Clark>//

Changelog:
[General][Changed] - React Native sync for revisions 4de99b3...1780659

jest_e2e[run_all_tests]

Reviewed By: rickhanlonii

Differential Revision: D34552175

fbshipit-source-id: f1c831a45f96d335a20c3b4113196e0a42cefc03
zhxlp pushed a commit to zhxlp/react-native that referenced this issue Aug 1, 2023
Summary:
Fixes facebook#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: facebook#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.