-
Notifications
You must be signed in to change notification settings - Fork 50.9k
Expand file tree
/
Copy pathReactFiberConfigFabricWithViewTransition.js
More file actions
266 lines (237 loc) · 6.29 KB
/
ReactFiberConfigFabricWithViewTransition.js
File metadata and controls
266 lines (237 loc) · 6.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import type {TransitionTypes} from 'react/src/ReactTransitionType';
import type {
Instance,
Props,
Container,
SuspendedState,
GestureTimeline,
} from './ReactFiberConfigFabric';
import {allocateTag} from './ReactFiberConfigFabric';
const {
applyViewTransitionName: fabricApplyViewTransitionName,
createViewTransitionInstance: fabricCreateViewTransitionInstance,
startViewTransition: fabricStartViewTransition,
} = nativeFabricUIManager;
export type InstanceMeasurement = {
rect: {x: number, y: number, width: number, height: number},
abs: boolean,
clip: boolean,
view: boolean,
};
export type RunningViewTransition = {
finished: Promise<void>,
ready: Promise<void>,
...
};
interface ViewTransitionPseudoElementType extends mixin$Animatable {
_pseudo: string;
_name: string;
}
function ViewTransitionPseudoElement(
this: ViewTransitionPseudoElementType,
pseudo: string,
name: string,
) {
// TODO: Get the owner document from the root container.
this._pseudo = pseudo;
this._name = name;
}
export type ViewTransitionInstance = null | {
name: string,
old: mixin$Animatable,
new: mixin$Animatable,
...
};
export function restoreViewTransitionName(
instance: Instance,
props: Props,
): void {
if (__DEV__) {
console.warn('restoreViewTransitionName is not implemented');
}
}
// Cancel the old and new snapshots of viewTransitionName
export function cancelViewTransitionName(
instance: Instance,
oldName: string,
props: Props,
): void {
if (__DEV__) {
console.warn('cancelViewTransitionName is not implemented');
}
}
export function cancelRootViewTransitionName(rootContainer: Container): void {
// No-op
}
export function restoreRootViewTransitionName(rootContainer: Container): void {
// No-op
}
export function cloneRootViewTransitionContainer(
rootContainer: Container,
): Instance {
if (__DEV__) {
console.warn('cloneRootViewTransitionContainer is not implemented');
}
// $FlowFixMe[incompatible-return] Return empty stub
return null;
}
export function removeRootViewTransitionClone(
rootContainer: Container,
clone: Instance,
): void {
if (__DEV__) {
console.warn('removeRootViewTransitionClone is not implemented');
}
}
export function measureInstance(instance: Instance): InstanceMeasurement {
if (__DEV__) {
console.warn('measureInstance is not implemented');
}
return {
rect: {
x: 0,
y: 0,
width: 0,
height: 0,
},
abs: false,
clip: false,
// TODO: properly calculate whether instance is in viewport
view: true,
};
}
export function measureClonedInstance(instance: Instance): InstanceMeasurement {
if (__DEV__) {
console.warn('measureClonedInstance is not implemented');
}
return {
rect: {x: 0, y: 0, width: 0, height: 0},
abs: false,
clip: false,
view: true,
};
}
export function wasInstanceInViewport(
measurement: InstanceMeasurement,
): boolean {
return measurement.view;
}
export function hasInstanceChanged(
oldMeasurement: InstanceMeasurement,
newMeasurement: InstanceMeasurement,
): boolean {
if (__DEV__) {
console.warn('hasInstanceChanged is not implemented');
}
return false;
}
export function hasInstanceAffectedParent(
oldMeasurement: InstanceMeasurement,
newMeasurement: InstanceMeasurement,
): boolean {
if (__DEV__) {
console.warn('hasInstanceAffectedParent is not implemented');
}
return false;
}
export function startGestureTransition(
suspendedState: null | SuspendedState,
rootContainer: Container,
timeline: GestureTimeline,
rangeStart: number,
rangeEnd: number,
transitionTypes: null | TransitionTypes,
mutationCallback: () => void,
animateCallback: () => void,
errorCallback: (error: mixed) => void,
finishedAnimation: () => void,
): RunningViewTransition {
if (__DEV__) {
console.warn('startGestureTransition is not implemented');
}
return {
finished: Promise.resolve(),
ready: Promise.resolve(),
};
}
export function stopViewTransition(transition: RunningViewTransition): void {
if (__DEV__) {
console.warn('stopViewTransition is not implemented');
}
}
export function addViewTransitionFinishedListener(
transition: RunningViewTransition,
callback: () => void,
): void {
transition.finished.finally(callback);
}
export function createViewTransitionInstance(
name: string,
): ViewTransitionInstance {
const tag = allocateTag();
fabricCreateViewTransitionInstance(name, tag);
return {
name,
old: new (ViewTransitionPseudoElement: any)('old', name),
new: new (ViewTransitionPseudoElement: any)('new', name),
};
}
export function applyViewTransitionName(
instance: Instance,
name: string,
className: ?string,
): void {
// add view-transition-name to things that might animate for browser
fabricApplyViewTransitionName(instance.node, name, className);
}
export function startViewTransition(
suspendedState: null | SuspendedState,
rootContainer: Container,
transitionTypes: null | TransitionTypes,
mutationCallback: () => void,
layoutCallback: () => void,
afterMutationCallback: () => void,
spawnedWorkCallback: () => void,
passiveCallback: () => mixed,
errorCallback: (error: mixed) => void,
blockedCallback: (name: string) => void,
finishedAnimation: () => void,
): null | RunningViewTransition {
const transition = fabricStartViewTransition(
// mutation
() => {
mutationCallback(); // completeRoot should run here
layoutCallback();
afterMutationCallback();
},
);
if (transition == null) {
if (__DEV__) {
console.warn(
"startViewTransition didn't kick off transition in Fabric, the ViewTransition ReactNativeFeatureFlag might not be enabled.",
);
}
// Flush remaining work synchronously.
mutationCallback();
layoutCallback();
// Skip afterMutationCallback(). We don't need it since we're not animating.
spawnedWorkCallback();
// Skip passiveCallback(). Spawned work will schedule a task.
return null;
}
transition.ready.then(() => {
spawnedWorkCallback();
});
transition.finished.finally(() => {
passiveCallback();
});
return transition;
}