[Chat] Swipe to close keyboard on iOS
If you haven’t already, check out our contributing guidelines for onboarding!
Expected Result:
Swipe collapses the keyboard, by dragging your thumb from the message window to the keyboard.
Actual Result:
Swipe to close keyboard is not a supported gesture.
Action Performed:
- Tap into a chat
- Tap in the comment box
- Notice keyboard is now open
- Attempt to swipe down to close keyboard
- Notice keyboard doesn't close
Workaround:
Can the user still use Expensify without this being fixed? Have you informed them of the workaround?
Platform:
iOS
Notes/Photos/Videos:

Upwork job posting: https://www.upwork.com/jobs/~0104d324e7e78c07ea
@NicMendonca I fixed the above issues with adding ScrollView to your total component. And we have to give the keyboardShouldPersistTaps='handled' permission to ScrollView.
<ScrollView contentContainerStyle={{flexGrow: 1}} keyboardShouldPersistTaps='handled'
Hi @NicMendonca!
I would love to work on the issue!
I did a bit of research and have two solutions for this:
Solution 1:
- Wrap
ReportActionComposewith aScrollViewand usekeyboardDismissModeto dismiss the keyboard in response to a drag. iOS has 'interactive' which dismisses the keyboard interactively. - Wrap the
ScrollViewaround aViewto remove extra padding
During the testing phase, I faced the problem of the ReportActionCompose component bouncing while scrolling, so I will have to spend more time figuring out this solution.
Solution 2:
- Use
PanGestureHandlerfromreact-native-gesture-handlerto wrap the above component and dismiss the keyboard using Keyboard.dismiss() whenever a gesture event (drag down) is registered.
~~We will have to install react-native-gesture-handler package for this solution.~~
EDIT: We need not install react-native-gesture-handler. PanResponder from React Native package actually works the same way as the comment points out.
My proposal is to use PanResponder and capture the swipe down gesture using onMoveShouldSetPanResponderCapture whenever gestureState.dy < someValue so that the PanResponder only comes to focus on swipe down. Then dismiss the keyboard using onPanResponderMove using Keyboard.dismiss() above.
I implemented the solution below using the second option:
https://user-images.githubusercontent.com/19339044/111713243-51375a80-8877-11eb-944f-08ad66884f68.mov
Hi,
I've applied for the Upwork job.
My proposed solution:
Attach PanResponder to ReportActionCompose component and make the PanResponder and the Textinput coexist so that a tap will focus on the TextInput and a swipe will still trigger the PanResponder callbacks.
@barun1997 The PanResponder solution sounds preferable. Could we perhaps design this in a way so that any element could be wrapped with something like SwipeableView and have an onSwipeDown prop?
<SwipeableView
onSwipeDown={() => Keyboard.dismiss()}
>
<SomeOtherComponent />
</SwipeableView>
@marcaaron Of course! Will do. I am guessing, we pass onSwipeDown as a prop to the component as well?
Right, it would be fired whenever we swipe down, but will be a callback function.
Great, gotcha @marcaaron ! Am I good to go with working for the PR on the issue?
Hi,
This is Kaushik here and I would like to suggest a simple and effective explanation for this,
- it will be handle by adding keyboardShouldPersistTaps='handled' to scroll view.
Just merged this but the issue did not close I think it should have?