Commit ac58fdd
authored
fix(Android, FormSheet): Prioritize keyboard animation over content resize animation (#3924)
## Description
This PR fixes a snap back that occurs in FormSheet for the following
combination:
- fitToContents
- TextInput
- SafeAreaView
- sheetResizeAnimationEnabled: true
There was a race condition between the keyboard insets animation (moving
the FormSheet above the keyboard) and the sheet's content resize
animation (caused by ignoring the bottom inset when the IME is present,
because the FormSheet will be moved above the navigation bar). When the
keyboard slides in, RN will recalculate the layout (sheet's height
changed, because of the ignored bottom inset). This layout change
triggers `updateSheetContentHeightWithAnimation` in the
SheetAnimationCoordinator, and two animations try to update properties
at the same time.
I think that the simplest solution is to let the keyboard animation set
the sheet position without interference from the content resize animator
by the time the keyboard slides in.
Closes:
software-mansion/react-native-screens-labs#1170
## Changes
- Introduced an `isKeyboardAnimationInProgress` flag.
- Added `onPrepare` and `onEnd` overrides to notify the keyboard
animation state.
- Updated `updateSheetContentHeightWithAnimation` - if a keyboard
animation is in progress, it now silently updates the bottom sheet
metrics and layout without firing a competing ValueAnimator.
## Before & after - visual documentation
| Before | After |
| --- | --- |
| <video
src="https://github.com/user-attachments/assets/1adfe76c-ff68-4fd8-b97b-13da8488d4ff"
/> | <video
src="https://github.com/user-attachments/assets/c7c1b77b-085a-4d78-a68a-458def1ece6e"
/> |
## Test plan
Test3336 - FormSheetWithFitToContentsWithTextInput case
## Checklist
- [ ] Included code example that can be used to test this change.
- [ ] For visual changes, included screenshots / GIFs / recordings
documenting the change.
- [ ] For API changes, updated relevant public types.
- [ ] Ensured that CI passes1 parent 49bbc28 commit ac58fdd
3 files changed
Lines changed: 31 additions & 3 deletions
File tree
- android/src/main/java/com/swmansion/rnscreens
- bottomsheet
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
279 | 287 | | |
280 | 288 | | |
281 | 289 | | |
| |||
294 | 302 | | |
295 | 303 | | |
296 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
297 | 309 | | |
298 | 310 | | |
299 | 311 | | |
| |||
Lines changed: 15 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
| |||
96 | 99 | | |
97 | 100 | | |
98 | 101 | | |
99 | | - | |
100 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
101 | 105 | | |
102 | | - | |
| 106 | + | |
103 | 107 | | |
104 | 108 | | |
105 | 109 | | |
| |||
207 | 211 | | |
208 | 212 | | |
209 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
210 | 222 | | |
211 | 223 | | |
212 | 224 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
443 | 443 | | |
444 | 444 | | |
445 | 445 | | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
446 | 450 | | |
447 | 451 | | |
448 | 452 | | |
| |||
0 commit comments