@@ -11,21 +11,30 @@ import type {ReactNodeList} from 'shared/ReactTypes';
1111import type { FiberRoot } from './ReactInternalTypes' ;
1212import type { ViewTransitionInstance } from './ReactFiberConfig' ;
1313
14- import { getWorkInProgressRoot } from './ReactFiberWorkLoop' ;
14+ import {
15+ getWorkInProgressRoot ,
16+ getPendingTransitionTypes ,
17+ } from './ReactFiberWorkLoop' ;
1518
1619import { getIsHydrating } from './ReactFiberHydrationContext' ;
1720
1821import { getTreeId } from './ReactFiberTreeContext' ;
1922
23+ export type ViewTransitionClassPerType = {
24+ [ transitionType : 'default' | string ] : 'none' | string ,
25+ } ;
26+
27+ export type ViewTransitionClass = 'none' | string | ViewTransitionClassPerType ;
28+
2029export type ViewTransitionProps = {
2130 name ?: string ,
2231 children ?: ReactNodeList ,
23- className ?: 'none' | string ,
24- enter ?: 'none' | string ,
25- exit ?: 'none' | string ,
26- layout ?: 'none' | string ,
27- share ?: 'none' | string ,
28- update ?: 'none' | string ,
32+ className ?: ViewTransitionClass ,
33+ enter ?: ViewTransitionClass ,
34+ exit ?: ViewTransitionClass ,
35+ layout ?: ViewTransitionClass ,
36+ share ?: ViewTransitionClass ,
37+ update ?: ViewTransitionClass ,
2938 onEnter ?: ( instance : ViewTransitionInstance , types : Array < string > ) => void ,
3039 onExit ?: ( instance : ViewTransitionInstance , types : Array < string > ) => void ,
3140 onLayout ?: ( instance : ViewTransitionInstance , types : Array < string > ) => void ,
@@ -82,17 +91,49 @@ export function getViewTransitionName(
8291 return ( instance . autoName : any ) ;
8392}
8493
94+ function getClassNameByType ( classByType : ?ViewTransitionClass ) : ?string {
95+ if ( classByType == null || typeof classByType === 'string' ) {
96+ return classByType ;
97+ }
98+ let className : ?string = null ;
99+ const activeTypes = getPendingTransitionTypes ( ) ;
100+ if ( activeTypes !== null ) {
101+ for ( let i = 0 ; i < activeTypes . length ; i ++ ) {
102+ const match = classByType [ activeTypes [ i ] ] ;
103+ if ( match != null ) {
104+ if ( match === 'none' ) {
105+ // If anything matches "none" that takes precedence over any other
106+ // type that also matches.
107+ return 'none' ;
108+ }
109+ if ( className == null ) {
110+ className = match ;
111+ } else {
112+ className += ' ' + match ;
113+ }
114+ }
115+ }
116+ }
117+ if ( className == null ) {
118+ // We had no other matches. Match the default for this configuration.
119+ return classByType . default ;
120+ }
121+ return className ;
122+ }
123+
85124export function getViewTransitionClassName (
86- className : ?string ,
87- eventClassName : ?string ,
125+ defaultClass : ?ViewTransitionClass ,
126+ eventClass : ?ViewTransitionClass ,
88127) : ?string {
128+ const className : ?string = getClassNameByType ( defaultClass ) ;
129+ const eventClassName : ?string = getClassNameByType ( eventClass ) ;
89130 if ( eventClassName == null ) {
90131 return className ;
91132 }
92133 if ( eventClassName === 'none' ) {
93134 return eventClassName ;
94135 }
95- if ( className != null ) {
136+ if ( className != null && className !== 'none' ) {
96137 return className + ' ' + eventClassName ;
97138 }
98139 return eventClassName ;
0 commit comments