Skip to content

Dispatch paired momentum scroll events for animated programmatic scrolls - #60162

Open
Abbondanzo wants to merge 1 commit into
react:mainfrom
Abbondanzo:export-D131264148
Open

Abbondanzo wants to merge 1 commit into
react:mainfrom
Abbondanzo:export-D131264148

Conversation

@Abbondanzo

Copy link
Copy Markdown
Contributor

Summary:
On iOS, an animated scrollTo/scrollToEnd dispatched onMomentumScrollEnd without a preceding onMomentumScrollBegin, and a non-animated one dispatched a lone onMomentumScrollEnd. Android dispatches a begin/end pair for animated programmatic scrolls and nothing for non-animated ones.

An earlier attempt dispatched onMomentumScrollBegin after starting the animation. When UIKit finished the animation synchronously, or never reported its end, the begin event arrived after its end event or was never matched. ScrollView treats a begin newer than the last end as "still animating" and captures every touch, so its children stopped responding.

Behind the fixProgrammaticScrollMomentumEventsIOS feature flag (off by default, on for the OSS canary release level), track an in-flight animated programmatic scroll and guarantee ordering and pairing:

  • Dispatch onMomentumScrollBegin before calling setContentOffset:animated:.
  • Dispatch onMomentumScrollEnd when the animation ends, when UIKit applies the offset without animating (no window, or offset applied immediately), when a drag interrupts the animation, when the view leaves the window, or from a fallback one second later if UIKit never reports the end.
  • Non-animated scrolls, and animated zoomToRect, dispatch neither event.

With the flag off, behavior is unchanged.

Changelog:
[iOS][Added] - fixProgrammaticScrollMomentumEventsIOS feature flag: onMomentumScrollBegin and onMomentumScrollEnd fire as a pair for animated scrollTo/scrollToEnd, and neither fires for non-animated scrolls

Reviewed By: andrewdacenko

Differential Revision: D131264148

Summary:
On iOS, an animated `scrollTo`/`scrollToEnd` dispatched `onMomentumScrollEnd` without a preceding `onMomentumScrollBegin`, and a non-animated one dispatched a lone `onMomentumScrollEnd`. Android dispatches a begin/end pair for animated programmatic scrolls and nothing for non-animated ones.

An earlier attempt dispatched `onMomentumScrollBegin` after starting the animation. When UIKit finished the animation synchronously, or never reported its end, the begin event arrived after its end event or was never matched. `ScrollView` treats a begin newer than the last end as "still animating" and captures every touch, so its children stopped responding.

Behind the `fixProgrammaticScrollMomentumEventsIOS` feature flag (off by default, on for the OSS canary release level), track an in-flight animated programmatic scroll and guarantee ordering and pairing:
- Dispatch `onMomentumScrollBegin` before calling `setContentOffset:animated:`.
- Dispatch `onMomentumScrollEnd` when the animation ends, when UIKit applies the offset without animating (no window, or offset applied immediately), when a drag interrupts the animation, when the view leaves the window, or from a fallback one second later if UIKit never reports the end.
- Non-animated scrolls, and animated `zoomToRect`, dispatch neither event.

With the flag off, behavior is unchanged.

Changelog:
[iOS][Added] - `fixProgrammaticScrollMomentumEventsIOS` feature flag: `onMomentumScrollBegin` and `onMomentumScrollEnd` fire as a pair for animated `scrollTo`/`scrollToEnd`, and neither fires for non-animated scrolls

Reviewed By: andrewdacenko

Differential Revision: D131264148
@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 19, 2026
@meta-codesync

meta-codesync Bot commented Nov 19, 2026

Copy link
Copy Markdown

@Abbondanzo has exported this pull request. If you are a Meta employee, you can view the originating Diff in D131264148.

@andrewdacenko andrewdacenko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

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-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants