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

[RNKC-053] - native-stack + statusBarTranslucent causes incorrect positioning #51

Closed
kirillzyusko opened this issue Aug 12, 2022 · 2 comments · Fixed by #207
Closed
Assignees
Labels
🤖 android Android specific 🐛 bug Something isn't working

Comments

@kirillzyusko
Copy link
Owner

Describe the bug

using a combination of RN 0.69, native-stack and statusBarTranslucent causes some issues. Seems like keyboard insets are also applied automatically, and because of that positioning of views is incorrect.

Repo for reproducing

#50

To Reproduce
Steps to reproduce the behavior:

  1. Go to Native Stack
  2. Click on TextInput

Expected behavior

Views shouldn't react on keyboard appearance if they don't subscribed to useKeyboardAnimation animated values.

Screenshots

Expected Actual
image image

Smartphone (please complete the following information):

  • Desktop OS: Mac OS 12.5
  • Device: Pixel 3 (emulator)
  • OS: Android API 32
  • JS engine: JSC
  • Library version: 1.0.1

Additional context

Seems like it wasn't an issue in RN 0.68

@kirillzyusko kirillzyusko added the 🐛 bug Something isn't working label Aug 12, 2022
@kirillzyusko kirillzyusko self-assigned this Aug 12, 2022
@kirillzyusko kirillzyusko added the 🤖 android Android specific label Aug 12, 2022
@kirillzyusko
Copy link
Owner Author

The progress can be tracked here: https://github.com/kirillzyusko/react-native-screens/tree/refactor/removed-deprecated-replace-system-window-insets

@kirillzyusko
Copy link
Owner Author

Just found a workaround: if you don't change soft-input method in screens, where status bar translucency is controlled by react-native-screens, then everything works good (comparing to original hook - here we are not using useResizeMode hook):

const useKeyboardAnimationInNativeStack = () => {
  const context = useContext(KeyboardContext);

  return context.animated;
};

This is a temporary workaround - I'm still looking for a complete solution/fix 👀

kirillzyusko added a commit that referenced this issue Aug 18, 2023
## 📜 Description

Setup `onApplyWindowInsetsListener` that manages `systemBars` and
`navigationBar` on `rootView` to get correct and constant insets.

## 💡 Motivation and Context

If we setup `onApplyWindowInsetsListener` on `EdgeToEdgeReactViewGroup`,
then sometimes insets are including keyboard size (it's is `0, 1225`
(top, bottom) instead of expected `144, 84`).

I discovered that if we setup `onApplyWindowInsetsListener` on
`rootVIew` - in this case insets are always stable. So I reworked this
part (worth to note that `onApplyWindowInsetsListener` that detects
keyboard size changes still should listen to `EdgeToEdgeReactViewGroup`
because otherwise it's not working).

It fixes a problem with content jump, however the old approach (setting
`padding` for `action_bar_root`) is not working anymore - instead we
should apply margin. Last, but not least - we should setup it
asynchronously, because if we setup it in `onAttachedToWindow`/`init`
then it'll add undesired padding:

<p align="center">
<img width="257" alt="image"
src="https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/bac5586a-c91b-4162-8098-831b63607323">
</p>
<p align="center">
<i>Area in blue - undesired margin</i>
</p>

Fixes
#51

## 📢 Changelog

### Android
- apply `margin` to `action_bar_root` instead of `padding`;
- for managing paddings setup `onApplyWindowInsetsListener` on
`rootView`, keep `onApplyWindowInsetsListener` on `EdgeToEdgeView` just
for detecting keyboard size changes;
- setup `onApplyWindowInsetsListener` on `rootView` asynchronously (to
avoid unnecessary margin on mount);
- added `ThemedReactContext` extension that returns `rootView`;

## 🤔 How Has This Been Tested?

Tested (fabric/paper) on:
- Pixel 7 Pro (Android 13);
- Redmi note 5 Pro (Android 9);

## 📸 Screenshots (if appropriate):

|Before|After|
|------|-----|

|![telegram-cloud-photo-size-2-5402402906965133775-y](https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/e89ac555-4ef6-463d-81b6-7f66178fe506)|![telegram-cloud-photo-size-2-5402402906965133774-y](https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/1b94cb28-ce09-4977-967a-c7d1487377f9)|

## 📝 Checklist

- [x] CI successfully passed
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant