question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to scroll AND swipe to dismiss keyboard using scrollview

See original GitHub issue

Please provide all the information requested. Issues that do not follow this format are likely to stall.

Description

I am creating a chat application and trying to follow iOS iMessage as closely as possible. I’m struggling with the keyboardDismissMode and keyboardShouldPersistTaps props.

What I’d like to be able to do is have the user scroll through a list of messages while the keyboard is visible but then swipe to dismiss the keyboard as well. Currently, I can either allow scrolling when the keyboard is up OR swipe to dismiss keyboard but not both.

React Native version:

System: OS: macOS 10.15.2 CPU: (8) x64 Intel® Core™ i7-4770HQ CPU @ 2.20GHz Memory: 53.13 MB / 16.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 14.5.0 - /usr/local/bin/node Yarn: 1.22.4 - /usr/local/bin/yarn npm: 6.14.5 - /usr/local/bin/npm SDKs: iOS SDK: Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2 Android SDK: API Levels: 23, 25, 26, 27, 28, 29 Build Tools: 23.0.1, 25.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.0, 28.0.2, 28.0.3, 29.0.0, 29.0.2, 29.0.3 System Images: android-28 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom, android-Q | Android TV Intel x86 Atom IDEs: Android Studio: 4.0 AI-193.6911.18.40.6514223 Xcode: 11.5/11E608c - /usr/bin/xcodebuild npmPackages: react: 16.8.6 => 16.8.6 react-native: 0.60.6 => 0.60.6 npmGlobalPackages: react-native-cli: 2.0.1

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

Example of scrolling but no keyboard dismiss: keyboard

Example of keyboard dismiss, but no scrolling: keyboard2

Expected Results

I’d like to be able to scroll within the scrollview while the keyboard is open and swipe downwards to dismiss the keyboard.

Snack, code example, screenshot, or link to a repository:

For case where keyboard dismisses on swipe, but scrolling is not possible: <KeyboardAvoidingView // Don't specify behavior for android due to a react native offset bug behavior={Platform.OS === 'ios' ? 'padding' : null} keyboardVerticalOffset={50} enabled style={styles.keyboardViewStyle}> <View style={styles.listContainer}> <ScrollView scrollEnabled = {true} ref={scrollToRef} horizontal= {true} alwaysBounceHorizontal = {true} onScrollEndDrag = {onScrollEnd} showsHorizontalScrollIndicator={false} keyboardDismissMode={'interactive'} keyboardShouldPersistTaps={'handled'} > <List data={messageList} renderItem={messageListRenderItem} inverted={true} onEndReached={handleEndReached} onEndReachedThreshold={1} ListHeaderComponent={header} ListFooterComponent={pageLoadingComponent} showsVerticalScrollIndicator={false} /> </ScrollView> <ReplyView message={message} buttonDisabled={disable} onUpdateMessage={handleUpdateMessage} onPress={handlePress}/> </View> </KeyboardAvoidingView> For case where scrolling is possible, no keyboard dismiss on swipe: <KeyboardAvoidingView // Don't specify behavior for android due to a react native offset bug behavior={Platform.OS === 'ios' ? 'padding' : null} keyboardVerticalOffset={50} enabled style={styles.keyboardViewStyle}> <View style={styles.listContainer}> <ScrollView scrollEnabled = {true} ref={scrollToRef} horizontal= {true} alwaysBounceHorizontal = {true} onScrollEndDrag = {onScrollEnd} showsHorizontalScrollIndicator={false} keyboardDismissMode={'interactive'} keyboardShouldPersistTaps={'always'} > <List data={messageList} renderItem={messageListRenderItem} inverted={true} onEndReached={handleEndReached} onEndReachedThreshold={1} ListHeaderComponent={header} ListFooterComponent={pageLoadingComponent} showsVerticalScrollIndicator={false} /> </ScrollView> <ReplyView message={message} buttonDisabled={disable} onUpdateMessage={handleUpdateMessage} onPress={handlePress}/> </View> </KeyboardAvoidingView>

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
clfristoecommented, Aug 5, 2020

@chrisglein Here is a snack with the general idea: https://snack.expo.io/N5qTzRNuN This one shows the case where I can scroll to dismiss the keyboard, but I am unable to scroll through the list when the keyboard is open. I’ve added a comment with a quick code change to show the other experience.

0reactions
stale[bot]commented, Dec 25, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native: Keyboard dismiss when changing focus in ...
'always', the keyboard will not dismiss automatically, and the scroll view will not catch taps, but children of the scroll view can catch ......
Read more >
Dismissing Keyboard on Scrollview Swift
I have some textfields within my scrollview and the touches are not recognized within the scroll view to dismiss the keyboard. Any help...
Read more >
How to dismiss keyboard with react-navigation in ...
'always' , the keyboard will not dismiss automatically, and the scroll view will not catch taps, but children of the scroll view can...
Read more >
ScrollView
For vertical scrolling, consider NestedScrollView instead of scroll view which offers ... Hide the system bars instead if the application needs to be...
Read more >
Dismissing Keyboards in React Native Views
Some people suggest replacing the View with a ScrollView as it has keyboard dismissing ability built-in. By default, tapping outside of an input ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found