main
js 50 lines 1.61 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10 import ReactSharedInternals from 'shared/ReactSharedInternals';
11 import {
12 enableViewTransition,
13 enableGestureTransition,
14 } from 'shared/ReactFeatureFlags';
15 import {startTransition} from './ReactStartTransition';
16
17 export type TransitionTypes = Array<string>;
18
19 export function addTransitionType(type: string): void {
20 if (enableViewTransition) {
21 const transition = ReactSharedInternals.T;
22 if (transition !== null) {
23 const transitionTypes = transition.types;
24 if (transitionTypes === null) {
25 transition.types = [type];
26 } else if (transitionTypes.indexOf(type) === -1) {
27 transitionTypes.push(type);
28 }
29 } else {
30 // We're in the async gap. Simulate an implicit startTransition around it.
31 if (__DEV__) {
32 if (ReactSharedInternals.asyncTransitions === 0) {
33 if (enableGestureTransition) {
34 console.error(
35 'addTransitionType can only be called inside a `startTransition()` ' +
36 'or `startGestureTransition()` callback. ' +
37 'It must be associated with a specific Transition.',
38 );
39 } else {
40 console.error(
41 'addTransitionType can only be called inside a `startTransition()` ' +
42 'callback. It must be associated with a specific Transition.',
43 );
44 }
45 }
46 }
47 startTransition(addTransitionType.bind(null, type));
48 }
49 }
50 }