@@ -120,6 +120,7 @@ import {
120120 startViewTransition ,
121121 startGestureTransition ,
122122 stopViewTransition ,
123+ addViewTransitionFinishedListener ,
123124 createViewTransitionInstance ,
124125 flushHydrationEvents ,
125126} from './ReactFiberConfig' ;
@@ -733,8 +734,9 @@ let pendingEffectsRenderEndTime: number = -0; // Profiling-only
733734let pendingPassiveTransitions : Array < Transition > | null = null ;
734735let pendingRecoverableErrors : null | Array < CapturedValue < mixed >> = null ;
735736let pendingViewTransition : null | RunningViewTransition = null ;
736- let pendingViewTransitionEvents : Array < ( types : Array < string > ) => void > | null =
737- null ;
737+ let pendingViewTransitionEvents : Array <
738+ ( types : Array < string > ) => void | ( ( ) => void ) ,
739+ > | null = null ;
738740let pendingTransitionTypes : null | TransitionTypes = null ;
739741let pendingDidIncludeRenderPhaseUpdate : boolean = false ;
740742let pendingSuspendedCommitReason : SuspendedCommitReason = null ; // Profiling-only
@@ -899,7 +901,10 @@ export function requestDeferredLane(): Lane {
899901
900902export function scheduleViewTransitionEvent (
901903 fiber : Fiber ,
902- callback : ?( instance : ViewTransitionInstance , types : Array < string > ) => void ,
904+ callback : ?(
905+ instance : ViewTransitionInstance ,
906+ types : Array < string > ,
907+ ) = > void | ( ( ) => void ) ,
903908) : void {
904909 if ( enableViewTransition ) {
905910 if ( callback != null ) {
@@ -925,7 +930,7 @@ export function scheduleGestureTransitionEvent(
925930 options : GestureOptionsRequired ,
926931 instance : ViewTransitionInstance ,
927932 types : Array < string > ,
928- ) = > void ,
933+ ) = > void | ( ( ) => void ) ,
929934) : void {
930935 if ( enableGestureTransition ) {
931936 if ( callback != null ) {
@@ -4143,6 +4148,7 @@ function flushSpawnedWork(): void {
41434148
41444149 pendingEffectsStatus = NO_PENDING_EFFECTS ;
41454150
4151+ const committedViewTransition = pendingViewTransition ;
41464152 pendingViewTransition = null ; // The view transition has now fully started.
41474153
41484154 // Tell Scheduler to yield at the end of the frame, so the browser has an
@@ -4262,9 +4268,14 @@ function flushSpawnedWork(): void {
42624268 // Normalize the type. This is lazily created only for events.
42634269 pendingTypes = [ ] ;
42644270 }
4265- for ( let i = 0 ; i < pendingEvents . length ; i ++ ) {
4266- const viewTransitionEvent = pendingEvents [ i ] ;
4267- viewTransitionEvent ( pendingTypes ) ;
4271+ if ( committedViewTransition !== null ) {
4272+ for ( let i = 0 ; i < pendingEvents . length ; i ++ ) {
4273+ const viewTransitionEvent = pendingEvents [ i ] ;
4274+ const cleanup = viewTransitionEvent ( pendingTypes ) ;
4275+ if ( cleanup !== undefined ) {
4276+ addViewTransitionFinishedListener ( committedViewTransition , cleanup ) ;
4277+ }
4278+ }
42684279 }
42694280 }
42704281 }
@@ -4532,9 +4543,18 @@ function flushGestureAnimations(): void {
45324543 // Normalize the type. This is lazily created only for events.
45334544 pendingTypes = [ ] ;
45344545 }
4535- for ( let i = 0 ; i < pendingEvents . length ; i ++ ) {
4536- const viewTransitionEvent = pendingEvents [ i ] ;
4537- viewTransitionEvent ( pendingTypes ) ;
4546+ const appliedGesture = root . pendingGestures ;
4547+ if ( appliedGesture !== null ) {
4548+ const runningTransition = appliedGesture . running ;
4549+ if ( runningTransition !== null ) {
4550+ for ( let i = 0 ; i < pendingEvents . length ; i ++ ) {
4551+ const viewTransitionEvent = pendingEvents [ i ] ;
4552+ const cleanup = viewTransitionEvent ( pendingTypes ) ;
4553+ if ( cleanup !== undefined ) {
4554+ addViewTransitionFinishedListener ( runningTransition , cleanup ) ;
4555+ }
4556+ }
4557+ }
45384558 }
45394559 }
45404560 }
0 commit comments