8
*/
9
10
import ReactSharedInternals from 'shared/ReactSharedInternals';
11
-import {enableViewTransition} from 'shared/ReactFeatureFlags';
11
+import {
12
+ enableViewTransition,
13
+ enableGestureTransition,
14
+} from 'shared/ReactFeatureFlags';
15
16
export type TransitionTypes = Array<string>;
17
18
+// This one is only available synchronously so we don't need to use ReactSharedInternals
19
+// for this state. Instead, we track it in isomorphic and pass it to the renderer.
20
+export let pendingGestureTransitionTypes: null | TransitionTypes = null;
21
+
22
+export function pushPendingGestureTransitionTypes(): null | TransitionTypes {
23
+ const prev = pendingGestureTransitionTypes;
24
+ pendingGestureTransitionTypes = null;
25
+ return prev;
26
+}
27
+
28
+export function popPendingGestureTransitionTypes(
29
+ prev: null | TransitionTypes,
30
+): void {
31
+ pendingGestureTransitionTypes = prev;
32
+}
33
+
34
export function addTransitionType(type: string): void {
35
if (enableViewTransition) {
17
- const pendingTransitionTypes: null | TransitionTypes =
18
- ReactSharedInternals.V;
19
- if (pendingTransitionTypes === null) {
20
- ReactSharedInternals.V = [type];
21
- } else if (pendingTransitionTypes.indexOf(type) === -1) {
36
+ let pendingTransitionTypes: null | TransitionTypes;
37
+ if (
38
+ enableGestureTransition &&
39
+ ReactSharedInternals.T !== null &&
40
+ ReactSharedInternals.T.gesture !== null
41
+ ) {
42
+ // We're inside a startGestureTransition which is always sync.
43
+ pendingTransitionTypes = pendingGestureTransitionTypes;
44
+ if (pendingTransitionTypes === null) {
45
+ pendingTransitionTypes = pendingGestureTransitionTypes = [];
46
+ }
47
+ } else {
48
+ // Otherwise we're either inside a synchronous startTransition
49
+ // or in the async gap of one, which we track globally.
50
+ pendingTransitionTypes = ReactSharedInternals.V;
51
+ if (pendingTransitionTypes === null) {
52
+ pendingTransitionTypes = ReactSharedInternals.V = [];
53
+ }
54
+ }
55
+ if (pendingTransitionTypes.indexOf(type) === -1) {
56
pendingTransitionTypes.push(type);
57
}
58
}