App icon indicating copy to clipboard operation
App copied to clipboard

[Chat] Swipe to close keyboard on iOS

Open NicMendonca opened this issue 5 years ago • 9 comments

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:

image

Upwork job posting: https://www.upwork.com/jobs/~0104d324e7e78c07ea

NicMendonca avatar Mar 18 '21 21:03 NicMendonca

@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'

OnlineSmileDev avatar Mar 18 '21 22:03 OnlineSmileDev

Hi @NicMendonca!

I would love to work on the issue!

I did a bit of research and have two solutions for this:

Solution 1:

  1. Wrap ReportActionCompose with a ScrollView and use keyboardDismissMode to dismiss the keyboard in response to a drag. iOS has 'interactive' which dismisses the keyboard interactively.
  2. Wrap theScrollViewaround a View to 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:

  1. Use PanGestureHandler from react-native-gesture-handler to 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

barun1997 avatar Mar 19 '21 00:03 barun1997

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.

wildan-m avatar Mar 20 '21 07:03 wildan-m

@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 avatar Mar 22 '21 20:03 marcaaron

@marcaaron Of course! Will do. I am guessing, we pass onSwipeDown as a prop to the component as well?

barun1997 avatar Mar 22 '21 22:03 barun1997

Right, it would be fired whenever we swipe down, but will be a callback function.

marcaaron avatar Mar 23 '21 16:03 marcaaron

Great, gotcha @marcaaron ! Am I good to go with working for the PR on the issue?

barun1997 avatar Mar 23 '21 16:03 barun1997

Hi,

This is Kaushik here and I would like to suggest a simple and effective explanation for this,

  1. it will be handle by adding keyboardShouldPersistTaps='handled' to scroll view.

kaushiktd avatar Mar 26 '21 16:03 kaushiktd

Just merged this but the issue did not close I think it should have?

marcaaron avatar Mar 29 '21 21:03 marcaaron