Commit 540efeb
authored
View Transition Events (facebook#32041)
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`.1 parent 0bf1f39 commit 540efeb
File tree
4 files changed
+93
-19
lines changed- fixtures/view-transition/src/components
- packages/react-reconciler/src
4 files changed
+93
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | 4 | | |
7 | 5 | | |
8 | 6 | | |
| |||
37 | 35 | | |
38 | 36 | | |
39 | 37 | | |
40 | | - | |
41 | 38 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
53 | 47 | | |
54 | | - | |
| 48 | + | |
55 | 49 | | |
56 | 50 | | |
57 | 51 | | |
| |||
76 | 70 | | |
77 | 71 | | |
78 | 72 | | |
79 | | - | |
| 73 | + | |
80 | 74 | | |
81 | 75 | | |
82 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| 189 | + | |
189 | 190 | | |
190 | 191 | | |
191 | 192 | | |
| |||
649 | 650 | | |
650 | 651 | | |
651 | 652 | | |
| 653 | + | |
652 | 654 | | |
653 | 655 | | |
654 | 656 | | |
| |||
682 | 684 | | |
683 | 685 | | |
684 | 686 | | |
685 | | - | |
686 | 687 | | |
687 | 688 | | |
688 | 689 | | |
| |||
701 | 702 | | |
702 | 703 | | |
703 | 704 | | |
| 705 | + | |
704 | 706 | | |
705 | 707 | | |
706 | 708 | | |
707 | 709 | | |
708 | 710 | | |
709 | 711 | | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
710 | 717 | | |
711 | 718 | | |
712 | 719 | | |
| |||
764 | 771 | | |
765 | 772 | | |
766 | 773 | | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
767 | 777 | | |
768 | 778 | | |
769 | 779 | | |
| |||
811 | 821 | | |
812 | 822 | | |
813 | 823 | | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
814 | 829 | | |
815 | 830 | | |
816 | 831 | | |
| 832 | + | |
| 833 | + | |
817 | 834 | | |
818 | 835 | | |
819 | 836 | | |
| |||
1118 | 1135 | | |
1119 | 1136 | | |
1120 | 1137 | | |
| 1138 | + | |
| 1139 | + | |
1121 | 1140 | | |
1122 | 1141 | | |
1123 | 1142 | | |
| |||
3075 | 3094 | | |
3076 | 3095 | | |
3077 | 3096 | | |
| 3097 | + | |
| 3098 | + | |
3078 | 3099 | | |
3079 | 3100 | | |
3080 | 3101 | | |
| |||
3103 | 3124 | | |
3104 | 3125 | | |
3105 | 3126 | | |
| 3127 | + | |
| 3128 | + | |
3106 | 3129 | | |
| 3130 | + | |
| 3131 | + | |
| 3132 | + | |
| 3133 | + | |
| 3134 | + | |
| 3135 | + | |
| 3136 | + | |
| 3137 | + | |
3107 | 3138 | | |
3108 | 3139 | | |
3109 | 3140 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
24 | 29 | | |
25 | 30 | | |
26 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| |||
95 | 98 | | |
96 | 99 | | |
97 | 100 | | |
| 101 | + | |
98 | 102 | | |
99 | 103 | | |
100 | 104 | | |
| |||
649 | 653 | | |
650 | 654 | | |
651 | 655 | | |
| 656 | + | |
652 | 657 | | |
653 | 658 | | |
654 | 659 | | |
| |||
797 | 802 | | |
798 | 803 | | |
799 | 804 | | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
800 | 826 | | |
801 | 827 | | |
802 | 828 | | |
| |||
3322 | 3348 | | |
3323 | 3349 | | |
3324 | 3350 | | |
| 3351 | + | |
| 3352 | + | |
| 3353 | + | |
3325 | 3354 | | |
3326 | 3355 | | |
3327 | 3356 | | |
| |||
3673 | 3702 | | |
3674 | 3703 | | |
3675 | 3704 | | |
| 3705 | + | |
| 3706 | + | |
| 3707 | + | |
| 3708 | + | |
| 3709 | + | |
| 3710 | + | |
| 3711 | + | |
| 3712 | + | |
| 3713 | + | |
| 3714 | + | |
| 3715 | + | |
| 3716 | + | |
| 3717 | + | |
| 3718 | + | |
| 3719 | + | |
3676 | 3720 | | |
3677 | 3721 | | |
3678 | 3722 | | |
| |||
0 commit comments