Repository navigation
Report Android safe-area insets after a last-pixel change settles - #60373
Conversation
Visual regressionNo visual differences at ios: no capture |
8228ad5 to
609daf0
Compare
chrfalch
left a comment
There was a problem hiding this comment.
The logic looks right to me, and the new test fails on main. (Commenting rather than approving since it's still a draft.)
One request on the test: lastPixelOfASlideIn_isReportedOnceTheViewHoldsStill calls observer.onPreDraw() by hand for the extra frame. On a device nothing would call it once the animation has ended. The view.postInvalidateOnAnimation() call is what makes that extra frame happen, so it is the core of the fix. Because the test drives every frame itself, it still passes if that call is removed. Could the test also assert that a frame was requested after the held sub-pixel change? For example, spy on the view and verify postInvalidateOnAnimation(), or check the invalidation through Robolectric's looper or shadow view. Then the request can't be dropped by accident later.
| private val geometry = Geometry() | ||
| private val insets = FloatArray(4) | ||
| private val lastInsets = FloatArray(4) | ||
| private val heldInsets = FloatArray(4) |
There was a problem hiding this comment.
Can we do this without the extra insets copy?
if hasHeldInsets is true (maybe rename to hasPendingInsetsToApply?) don't insets and lastInsets already contain the info you need?
There was a problem hiding this comment.
Renamed to hasPendingInsetsToApply, and the array to pendingInsets. The copy is still needed: lastInsets is the last value reported and insets is this frame's, but "settled" means this frame equals the previous one, which neither holds. Without the copy, a pending change is reported on the next frame even if the view is still moving, so a view moving less than a pixel per frame, as at the end of an ease-out, reports every other frame. subpixelChanges_emitOnlyBeyondOnePhysicalPixelWithoutRoundingPayload fails without it, and a comment now says why. If you'd rather have the simpler version and the extra events, I'll switch.
`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 a pixel or less 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>
609daf0 to
ee655bc
Compare
|
@chrfalch The test now uses a view that counts |
chrfalch
left a comment
There was a problem hiding this comment.
Thanks for the update, LGTM.
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D135308620. |
zeyap
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
|
This pull request was successfully merged by @ide in c3c3b7b When will my fix make it into a release? | How to file a pick request? |
Summary:
SafeAreaInsetsObserverreports 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):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:
The new
lastPixelOfASlideIn_isReportedOnceTheViewHoldsStillmoves a view in by 3, 1 and 0 px oftranslationX, and expects the last pixel to be reported asright: 0on the frame after the view stops, and no report on the frame after that. It also expects onepostInvalidateOnAnimationcall, made on the frame the view stops: the test callsonPreDrawitself, and on a device nothing else would draw that next frame. The test fails onmain, and fails with thepostInvalidateOnAnimationcall 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_emitOnlyBeyondOnePhysicalPixelWithoutRoundingPayloadfails.ktfmt and
git diff --checkare clean. Not run: a device or emulator.