Skip to content

Report Android safe-area insets after a last-pixel change settles - #60373

Draft
ide wants to merge 1 commit into
react:mainfrom
expo:@ide/android-safe-area-last-pixel
Draft

ide wants to merge 1 commit into
react:mainfrom
expo:@ide/android-safe-area-last-pixel

Conversation

@ide

@ide ide commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

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 reporting the one-pixel inset it had on the frame before it stopped. Whether this happens depends on which frames the observer sees, 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 they are reported.
  • If they moved again, they are held again. A view that moves less than a pixel per frame still 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 its last sub-pixel change settles

Test Plan:

SafeAreaInsetsObserverTest.lastPixelOfASlideIn_isReportedOnceTheViewHoldsStill moves a view in by 3, 1 and 0 px of translationX. It expects the last pixel to be reported as right: 0 on the frame after the view stops, and no further report on the frame after that.

Run for this branch on upstream/main 94aee19ac9: ktfmt --dry-run --set-exit-if-changed on the two changed Kotlin files (clean) and git diff --check (clean).

Run on this base (2026-11-28):

./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests com.facebook.react.uimanager.SafeAreaInsetsObserverTest -Preact.internal.useHermesStable=true --console=plain
  • With SafeAreaInsetsObserver.kt from main and the new test kept: 40 tests, 1 failed (lastPixelOfASlideIn_isReportedOnceTheViewHoldsStill).
  • On this branch: all 40 pass.

Not run: a device or emulator check.

🤖 Generated with Claude Code

`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
was dropped for good. The last frame of a transition often moves a view
by its last pixel, so a screen that slid in from the side kept
reporting the one-pixel inset it had on the frame before it stopped.
Which frames the observer saw decided whether this happened, so the
same screen could end with different insets each time it opened.

Hold a change within the threshold and request another frame. If the
insets are the same on that frame, they have settled and are reported.
If they moved again, they are held again, so a view that moves less
than a pixel per frame still 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.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Nov 28, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 28, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant