-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: incorrect
Modal
layout (if it was open while keyboard was visi…
…ble) (#624) ## 📜 Description Fixed a problem of `Modal` window not stretching to full height of the screen if `Modal` was opened when keyboard was open. ## 💡 Motivation and Context The problem was caused by the fact that I attached `OnApplyWindowListener` to a `rootView`. Somehow it was breaking a layout and always kept `keyboard space` if Modal was opened when keyboard is visible. The first approach was an attempt to resize that window. I've tried to specify `.layoutParams` but it was a failed attempt. Why? Because in the end I had two options: - either it wasn't working. - triggered a crash; After some time I wrote a code where I set `OnApplyWindowListener` conditionally: - if keyboard open then I set it to `DialogRootViewGroup` (I was getting an instance of `ReactModalHostView.hostVIew` via reflection); - if keyboard is not open then attach to root view. While it was working approach it has several downsides: - it is pretty complex (reflection, conditional code, making some internals methods `isKeyboardVisible` public one); - when you often toggle keyboard between emoji/text states, then at some point it may not update position properly. So I decided to look for a more robust approach - and I decided to apply changes that I used in `EdgeToEdgeReactViewGroup`. I created a custom view (0 width and height) and was attaching it to the `rootView` of the modal. In this case I don't inject my custom handler into `rootView`, so the layout is managed properly. While it works I noticed that sometimes red (animated) or gray (reanimated) circles may behave differently and eventually they have a broken state. The problem is that sometimes `onProgress`/`onEnd` may be triggered from main callback. I added `Suspense` mechanism where I can toggle off the functionality on demand and pause callbacks events. While it was working good on Android 12+ it wasn't working on Android < 12. The problem comes from the fact that on these OS versions Android emulates keyboard transitions, and listens to main window. So if we pause main window callback then all transitions are not working - the obvious way to fix is to make `.suspense` call conditional. I refactored that part (reduced code duplication, moved everything to reusable code, etc.) and now this PR is ready to be merged 😊 Closes #619 ## 📢 Changelog <!-- High level overview of important changes --> <!-- For example: fixed status bar manipulation; added new types declarations; --> <!-- If your changes don't affect one of platform/language below - then remove this platform/language --> ### JS - added `suspendable` to `cspell` ignore; ### E2E - added new test verifying a layout correctness when Modal has been opened with an opened keyboard; ### Android - added new `constants` package with new `Keyboard` class (with `IS_ANIMATION_EMULATED` field); - added `Suspendable` interface; - `KeyboardAnimationCallback` now implements `Suspendable`; - added early return to `onStart`/`onProgress`/`onEnd` callbacks if callback is suspended; - change `WindowInsetsCompat.CONSUMED` back to `insets`; - `syncKeyboardPosition` now can accept `height` and `visible` as params; - pass `KeyboardAnimationCallback` instance to `ModalAttachedWatcher` from `EdgeToEdgeReactViewGroup`; - add `eventView` to `rootView` of `Modal` when modal is shown; - set `setOnApplyWindowInsetsListener` to `eventView`; - remove `eventView` when `Modal` dismissed; - force `syncKeyboardPosition` to closed keyboard state when `Modal` is shown on Android 12+; - suspend main `KeyboardAnimationCallback` when `Modal` is shown on Android 12+; - unsuspend main `KeyboardAnimationCallback` when `Modal` is dismissed; ## 🤔 How Has This Been Tested? Tested manually on: - Pixel 3A (API 33); - Pixel 6 Pro (API 28); Additionally covered everything with e2e tests 😎 ## 📸 Screenshots (if appropriate): |Device|Before|After| |-------|-------|-----| |Pixel 3A (API 33)|<img width="412" alt="image" src="https://github.com/user-attachments/assets/3119149d-a5b5-41fd-911b-a761dbf80896">|<img width="405" alt="image" src="https://github.com/user-attachments/assets/05096970-5830-4e77-b8a2-bb9c3b90fa1a">| |Pixel 6 Pro (API 28)|<img width="417" alt="image" src="https://github.com/user-attachments/assets/4e89428f-9271-4e32-b837-66e6a3432b5d">|<img width="413" alt="image" src="https://github.com/user-attachments/assets/b027f7e1-7618-4511-a5f1-c0bbbf0d64f2">| ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
- Loading branch information
1 parent
4b52227
commit bb5e9e1
Showing
18 changed files
with
107 additions
and
16 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
android/src/main/java/com/reactnativekeyboardcontroller/constants/Keyboard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.reactnativekeyboardcontroller.constants | ||
|
||
import android.os.Build | ||
|
||
object Keyboard { | ||
val IS_ANIMATION_EMULATED = Build.VERSION.SDK_INT < Build.VERSION_CODES.R | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.