Repository navigation
Commit c3c3b7b
authored
Report Android safe-area insets after a last-pixel change settles
## Summary:
`SafeAreaInsetsObserver` reports a view's safe-area insets only when an edge moves more than one physical pixel from the last report, to match iOS's precision while the view moves. A change within that threshold is dropped for good. The last frame of a transition often moves a view by its last pixel, so a screen that slides in from the side can keep the one-pixel inset it had on the frame before it stopped. Which frames the observer sees varies, so the same screen can end with different insets each time it opens.
This change holds a change within the threshold and requests another frame (`postInvalidateOnAnimation`):
- If the insets are the same on the next frame, they have settled and are reported.
- If they moved again, they are held again. A view that moves a pixel or less per frame sends nothing until it stops or moves past the threshold.
- Insets within 0.01 px of the last report count as unchanged, so a settled view sends nothing more.
The threshold while the view moves is unchanged.
## Changelog:
[ANDROID] [FIXED] - Report a view's safe-area insets when a change of one pixel or less settles
## Test Plan:
```sh
./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests com.facebook.react.uimanager.SafeAreaInsetsObserverTest -Preact.internal.useHermesStable=true --console=plain
```
The new `lastPixelOfASlideIn_isReportedOnceTheViewHoldsStill` moves a view in by 3, 1 and 0 px of `translationX`, and expects the last pixel to be reported as `right: 0` on the frame after the view stops, and no report on the frame after that. It also expects one `postInvalidateOnAnimation` call, made on the frame the view stops: the test calls `onPreDraw` itself, and on a device nothing else would draw that next frame. The test fails on `main`, and fails with the `postInvalidateOnAnimation` call removed (0 frame requests instead of 1).
The observer keeps the held frame's insets as well as the last reported ones. Without them it cannot tell a view that has stopped from one still moving within the threshold, and `subpixelChanges_emitOnlyBeyondOnePhysicalPixelWithoutRoundingPayload` fails.
ktfmt and `git diff --check` are clean. Not run: a device or emulator.
Differential Revision: D135308620
Pull Request resolved: #603731 parent 91668b3 commit c3c3b7b
2 files changed
Lines changed: 75 additions & 5 deletions
File tree
- packages/react-native/ReactAndroid/src
- main/java/com/facebook/react/uimanager/internal
- test/java/com/facebook/react/uimanager
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
97 | 110 | | |
98 | 111 | | |
99 | 112 | | |
100 | 113 | | |
101 | 114 | | |
102 | 115 | | |
103 | 116 | | |
| 117 | + | |
104 | 118 | | |
105 | 119 | | |
106 | 120 | | |
| |||
113 | 127 | | |
114 | 128 | | |
115 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
116 | 133 | | |
117 | 134 | | |
118 | 135 | | |
| |||
127 | 144 | | |
128 | 145 | | |
129 | 146 | | |
| 147 | + | |
| 148 | + | |
130 | 149 | | |
131 | 150 | | |
132 | 151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
531 | 531 | | |
532 | 532 | | |
533 | 533 | | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
534 | 585 | | |
535 | 586 | | |
536 | 587 | | |
| |||
0 commit comments