Skip to content
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

View Transition Events #32041

Merged
merged 2 commits into from
Jan 12, 2025
Merged

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Jan 10, 2025

This adds five events to <ViewTransition> that triggers when React wants to animate it.

  • onEnter: The <ViewTransition> or its parent Component is mounted and there's no other <ViewTransition> with the same name being deleted.
  • onExit: The <ViewTransition> or its parent Component is unmounted and there's no other <ViewTransition> with the same name being deleted.
  • onLayout: There are no updates to the content inside this <ViewTransition> boundary itself but the boundary has resized or moved due to other changes to siblings.
  • onShare: This <ViewTransition> is being mounted and another <ViewTransition> instance with the same name is being unmounted elsewhere.
  • onUpdate: The content of <ViewTransition> has changed either due to DOM mutations or because an inner child <ViewTransition> has resized.

Only one of these events is fired per Transition. If you want to cover all updates you have to listen to onLayout, onShare and onUpdate. We could potentially do something like fire onUpdate if onLayout or onShare isn't specified but it's a little sketchy to have behavior based on if someone is listening since it limits adding wrappers that may or may not need it.

Each takes a ViewTransitionInstance as an argument so you don't need a ref to animate it.

<ViewTransition onEnter={inst => inst.new.animate(keyframes, options)}>

The timing of this event is after the View Transition's ready state which means that's too late to do any changes to the View Transition's snapshots but now both the new and old pseudo-elements are ready to animate.

The order of onExit is parent first, where as the others are child first. This mimics effect mount/unmount.

I implement this by adding to a queue in the commit phase and then call it while we're finishing up the commit. This is after layout effects but before passive effects since passive effects fire after the animation is finished.

@react-sizebot
Copy link

react-sizebot commented Jan 10, 2025

Comparing: 0bf1f39...aac46d4

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 +0.05% 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js +0.05% 513.96 kB 514.24 kB = 91.78 kB 91.74 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.37% 550.36 kB 552.39 kB +0.30% 97.97 kB 98.27 kB
facebook-www/ReactDOM-prod.classic.js = 595.79 kB 595.79 kB = 104.85 kB 104.85 kB
facebook-www/ReactDOM-prod.modern.js = 586.21 kB 586.21 kB = 103.31 kB 103.30 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-reconciler/cjs/react-reconciler.production.js +0.43% 420.89 kB 422.71 kB +0.40% 67.84 kB 68.11 kB
oss-experimental/react-reconciler/cjs/react-reconciler.profiling.js +0.38% 473.91 kB 475.72 kB +0.40% 75.66 kB 75.96 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.37% 550.36 kB 552.39 kB +0.30% 97.97 kB 98.27 kB
oss-experimental/react-dom/cjs/react-dom-unstable_testing.production.js +0.36% 565.09 kB 567.12 kB +0.29% 101.59 kB 101.88 kB
oss-experimental/react-dom/cjs/react-dom-profiling.profiling.js +0.33% 606.60 kB 608.62 kB +0.31% 106.65 kB 106.98 kB
oss-experimental/react-art/cjs/react-art.production.js +0.33% 319.35 kB 320.42 kB +0.28% 54.26 kB 54.41 kB
oss-experimental/react-reconciler/cjs/react-reconciler.development.js +0.27% 707.89 kB 709.79 kB +0.28% 111.64 kB 111.96 kB
oss-experimental/react-art/cjs/react-art.development.js +0.20% 610.99 kB 612.22 kB +0.23% 97.22 kB 97.44 kB

Generated by 🚫 dangerJS against bcf15db

@sebmarkbage sebmarkbage merged commit 540efeb into facebook:main Jan 12, 2025
186 checks passed
github-actions bot pushed a commit that referenced this pull request Jan 12, 2025
This adds five events to `<ViewTransition>` that triggers when React
wants to animate it.

- `onEnter`: The `<ViewTransition>` or its parent Component is mounted
and there's no other `<ViewTransition>` with the same name being
deleted.
- `onExit`: The `<ViewTransition>` or its parent Component is unmounted
and there's no other `<ViewTransition>` with the same name being
deleted.
- `onLayout`: There are no updates to the content inside this
`<ViewTransition>` boundary itself but the boundary has resized or moved
due to other changes to siblings.
- `onShare`: This `<ViewTransition>` is being mounted and another
`<ViewTransition>` instance with the same name is being unmounted
elsewhere.
- `onUpdate`: The content of `<ViewTransition>` has changed either due
to DOM mutations or because an inner child `<ViewTransition>` has
resized.

Only one of these events is fired per Transition. If you want to cover
all updates you have to listen to `onLayout`, `onShare` and `onUpdate`.
We could potentially do something like fire `onUpdate` if `onLayout` or
`onShare` isn't specified but it's a little sketchy to have behavior
based on if someone is listening since it limits adding wrappers that
may or may not need it.

Each takes a `ViewTransitionInstance` as an argument so you don't need a
ref to animate it.

```js
<ViewTransition onEnter={inst => inst.new.animate(keyframes, options)}>
```

The timing of this event is after the View Transition's `ready` state
which means that's too late to do any changes to the View Transition's
snapshots but now both the new and old pseudo-elements are ready to
animate.

The order of `onExit` is parent first, where as the others are child
first. This mimics effect mount/unmount.

I implement this by adding to a queue in the commit phase and then call
it while we're finishing up the commit. This is after layout effects but
before passive effects since passive effects fire after the animation is
`finished`.

DiffTrain build for [540efeb](540efeb)
github-actions bot pushed a commit that referenced this pull request Jan 12, 2025
This adds five events to `<ViewTransition>` that triggers when React
wants to animate it.

- `onEnter`: The `<ViewTransition>` or its parent Component is mounted
and there's no other `<ViewTransition>` with the same name being
deleted.
- `onExit`: The `<ViewTransition>` or its parent Component is unmounted
and there's no other `<ViewTransition>` with the same name being
deleted.
- `onLayout`: There are no updates to the content inside this
`<ViewTransition>` boundary itself but the boundary has resized or moved
due to other changes to siblings.
- `onShare`: This `<ViewTransition>` is being mounted and another
`<ViewTransition>` instance with the same name is being unmounted
elsewhere.
- `onUpdate`: The content of `<ViewTransition>` has changed either due
to DOM mutations or because an inner child `<ViewTransition>` has
resized.

Only one of these events is fired per Transition. If you want to cover
all updates you have to listen to `onLayout`, `onShare` and `onUpdate`.
We could potentially do something like fire `onUpdate` if `onLayout` or
`onShare` isn't specified but it's a little sketchy to have behavior
based on if someone is listening since it limits adding wrappers that
may or may not need it.

Each takes a `ViewTransitionInstance` as an argument so you don't need a
ref to animate it.

```js
<ViewTransition onEnter={inst => inst.new.animate(keyframes, options)}>
```

The timing of this event is after the View Transition's `ready` state
which means that's too late to do any changes to the View Transition's
snapshots but now both the new and old pseudo-elements are ready to
animate.

The order of `onExit` is parent first, where as the others are child
first. This mimics effect mount/unmount.

I implement this by adding to a queue in the commit phase and then call
it while we're finishing up the commit. This is after layout effects but
before passive effects since passive effects fire after the animation is
`finished`.

DiffTrain build for [540efeb](540efeb)
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.

4 participants