Skip to content

Add ScrollTimeline Polyfill for Swipe Recognizer using a new CustomTimeline protocol #33501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sebmarkbage
Copy link
Collaborator

The React API is just that we now accept this protocol as an alternative to a native AnimationTimeline to be passed to startGestureTransition. This is specifically the DOM version.

interface CustomTimeline {
  currentTime: number;
  animate(animation: Animation): void | (() => void);
}

Instead, of passing this to the Animation that we start to control the View Transition keyframes, we instead inverse the control and pass the Animation to this one. It lets any custom implementation drive the updates. It can do so by updating the time every frame or letting it run a time based animation (such as momentum scroll).

In this case I added a basic polyfill for ScrollTimeline in the example but we'll need a better one.

@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label Jun 10, 2025
@sebmarkbage sebmarkbage force-pushed the scrolltimelinepolyfill branch from 811e00b to a24876c Compare June 10, 2025 21:31
@react-sizebot
Copy link

react-sizebot commented Jun 10, 2025

Comparing: a947eba...e4bb93c

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB = 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 530.57 kB 530.57 kB = 93.67 kB 93.67 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.12% 651.66 kB 652.47 kB +0.15% 114.78 kB 114.96 kB
facebook-www/ReactDOM-prod.classic.js = 674.81 kB 674.81 kB = 118.78 kB 118.78 kB
facebook-www/ReactDOM-prod.modern.js = 665.30 kB 665.30 kB = 117.19 kB 117.19 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against e4bb93c

@sebmarkbage
Copy link
Collaborator Author

This is also how you'd implement other gestures that can't be modeled as scroll. Such as rotate and zoom gestures.

@@ -5,6 +5,8 @@ import React, {
unstable_startGestureTransition as startGestureTransition,
} from 'react';

import ScrollTimelinePolyfill from 'animation-timelines/scroll-timeline';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I published this as a third party package instead since it's generally useful and I can put more complex ones there.

https://www.npmjs.com/package/animation-timelines

@sebmarkbage sebmarkbage force-pushed the scrolltimelinepolyfill branch 3 times, most recently from 45ca295 to 761229f Compare June 18, 2025 22:33
This basically lets a custom implementation drive the Animation we start
on pseudo-elements.
@sebmarkbage sebmarkbage force-pushed the scrolltimelinepolyfill branch from 761229f to e4bb93c Compare June 20, 2025 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants