Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: new way for handling insets (#207)
## 馃摐 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
- Loading branch information