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

Navigating back using gesture on iOS does not dismiss the keyboard #1413

Closed
2 of 7 tasks
gabrieldonadel opened this issue Apr 18, 2022 · 11 comments · Fixed by #1419
Closed
2 of 7 tasks

Navigating back using gesture on iOS does not dismiss the keyboard #1413

gabrieldonadel opened this issue Apr 18, 2022 · 11 comments · Fixed by #1419
Labels
Platform: iOS This issue is specific to iOS Repro provided A reproduction with a snack or repo is provided

Comments

@gabrieldonadel
Copy link
Contributor

Description

On iOS when navigating back from a screen that was a TextInput wrapped in a KeyboardAvoidingView using the swipe gesture does not dismiss the keyboard leading to weird animation during transitions. I tested the exact same come using @react-navigation/stack and the keyboard gets dismissed in the beginning of the transition

Screenshots

Screen.Recording.2022-04-18.at.14.08.12.mov

Steps To Reproduce

  1. Navigate to any screen that has a TextInput wrapped in a KeyboardAvoidingView
  2. Focus the TextInput and swipe from left to right (gesture to navigate back)
  3. Observe container resizing the but the keyboard remaining in its position (open)

Expected behavior

Either the keyboard should be dismissed when the navigation gesture starts, same behavior as @react-navigation/stack,
or the container wrapped with a KeyboardAvoidingView should not be resized during the transition

Actual behavior

Keyboard remains on the screen while navigating back

Reproduction

Snack https://snack.expo.dev/@gabidonadel/chat-keyboard

Platform

  • iOS
  • Android
  • Web
  • Windows
  • tvOS

Workflow

  • Managed workflow
  • Bare workflow

Package versions

package version
@react-navigation/native *
@react-navigation/native-stack *
react-native-screens 3.8.0
react-native-safe-area-context 3.3.2
react-native-gesture-handler 1.10.2
expo 43.0.0
@github-actions github-actions bot added Platform: iOS This issue is specific to iOS Repro provided A reproduction with a snack or repo is provided labels Apr 18, 2022
@vonovak
Copy link

vonovak commented Apr 19, 2022

I believe this (not hiding keyboard) is the expected behavior, see eg. the messages app.

@WoLewicki
Copy link
Member

I think it is a duplicate of #958, so maybe we should close it to keep the discussion in one place? And, as @vonovak said, it might be rather a problem with how KeyboardAvoidingView works rather than the platform's behavior.

@vonovak
Copy link

vonovak commented Apr 19, 2022

@gabrieldonadel have you tried with facebook/react-native@49a1460 ? (requires 0.68)

@gabrieldonadel
Copy link
Contributor Author

@gabrieldonadel have you tried with facebook/react-native@49a1460 ? (requires 0.68)

Thanks for the suggestion but from my testing using automaticallyAdjustKeyboardInsets still leads to the same problem

@felippepuhle
Copy link

Problem is not related to KeyboardAvoidingView only, @gabrieldonadel can correct me if I say something wrong but Keyboard is dispatching will/did hide even though keyboard is still open (we tried to create our own KeyboardAvoidingView and at the end of the day result was the same). Is there something we can help to fix this?

@WoLewicki
Copy link
Member

@felippepuhle did you check if the behavior of Keyboard events when using native-stack differs from the ones in native iOS project? I am not sure if we do anything specific in native-stack regarding those events so it should probably work just as in the native iOS projects.

@felippepuhle
Copy link

@WoLewicki nope, unfortunately we don't have any native iOS project for a quick test and unsure how we would test all these keyboard scenarios... but we did compare with the JS stack and in that case they are explicitly calling dismiss when starting the gesture and focusing again if user didn't finish the gesture and for some reason it works...

I'm not saying it's react-native-screens fault or anything, just trying to get some more thoughts about the odd scenario where we're getting the will/did hide event but the keyboard is not being really being dismissed (it might even be the OS triggering those), any thoughts?

We're considering applying your closed PR as a patch for now, we checked what some other react native apps are doing and discord for example is using the same approach, not perfect but much better IMO.

Thanks!

@WoLewicki
Copy link
Member

It is the OS that triggers those events (see https://github.com/facebook/react-native/blob/18196512db6b8b4469a5e1b098d8892ae72d743a/React/CoreModules/RCTKeyboardObserver.mm), but I am not sure why they are called in such way when swiping natively 😕

@WoLewicki
Copy link
Member

I made a PR with a prop for hiding keyboard on swipe: #1419. As for the option when we would like not to hide keyboard but also not change the frame of view, we would need changes in KeyboardAvoidingView or add our own component managing it. Can I help you more with it? Or can we close it with the PR?

@gabrieldonadel
Copy link
Contributor Author

Thanks for your help @WoLewicki, yeah I think we can close this with the PR

@WoLewicki WoLewicki linked a pull request Apr 22, 2022 that will close this issue
8 tasks
@cenzovit
Copy link

I made a PR with a prop for hiding keyboard on swipe: #1419. As for the option when we would like not to hide keyboard but also not change the frame of view, we would need changes in KeyboardAvoidingView or add our own component managing it. Can I help you more with it? Or can we close it with the PR?

Does anyone have any clue as to why this is the case -- that the native keyboard frame events are firing when the keyboard is not actually being dismissed? I'd like to both not hide the keyboard but also not trigger things like flatlist keyboard insets getting automatically adjusted which all seems to be tied to the native keyboard events being triggered incorrectly...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: iOS This issue is specific to iOS Repro provided A reproduction with a snack or repo is provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants