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

KeyboardAvoidingView doesn't work as intended on Android 10 #398

Closed
breakingrobot opened this issue Mar 21, 2024 · 2 comments · Fixed by #399
Closed

KeyboardAvoidingView doesn't work as intended on Android 10 #398

breakingrobot opened this issue Mar 21, 2024 · 2 comments · Fixed by #399
Assignees
Labels
🤖 android Android specific 🐛 bug Something isn't working 📚 components Anything related to the exported components of this library

Comments

@breakingrobot
Copy link

breakingrobot commented Mar 21, 2024

Describe the bug
On an Android 10 React Native app using a multi-step form with two screens that include an autofocused TextInput, any router.navigate or router.push will succeed but the following will happen

  • While navigation from ScreenA to ScreenB, keyboard doesn't seem to be dismissed
  • On ScreenB, TextInput is focused but the keyboard has no animation and KeyboardAvoidingView does not apply the padding expected.

Repo for reproducing
https://github.com/breakingrobot/react-native-keyboard-controller/tree/android-10-bug

To Reproduce
Steps to reproduce the behavior:

  1. Run an emulator with Android SDK <=29 (Android 10 and lower)
  2. Build the example app from my fork
  3. Go to Example 14. Keyboard Avoiding View
  4. Press Submit
  5. Go back and retry

Expected behavior
Behavior that exhibit any Android devices with Android 11 and higher :

  • While navigating from ScreenA to ScreenB, keyboard should be dismissed
  • On ScreenB, TextInput is focused, keyboard and KeyboardAvoidingView should trigger its animation and apply the correct padding

Screenshots

Android 10 - SDK 29

Enregistrement.de.l.ecran.2024-03-21.a.18.53.16.mp4

Android 14 - SDK 34

Enregistrement.de.l.ecran.2024-03-21.a.18.56.28.mp4

Smartphone (please complete the following information):

  • Desktop OS: macOS 14.0 (Sonoma)
  • Device:
    • Failing device: Emulated Pixel 4 - SDK 29 (arm64_v8a)
    • Successful device: Emulated Pixel 8 - SDK 34 (arm64_v8a)
  • OS: Android 10 (SDK 29)
  • RN version: 0.73.6 / 0.73.4 (on our Expo Project)
  • RN architecture: Fabric
  • JS engine: Hermes
  • Library version: 1.11.4
@breakingrobot breakingrobot changed the title KeyboardAvoidingView doesn't work as intended with Expo Router on Android 10 KeyboardAvoidingView doesn't work as intended with autofocus TextInput and React Navigation on Android 10 Mar 21, 2024
@breakingrobot breakingrobot changed the title KeyboardAvoidingView doesn't work as intended with autofocus TextInput and React Navigation on Android 10 KeyboardAvoidingView doesn't work as intended on Android 10 Mar 21, 2024
@kirillzyusko
Copy link
Owner

kirillzyusko commented Mar 21, 2024

@breakingrobot Interesting! I thought it could be fixed in #391 but it looks like you are using latest version and if the issues is reproducible - it means that it's something else.

On your video I see, that on Android 14 keyboard starts to hide, but then appears again, while on Android 10 it always stays on the screen.

I'll look into the problem, but as a potential workaround I could suggest you to manually close keyboard before navigating to the next screen (KeyboardController.dismiss()) and do autoFocus with some delay, like:

useEffect(() => {
  setTimeout(() => textInputRef.current.focus(), 250);
}, []);

I think it should do the trick! But I'll try to allocate some time and look into the problem 👀

@kirillzyusko kirillzyusko added 📚 components Anything related to the exported components of this library 🐛 bug Something isn't working 🤖 android Android specific labels Mar 21, 2024
@breakingrobot
Copy link
Author

breakingrobot commented Mar 22, 2024

@kirillzyusko Thanks for your quick answer, just to let you know I had a workaround with KeyboardController.dismiss()

I then tried with delaying focus with a textInputRef exactly like your code snippet and it alone solved the issue without KeyboardController.dismiss()

Using expo-router or react-navigation useFocusEffect :

useFocusEffect(
    useCallback(() => {
      setTimeout(() => inputRef?.current?.focus(), 250);
    }, []),
  );

This seems to do the trick right now, again thank you for your time to look into the problem!

kirillzyusko added a commit that referenced this issue Mar 26, 2024
## 📜 Description

Consume context values (as default values).

## 💡 Motivation and Context

When we navigate between screens, sometimes there can be a situation,
where keyboard is not moving. If we initialize values as a default one -
we'll have incorrect layout, because keyboard is actually shown (and
wasn't moved) so we will continue to use default values (keyboard
closed) while keyboard is actually open.

To fix this problem I specify default values from the context - context
always holds a current values. It fixes the problem 🙂

Closes
#398

## 📢 Changelog

### JS

- consume context values as a default one

## 🤔 How Has This Been Tested?

Tested on Android 10.

## 📸 Screenshots (if appropriate):

|Before|After|
|-------|----|
|<img width="346" alt="image"
src="https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/a28befcd-c52b-4db8-9ea9-4227b4067028">|<img
width="347" alt="image"
src="https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/d40e38de-2dfb-4079-9675-51d014b6c027">|

## 📝 Checklist

- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 android Android specific 🐛 bug Something isn't working 📚 components Anything related to the exported components of this library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants