You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Document the full callback signatures with ViewTransitionInstance
and types arguments, cleanup function return values, instance
properties (group, imagePair, old, new), and per-callback behavior.
Copy file name to clipboardExpand all lines: src/content/reference/react/ViewTransition.md
+30-8Lines changed: 30 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,16 +84,38 @@ By default, `<ViewTransition>` animates with a smooth cross-fade. You can custom
84
84
85
85
#### Callback {/*events*/}
86
86
87
-
These callbacks allow you to adjust the animation imperatively using the [animate](https://developer.mozilla.org/en-US/docs/Web/API/Element/animate) APIs:
87
+
These callbacks allow you to control the animation imperatively using the [Web Animations API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API). React calls them after the View Transition's [`ready`](https://developer.mozilla.org/en-US/docs/Web/API/ViewTransition/ready) Promise resolves, once built-in default animations have already been computed. Only one callback fires per `<ViewTransition>` per Transition.
88
88
89
-
***optional**`onEnter`: A function. React calls `onEnter` after an "enter" animation.
90
-
***optional**`onExit`: A function. React calls `onExit` after an "exit" animation.
91
-
***optional**`onShare`: A function. React calls `onShare` after a "share" animation.
92
-
***optional**`onUpdate`: A function. React calls `onUpdate` after an "update" animation.
89
+
***optional**`onEnter`: `(instance, types) => void | (() => void)`. Called when this `<ViewTransition>` is inserted during a Transition without a matching named pair. Use this to animate the entering element imperatively.
90
+
***optional**`onExit`: `(instance, types) => void | (() => void)`. Called when this `<ViewTransition>` is removed during a Transition without a matching named pair. Use this to animate the exiting element imperatively.
91
+
***optional**`onShare`: `(instance, types) => void | (() => void)`. Called when this `<ViewTransition>` is part of a shared element Transition—where a named `<ViewTransition>` is deleted and another with the same name is inserted. Takes precedence over `onEnter` and `onExit`. Use this to animate the shared element Transition imperatively.
92
+
***optional**`onUpdate`: `(instance, types) => void | (() => void)`. Called when this `<ViewTransition>` has DOM mutations inside it, or when the boundary itself changes size or position due to a sibling change. Use this to animate content updates imperatively.
93
93
94
-
Each callback receives as arguments:
95
-
-`element`: The DOM element that was animated.
96
-
-`types`: The [Transition Types](/reference/react/addTransitionType) included in the animation.
94
+
Each callback receives two arguments:
95
+
96
+
*`instance`: A View Transition instance object that provides access to the view transition [pseudo-elements](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API/Using#the_view_transition_process). Call `instance.old.animate(keyframes, options)` and `instance.new.animate(keyframes, options)` to imperatively control the animation. The instance has these properties:
97
+
*`name`: The `view-transition-name` string for this boundary.
98
+
*`group`: The `::view-transition-group` pseudo-element. Supports `.animate()`, `.getAnimations()`, and `.getComputedStyle()`.
99
+
*`imagePair`: The `::view-transition-image-pair` pseudo-element. Supports `.animate()`, `.getAnimations()`, and `.getComputedStyle()`.
100
+
*`old`: The `::view-transition-old` pseudo-element (the snapshot of the previous state). Supports `.animate()`, `.getAnimations()`, and `.getComputedStyle()`.
101
+
*`new`: The `::view-transition-new` pseudo-element (the live representation of the new state). Supports `.animate()`, `.getAnimations()`, and `.getComputedStyle()`.
102
+
*`types`: An `Array<string>` of [Transition Types](/reference/react/addTransitionType) included in the animation. Empty array if no types were specified.
103
+
104
+
Each callback can optionally return a **cleanup function**. The cleanup function is called when the View Transition finishes, allowing you to cancel any manually started animations:
105
+
106
+
```js
107
+
<ViewTransition
108
+
onEnter={(instance, types) => {
109
+
constanim=instance.new.animate(
110
+
[{ opacity:0 }, { opacity:1 }],
111
+
{ duration:500 }
112
+
);
113
+
return () =>anim.cancel();
114
+
}}
115
+
>
116
+
<div>...</div>
117
+
</ViewTransition>
118
+
```
97
119
98
120
### View Transition Class {/*view-transition-class*/}
0 commit comments