@onlynative/inertia 0.0.1-alpha.2 → 0.0.1-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -3
- package/dist/index.d.mts +259 -3
- package/dist/index.d.ts +259 -3
- package/dist/index.js +1866 -161
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1864 -165
- package/dist/index.mjs.map +1 -1
- package/dist/motion/Image.d.mts +1 -1
- package/dist/motion/Image.d.ts +1 -1
- package/dist/motion/Image.js +1696 -146
- package/dist/motion/Image.js.map +1 -1
- package/dist/motion/Image.mjs +1698 -148
- package/dist/motion/Image.mjs.map +1 -1
- package/dist/motion/Pressable.d.mts +1 -1
- package/dist/motion/Pressable.d.ts +1 -1
- package/dist/motion/Pressable.js +1696 -146
- package/dist/motion/Pressable.js.map +1 -1
- package/dist/motion/Pressable.mjs +1698 -148
- package/dist/motion/Pressable.mjs.map +1 -1
- package/dist/motion/ScrollView.d.mts +1 -1
- package/dist/motion/ScrollView.d.ts +1 -1
- package/dist/motion/ScrollView.js +1696 -146
- package/dist/motion/ScrollView.js.map +1 -1
- package/dist/motion/ScrollView.mjs +1698 -148
- package/dist/motion/ScrollView.mjs.map +1 -1
- package/dist/motion/Text.d.mts +1 -1
- package/dist/motion/Text.d.ts +1 -1
- package/dist/motion/Text.js +1696 -146
- package/dist/motion/Text.js.map +1 -1
- package/dist/motion/Text.mjs +1698 -148
- package/dist/motion/Text.mjs.map +1 -1
- package/dist/motion/View.d.mts +1 -1
- package/dist/motion/View.d.ts +1 -1
- package/dist/motion/View.js +1696 -146
- package/dist/motion/View.js.map +1 -1
- package/dist/motion/View.mjs +1698 -148
- package/dist/motion/View.mjs.map +1 -1
- package/dist/{types-DeZZzE_e.d.mts → types-CjztO3RW.d.mts} +89 -20
- package/dist/{types-DeZZzE_e.d.ts → types-CjztO3RW.d.ts} +89 -20
- package/llms.txt +54 -6
- package/package.json +1 -1
- package/src/__type-tests__/animate.test-d.tsx +88 -0
- package/src/index.ts +16 -1
- package/src/layout/index.ts +1 -0
- package/src/layout/resolveLayout.ts +54 -0
- package/src/motion/createMotionComponent.tsx +292 -153
- package/src/motion/installCheck.ts +69 -0
- package/src/transitions/easing.ts +3 -1
- package/src/transitions/index.ts +3 -0
- package/src/transitions/keys.ts +32 -0
- package/src/transitions/resolve.ts +1 -24
- package/src/transitions/sig.ts +40 -0
- package/src/transitions/spring.ts +41 -0
- package/src/types.ts +96 -18
- package/src/values/index.ts +14 -0
- package/src/values/useAnimation.ts +69 -0
- package/src/values/useGesture.ts +144 -0
- package/src/values/useMotionValue.ts +33 -0
- package/src/values/useScroll.ts +72 -0
- package/src/values/useSpring.ts +93 -0
- package/src/values/useTransform.ts +132 -0
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Platform, TurboModuleRegistry, ScrollView } from 'react-native';
|
|
2
2
|
import { createContext, forwardRef, useRef, useState, useEffect, useMemo, useContext } from 'react';
|
|
3
|
-
import Animated, { useAnimatedStyle,
|
|
3
|
+
import Animated, { useSharedValue, useAnimatedStyle, interpolateColor, useReducedMotion, withSequence, LinearTransition, runOnJS as runOnJS$1, withRepeat, withDelay, withDecay, withTiming, Easing, withSpring } from 'react-native-reanimated';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
var __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
9
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
10
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
11
|
+
}) : x)(function(x) {
|
|
12
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
13
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
14
|
+
});
|
|
15
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
16
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
17
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
18
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
7
19
|
var DEFAULT_MOTION_CONFIG = {
|
|
8
20
|
reducedMotion: "user"
|
|
9
21
|
};
|
|
@@ -13,40 +25,1424 @@ var MotionConfigContext = createContext(
|
|
|
13
25
|
function useMotionConfig() {
|
|
14
26
|
return useContext(MotionConfigContext);
|
|
15
27
|
}
|
|
16
|
-
function useShouldReduceMotion() {
|
|
17
|
-
const { reducedMotion } = useMotionConfig();
|
|
18
|
-
const osReduced = useReducedMotion();
|
|
19
|
-
if (reducedMotion === "never") return false;
|
|
20
|
-
if (reducedMotion === "always") return true;
|
|
21
|
-
return osReduced;
|
|
28
|
+
function useShouldReduceMotion() {
|
|
29
|
+
const { reducedMotion } = useMotionConfig();
|
|
30
|
+
const osReduced = useReducedMotion();
|
|
31
|
+
if (reducedMotion === "never") return false;
|
|
32
|
+
if (reducedMotion === "always") return true;
|
|
33
|
+
return osReduced;
|
|
34
|
+
}
|
|
35
|
+
var modality = "keyboard";
|
|
36
|
+
var installed = false;
|
|
37
|
+
function setKeyboard() {
|
|
38
|
+
modality = "keyboard";
|
|
39
|
+
}
|
|
40
|
+
function setPointer() {
|
|
41
|
+
modality = "pointer";
|
|
42
|
+
}
|
|
43
|
+
function ensureInstalled() {
|
|
44
|
+
if (installed) return;
|
|
45
|
+
if (Platform.OS !== "web") return;
|
|
46
|
+
if (typeof document === "undefined") return;
|
|
47
|
+
document.addEventListener("keydown", setKeyboard, true);
|
|
48
|
+
document.addEventListener("mousedown", setPointer, true);
|
|
49
|
+
document.addEventListener("pointerdown", setPointer, true);
|
|
50
|
+
document.addEventListener("touchstart", setPointer, true);
|
|
51
|
+
installed = true;
|
|
52
|
+
}
|
|
53
|
+
function isFocusVisible() {
|
|
54
|
+
if (Platform.OS !== "web") return true;
|
|
55
|
+
ensureInstalled();
|
|
56
|
+
return modality === "keyboard";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ../../node_modules/react-native-worklets/lib/module/logger.js
|
|
60
|
+
var PREFIX = "[Worklets]";
|
|
61
|
+
function formatMessage(message) {
|
|
62
|
+
return `${PREFIX} ${message}`;
|
|
63
|
+
}
|
|
64
|
+
var logger = {
|
|
65
|
+
warn(message) {
|
|
66
|
+
console.warn(formatMessage(message));
|
|
67
|
+
},
|
|
68
|
+
error(message) {
|
|
69
|
+
console.error(formatMessage(message));
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// ../../node_modules/react-native-worklets/lib/module/runtimeKind.js
|
|
74
|
+
var RuntimeKind = /* @__PURE__ */ (function(RuntimeKind2) {
|
|
75
|
+
RuntimeKind2[RuntimeKind2["ReactNative"] = 1] = "ReactNative";
|
|
76
|
+
RuntimeKind2[RuntimeKind2["UI"] = 2] = "UI";
|
|
77
|
+
RuntimeKind2[RuntimeKind2["Worker"] = 3] = "Worker";
|
|
78
|
+
return RuntimeKind2;
|
|
79
|
+
})({});
|
|
80
|
+
if (globalThis.__RUNTIME_KIND === void 0) {
|
|
81
|
+
globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsError.js
|
|
85
|
+
function WorkletsErrorConstructor(message) {
|
|
86
|
+
"worklet";
|
|
87
|
+
const prefix = "[Worklets]";
|
|
88
|
+
const errorInstance = new Error(message ? `${prefix} ${message}` : prefix);
|
|
89
|
+
errorInstance.name = `WorkletsError`;
|
|
90
|
+
return errorInstance;
|
|
91
|
+
}
|
|
92
|
+
function registerWorkletsError() {
|
|
93
|
+
"worklet";
|
|
94
|
+
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
|
|
95
|
+
globalThis.WorkletsError = WorkletsErrorConstructor;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
var WorkletsError = WorkletsErrorConstructor;
|
|
99
|
+
|
|
100
|
+
// ../../node_modules/react-native-worklets/lib/module/bundleUnpacker.js
|
|
101
|
+
var handleCache = /* @__PURE__ */ new WeakMap();
|
|
102
|
+
function bundleValueUnpacker(objectToUnpack, category, remoteFunctionName) {
|
|
103
|
+
const workletHash = objectToUnpack.__workletHash;
|
|
104
|
+
if (workletHash !== void 0) {
|
|
105
|
+
return getWorklet(workletHash, objectToUnpack.__closure);
|
|
106
|
+
} else if (objectToUnpack.__init !== void 0) {
|
|
107
|
+
let value = handleCache.get(objectToUnpack);
|
|
108
|
+
if (value === void 0) {
|
|
109
|
+
value = objectToUnpack.__init();
|
|
110
|
+
handleCache.set(objectToUnpack, value);
|
|
111
|
+
}
|
|
112
|
+
return value;
|
|
113
|
+
} else if (category === "RemoteFunction") {
|
|
114
|
+
const remoteFunctionHolder = () => {
|
|
115
|
+
const label = remoteFunctionName ? `function \`${remoteFunctionName}\`` : "anonymous function";
|
|
116
|
+
throw new WorkletsError(`Tried to synchronously call a non-worklet ${label} on the UI thread.
|
|
117
|
+
See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-synchronously-call-a-non-worklet-function-on-the-ui-thread for more details.`);
|
|
118
|
+
};
|
|
119
|
+
remoteFunctionHolder.__remoteFunction = objectToUnpack;
|
|
120
|
+
return remoteFunctionHolder;
|
|
121
|
+
} else {
|
|
122
|
+
throw new WorkletsError(`Data type in category "${category}" not recognized by value unpacker: "${globalThis._toString(objectToUnpack)}".`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function getWorklet(workletHash, closureVariables) {
|
|
126
|
+
let worklet;
|
|
127
|
+
if (__DEV__) {
|
|
128
|
+
try {
|
|
129
|
+
worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
|
|
130
|
+
} catch (_e) {
|
|
131
|
+
logger.error("Unable to resolve worklet with hash " + workletHash + ". Try reloading the app.");
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
|
|
135
|
+
}
|
|
136
|
+
return worklet;
|
|
137
|
+
}
|
|
138
|
+
var metroRequire = globalThis.__r;
|
|
139
|
+
function getWorkletFromMetroRequire(workletHash, closureVariables) {
|
|
140
|
+
const factory = metroRequire(workletHash).default;
|
|
141
|
+
return factory(closureVariables);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ../../node_modules/react-native-worklets/lib/module/callGuard.js
|
|
145
|
+
function callGuardDEV(fn, ...args) {
|
|
146
|
+
"worklet";
|
|
147
|
+
try {
|
|
148
|
+
return fn(...args);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
if (globalThis.__workletsModuleProxy) {
|
|
151
|
+
const {
|
|
152
|
+
message,
|
|
153
|
+
stack,
|
|
154
|
+
name,
|
|
155
|
+
jsEngine
|
|
156
|
+
} = error;
|
|
157
|
+
globalThis.__workletsModuleProxy.reportFatalErrorOnJS(message, stack ?? "", name ?? "WorkletsError", jsEngine ?? "Worklets");
|
|
158
|
+
} else {
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function setupCallGuard() {
|
|
164
|
+
"worklet";
|
|
165
|
+
if (!globalThis.__callGuardDEV) {
|
|
166
|
+
globalThis.__callGuardDEV = callGuardDEV;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// ../../node_modules/react-native-worklets/lib/module/errors.js
|
|
171
|
+
var _workletStackDetails = /* @__PURE__ */ new Map();
|
|
172
|
+
function registerWorkletStackDetails(hash, stackDetails) {
|
|
173
|
+
_workletStackDetails.set(hash, stackDetails);
|
|
174
|
+
}
|
|
175
|
+
function getBundleOffset(error) {
|
|
176
|
+
const frame = error.stack?.split("\n")?.[0];
|
|
177
|
+
if (frame) {
|
|
178
|
+
const parsedFrame = /@([^@]+):(\d+):(\d+)/.exec(frame);
|
|
179
|
+
if (parsedFrame) {
|
|
180
|
+
const [, file, line, col] = parsedFrame;
|
|
181
|
+
return [file, Number(line), Number(col)];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return ["unknown", 0, 0];
|
|
185
|
+
}
|
|
186
|
+
function processStack(stack) {
|
|
187
|
+
if (stack === "" || stack === void 0) {
|
|
188
|
+
return void 0;
|
|
189
|
+
}
|
|
190
|
+
const workletStackEntries = stack.match(/worklet_(\d+):(\d+):(\d+)/g);
|
|
191
|
+
let result = stack;
|
|
192
|
+
workletStackEntries?.forEach((match) => {
|
|
193
|
+
const [, hash, origLine, origCol] = match.split(/:|_/).map(Number);
|
|
194
|
+
const errorDetails = _workletStackDetails.get(hash);
|
|
195
|
+
if (!errorDetails) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const [error, lineOffset, colOffset] = errorDetails;
|
|
199
|
+
const [bundleFile, bundleLine, bundleCol] = getBundleOffset(error);
|
|
200
|
+
const line = origLine + bundleLine + lineOffset;
|
|
201
|
+
const col = origCol + bundleCol + colOffset;
|
|
202
|
+
result = result.replace(match, `${bundleFile}:${line}:${col}`);
|
|
203
|
+
});
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
function reportFatalRemoteError({
|
|
207
|
+
message,
|
|
208
|
+
stack,
|
|
209
|
+
name,
|
|
210
|
+
jsEngine
|
|
211
|
+
}, force) {
|
|
212
|
+
const error = new WorkletsError();
|
|
213
|
+
error.message = message;
|
|
214
|
+
error.stack = processStack(stack);
|
|
215
|
+
error.name = name;
|
|
216
|
+
error.jsEngine = jsEngine;
|
|
217
|
+
if (force) {
|
|
218
|
+
throw error;
|
|
219
|
+
} else {
|
|
220
|
+
globalThis.ErrorUtils.reportFatalError(error);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function registerReportFatalRemoteError() {
|
|
224
|
+
globalThis.__reportFatalRemoteError = reportFatalRemoteError;
|
|
225
|
+
}
|
|
226
|
+
var IS_JEST = !!process.env.JEST_WORKER_ID;
|
|
227
|
+
var IS_WEB = Platform.OS === "web";
|
|
228
|
+
var IS_WINDOWS = Platform.OS === "windows";
|
|
229
|
+
var SHOULD_BE_USE_WEB = IS_JEST || IS_WEB || IS_WINDOWS;
|
|
230
|
+
|
|
231
|
+
// ../../node_modules/react-native-worklets/lib/module/PlatformChecker/index.js
|
|
232
|
+
var IS_JEST2 = false;
|
|
233
|
+
var SHOULD_BE_USE_WEB2 = false;
|
|
234
|
+
if (globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
|
235
|
+
IS_JEST2 = IS_JEST;
|
|
236
|
+
SHOULD_BE_USE_WEB2 = SHOULD_BE_USE_WEB;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/common/setImmediatePolyfill.js
|
|
240
|
+
function setupSetImmediate() {
|
|
241
|
+
"worklet";
|
|
242
|
+
const setImmediatePolyfill = (callback, ...args) => {
|
|
243
|
+
return setTimeout(callback, 0, ...args);
|
|
244
|
+
};
|
|
245
|
+
const clearImmediatePolyfill = (immediateHandle) => {
|
|
246
|
+
clearTimeout(immediateHandle);
|
|
247
|
+
};
|
|
248
|
+
globalThis.setImmediate = setImmediatePolyfill;
|
|
249
|
+
globalThis.clearImmediate = clearImmediatePolyfill;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/common/setIntervalPolyfill.js
|
|
253
|
+
function setupSetInterval() {
|
|
254
|
+
"worklet";
|
|
255
|
+
const intervalHandleToTimeoutHandle = /* @__PURE__ */ new Map();
|
|
256
|
+
const setIntervalPolyfill = (callback, delay = 0, ...args) => {
|
|
257
|
+
let intervalHandle = 0;
|
|
258
|
+
const repeatingCallback = () => {
|
|
259
|
+
const timeoutHandle = setTimeout(repeatingCallback, delay);
|
|
260
|
+
intervalHandleToTimeoutHandle.set(intervalHandle, timeoutHandle);
|
|
261
|
+
callback(...args);
|
|
262
|
+
};
|
|
263
|
+
intervalHandle = setTimeout(repeatingCallback, delay);
|
|
264
|
+
intervalHandleToTimeoutHandle.set(intervalHandle, intervalHandle);
|
|
265
|
+
return intervalHandle;
|
|
266
|
+
};
|
|
267
|
+
const clearIntervalPolyfill = (intervalHandle) => {
|
|
268
|
+
const timeoutHandle = intervalHandleToTimeoutHandle.get(intervalHandle);
|
|
269
|
+
clearTimeout(timeoutHandle);
|
|
270
|
+
intervalHandleToTimeoutHandle.delete(intervalHandle);
|
|
271
|
+
};
|
|
272
|
+
globalThis.setInterval = setIntervalPolyfill;
|
|
273
|
+
globalThis.clearInterval = clearIntervalPolyfill;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js
|
|
277
|
+
function mockedRequestAnimationFrame(callback) {
|
|
278
|
+
return setTimeout(() => callback(performance.now()), 0);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// ../../node_modules/react-native-worklets/lib/module/isSynchronizable.js
|
|
282
|
+
function isSynchronizable(value) {
|
|
283
|
+
return typeof value === "object" && value !== null && "__synchronizableRef" in value && value.__synchronizableRef === true;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// ../../node_modules/react-native-worklets/lib/module/serializableMappingCache.js
|
|
287
|
+
var serializableMappingFlag = /* @__PURE__ */ Symbol("serializable flag");
|
|
288
|
+
var cache = SHOULD_BE_USE_WEB2 ? null : /* @__PURE__ */ new WeakMap();
|
|
289
|
+
var serializableMappingCache = SHOULD_BE_USE_WEB2 ? {
|
|
290
|
+
set() {
|
|
291
|
+
},
|
|
292
|
+
get() {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
} : {
|
|
296
|
+
set(serializable, serializableRef) {
|
|
297
|
+
cache.set(serializable, serializableRef || serializableMappingFlag);
|
|
298
|
+
},
|
|
299
|
+
get: cache.get.bind(cache)
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// ../../node_modules/react-native-worklets/lib/module/utils/jsVersion.js
|
|
303
|
+
var jsVersion = "0.5.1";
|
|
304
|
+
|
|
305
|
+
// ../../node_modules/react-native-worklets/lib/module/workletFunction.js
|
|
306
|
+
function isWorkletFunction(value) {
|
|
307
|
+
"worklet";
|
|
308
|
+
return (
|
|
309
|
+
// `__workletHash` isn't extracted in Worklet Runtimes.
|
|
310
|
+
typeof value === "function" && !!value.__workletHash
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsModule/JSWorklets.js
|
|
315
|
+
function createJSWorkletsModule() {
|
|
316
|
+
return new JSWorklets();
|
|
317
|
+
}
|
|
318
|
+
var requestAnimationFrameImpl = IS_JEST2 || !globalThis.requestAnimationFrame ? mockedRequestAnimationFrame : globalThis.requestAnimationFrame;
|
|
319
|
+
var JSWorklets = class {
|
|
320
|
+
createSerializable() {
|
|
321
|
+
throw new WorkletsError("createSerializable should never be called in JSWorklets.");
|
|
322
|
+
}
|
|
323
|
+
createSerializableString() {
|
|
324
|
+
throw new WorkletsError("createSerializableString should never be called in JSWorklets.");
|
|
325
|
+
}
|
|
326
|
+
createSerializableNumber() {
|
|
327
|
+
throw new WorkletsError("createSerializableNumber should never be called in JSWorklets.");
|
|
328
|
+
}
|
|
329
|
+
createSerializableBoolean() {
|
|
330
|
+
throw new WorkletsError("createSerializableBoolean should never be called in JSWorklets.");
|
|
331
|
+
}
|
|
332
|
+
createSerializableBigInt() {
|
|
333
|
+
throw new WorkletsError("createSerializableBigInt should never be called in JSWorklets.");
|
|
334
|
+
}
|
|
335
|
+
createSerializableUndefined() {
|
|
336
|
+
throw new WorkletsError("createSerializableUndefined should never be called in JSWorklets.");
|
|
337
|
+
}
|
|
338
|
+
createSerializableNull() {
|
|
339
|
+
throw new WorkletsError("createSerializableNull should never be called in JSWorklets.");
|
|
340
|
+
}
|
|
341
|
+
createSerializableTurboModuleLike() {
|
|
342
|
+
throw new WorkletsError("createSerializableTurboModuleLike should never be called in JSWorklets.");
|
|
343
|
+
}
|
|
344
|
+
createSerializableObject() {
|
|
345
|
+
throw new WorkletsError("createSerializableObject should never be called in JSWorklets.");
|
|
346
|
+
}
|
|
347
|
+
createSerializableMap() {
|
|
348
|
+
throw new WorkletsError("createSerializableMap should never be called in JSWorklets.");
|
|
349
|
+
}
|
|
350
|
+
createSerializableSet() {
|
|
351
|
+
throw new WorkletsError("createSerializableSet should never be called in JSWorklets.");
|
|
352
|
+
}
|
|
353
|
+
createSerializableImport() {
|
|
354
|
+
throw new WorkletsError("createSerializableImport should never be called in JSWorklets.");
|
|
355
|
+
}
|
|
356
|
+
createSerializableHostObject() {
|
|
357
|
+
throw new WorkletsError("createSerializableHostObject should never be called in JSWorklets.");
|
|
358
|
+
}
|
|
359
|
+
createSerializableArray() {
|
|
360
|
+
throw new WorkletsError("createSerializableArray should never be called in JSWorklets.");
|
|
361
|
+
}
|
|
362
|
+
createSerializableInitializer() {
|
|
363
|
+
throw new WorkletsError("createSerializableInitializer should never be called in JSWorklets.");
|
|
364
|
+
}
|
|
365
|
+
createSerializableFunction() {
|
|
366
|
+
throw new WorkletsError("createSerializableFunction should never be called in JSWorklets.");
|
|
367
|
+
}
|
|
368
|
+
createSerializableWorklet() {
|
|
369
|
+
throw new WorkletsError("createSerializableWorklet should never be called in JSWorklets.");
|
|
370
|
+
}
|
|
371
|
+
scheduleOnUI(worklet) {
|
|
372
|
+
requestAnimationFrameImpl(worklet);
|
|
373
|
+
}
|
|
374
|
+
executeOnUIRuntimeSync() {
|
|
375
|
+
throw new WorkletsError("`executeOnUIRuntimeSync` is not available in JSWorklets.");
|
|
376
|
+
}
|
|
377
|
+
createWorkletRuntime() {
|
|
378
|
+
throw new WorkletsError("createWorkletRuntime is not available in JSWorklets.");
|
|
379
|
+
}
|
|
380
|
+
scheduleOnRuntime() {
|
|
381
|
+
throw new WorkletsError("scheduleOnRuntime is not available in JSWorklets.");
|
|
382
|
+
}
|
|
383
|
+
createSynchronizable() {
|
|
384
|
+
throw new WorkletsError("createSynchronizable should never be called in JSWorklets.");
|
|
385
|
+
}
|
|
386
|
+
synchronizableGetDirty() {
|
|
387
|
+
throw new WorkletsError("synchronizableGetDirty should never be called in JSWorklets.");
|
|
388
|
+
}
|
|
389
|
+
synchronizableGetBlocking() {
|
|
390
|
+
throw new WorkletsError("synchronizableGetBlocking should never be called in JSWorklets.");
|
|
391
|
+
}
|
|
392
|
+
synchronizableSetBlocking() {
|
|
393
|
+
throw new WorkletsError("synchronizableSetBlocking should never be called in JSWorklets.");
|
|
394
|
+
}
|
|
395
|
+
synchronizableLock() {
|
|
396
|
+
throw new WorkletsError("synchronizableLock should never be called in JSWorklets.");
|
|
397
|
+
}
|
|
398
|
+
synchronizableUnlock() {
|
|
399
|
+
throw new WorkletsError("synchronizableUnlock should never be called in JSWorklets.");
|
|
400
|
+
}
|
|
401
|
+
reportFatalErrorOnJS() {
|
|
402
|
+
throw new WorkletsError("reportFatalErrorOnJS should never be called in JSWorklets.");
|
|
403
|
+
}
|
|
404
|
+
getStaticFeatureFlag() {
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
setDynamicFeatureFlag() {
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
var NativeWorkletsModule_default = TurboModuleRegistry.get("WorkletsModule");
|
|
411
|
+
|
|
412
|
+
// ../../node_modules/react-native-worklets/lib/module/specs/index.js
|
|
413
|
+
var WorkletsTurboModule = globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative ? NativeWorkletsModule_default : (
|
|
414
|
+
// In Bundle Mode, on Worklet Runtimes `RNWorkletsTurboModule` isn't
|
|
415
|
+
// available and shouldn't be accessed. We return null here
|
|
416
|
+
// to keep the same codebase for the Bundle Mode and legacy behavior.
|
|
417
|
+
null
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
// ../../node_modules/react-native-worklets/lib/module/utils/checkCppVersion.js
|
|
421
|
+
function checkCppVersion() {
|
|
422
|
+
const cppVersion = global._WORKLETS_VERSION_CPP;
|
|
423
|
+
if (cppVersion === void 0) {
|
|
424
|
+
logger.warn(`Couldn't determine the version of the native part of Worklets.
|
|
425
|
+
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#couldnt-determine-the-version-of-the-native-part-of-worklets\` for more details.`);
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const ok = matchVersion(jsVersion, cppVersion);
|
|
429
|
+
if (!ok) {
|
|
430
|
+
throw new WorkletsError(`Mismatch between JavaScript part and native part of Worklets (${jsVersion} vs ${cppVersion}).
|
|
431
|
+
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-part-and-native-part-of-worklets\` for more details.`);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
function matchVersion(version1, version2) {
|
|
435
|
+
if (version1.match(/^\d+\.\d+\.\d+$/) && version2.match(/^\d+\.\d+\.\d+$/)) {
|
|
436
|
+
const [major1, minor1] = version1.split(".");
|
|
437
|
+
const [major2, minor2] = version2.split(".");
|
|
438
|
+
return major1 === major2 && minor1 === minor2;
|
|
439
|
+
} else {
|
|
440
|
+
return version1 === version2;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsModule/NativeWorklets.js
|
|
445
|
+
function createNativeWorkletsModule() {
|
|
446
|
+
return new NativeWorklets();
|
|
447
|
+
}
|
|
448
|
+
var _workletsModuleProxy, _serializableUndefined, _serializableNull, _serializableTrue, _serializableFalse;
|
|
449
|
+
var NativeWorklets = class {
|
|
450
|
+
constructor() {
|
|
451
|
+
__privateAdd(this, _workletsModuleProxy);
|
|
452
|
+
__privateAdd(this, _serializableUndefined);
|
|
453
|
+
__privateAdd(this, _serializableNull);
|
|
454
|
+
__privateAdd(this, _serializableTrue);
|
|
455
|
+
__privateAdd(this, _serializableFalse);
|
|
456
|
+
globalThis._WORKLETS_VERSION_JS = jsVersion;
|
|
457
|
+
if (global.__workletsModuleProxy === void 0 && globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
|
458
|
+
WorkletsTurboModule?.installTurboModule();
|
|
459
|
+
}
|
|
460
|
+
if (global.__workletsModuleProxy === void 0) {
|
|
461
|
+
throw new WorkletsError(`Native part of Worklets doesn't seem to be initialized.
|
|
462
|
+
See https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#native-part-of-worklets-doesnt-seem-to-be-initialized for more details.`);
|
|
463
|
+
}
|
|
464
|
+
if (__DEV__) {
|
|
465
|
+
checkCppVersion();
|
|
466
|
+
}
|
|
467
|
+
__privateSet(this, _workletsModuleProxy, global.__workletsModuleProxy);
|
|
468
|
+
__privateSet(this, _serializableNull, __privateGet(this, _workletsModuleProxy).createSerializableNull());
|
|
469
|
+
__privateSet(this, _serializableUndefined, __privateGet(this, _workletsModuleProxy).createSerializableUndefined());
|
|
470
|
+
__privateSet(this, _serializableTrue, __privateGet(this, _workletsModuleProxy).createSerializableBoolean(true));
|
|
471
|
+
__privateSet(this, _serializableFalse, __privateGet(this, _workletsModuleProxy).createSerializableBoolean(false));
|
|
472
|
+
}
|
|
473
|
+
createSerializable(value, shouldPersistRemote, nativeStateSource) {
|
|
474
|
+
return __privateGet(this, _workletsModuleProxy).createSerializable(value, shouldPersistRemote, nativeStateSource);
|
|
475
|
+
}
|
|
476
|
+
createSerializableImport(from, to) {
|
|
477
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableImport(from, to);
|
|
478
|
+
}
|
|
479
|
+
createSerializableString(str) {
|
|
480
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableString(str);
|
|
481
|
+
}
|
|
482
|
+
createSerializableNumber(num) {
|
|
483
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableNumber(num);
|
|
484
|
+
}
|
|
485
|
+
createSerializableBoolean(bool) {
|
|
486
|
+
return bool ? __privateGet(this, _serializableTrue) : __privateGet(this, _serializableFalse);
|
|
487
|
+
}
|
|
488
|
+
createSerializableBigInt(bigInt) {
|
|
489
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableBigInt(bigInt);
|
|
490
|
+
}
|
|
491
|
+
createSerializableUndefined() {
|
|
492
|
+
return __privateGet(this, _serializableUndefined);
|
|
493
|
+
}
|
|
494
|
+
createSerializableNull() {
|
|
495
|
+
return __privateGet(this, _serializableNull);
|
|
496
|
+
}
|
|
497
|
+
createSerializableTurboModuleLike(props, proto) {
|
|
498
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableTurboModuleLike(props, proto);
|
|
499
|
+
}
|
|
500
|
+
createSerializableObject(obj, shouldRetainRemote, nativeStateSource) {
|
|
501
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableObject(obj, shouldRetainRemote, nativeStateSource);
|
|
502
|
+
}
|
|
503
|
+
createSerializableHostObject(obj) {
|
|
504
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableHostObject(obj);
|
|
505
|
+
}
|
|
506
|
+
createSerializableArray(array, shouldRetainRemote) {
|
|
507
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableArray(array, shouldRetainRemote);
|
|
508
|
+
}
|
|
509
|
+
createSerializableMap(keys, values) {
|
|
510
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableMap(keys, values);
|
|
511
|
+
}
|
|
512
|
+
createSerializableSet(values) {
|
|
513
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableSet(values);
|
|
514
|
+
}
|
|
515
|
+
createSerializableInitializer(obj) {
|
|
516
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableInitializer(obj);
|
|
517
|
+
}
|
|
518
|
+
createSerializableFunction(func) {
|
|
519
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableFunction(func);
|
|
520
|
+
}
|
|
521
|
+
createSerializableWorklet(worklet, shouldPersistRemote) {
|
|
522
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableWorklet(worklet, shouldPersistRemote);
|
|
523
|
+
}
|
|
524
|
+
scheduleOnUI(serializable) {
|
|
525
|
+
return __privateGet(this, _workletsModuleProxy).scheduleOnUI(serializable);
|
|
526
|
+
}
|
|
527
|
+
executeOnUIRuntimeSync(serializable) {
|
|
528
|
+
return __privateGet(this, _workletsModuleProxy).executeOnUIRuntimeSync(serializable);
|
|
529
|
+
}
|
|
530
|
+
createWorkletRuntime(name, initializer, useDefaultQueue, customQueue, enableEventLoop) {
|
|
531
|
+
return __privateGet(this, _workletsModuleProxy).createWorkletRuntime(name, initializer, useDefaultQueue, customQueue, enableEventLoop);
|
|
532
|
+
}
|
|
533
|
+
scheduleOnRuntime(workletRuntime, serializableWorklet) {
|
|
534
|
+
return __privateGet(this, _workletsModuleProxy).scheduleOnRuntime(workletRuntime, serializableWorklet);
|
|
535
|
+
}
|
|
536
|
+
createSynchronizable(value) {
|
|
537
|
+
return __privateGet(this, _workletsModuleProxy).createSynchronizable(value);
|
|
538
|
+
}
|
|
539
|
+
synchronizableGetDirty(synchronizableRef) {
|
|
540
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableGetDirty(synchronizableRef);
|
|
541
|
+
}
|
|
542
|
+
synchronizableGetBlocking(synchronizableRef) {
|
|
543
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableGetBlocking(synchronizableRef);
|
|
544
|
+
}
|
|
545
|
+
synchronizableSetBlocking(synchronizableRef, value) {
|
|
546
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableSetBlocking(synchronizableRef, value);
|
|
547
|
+
}
|
|
548
|
+
synchronizableLock(synchronizableRef) {
|
|
549
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableLock(synchronizableRef);
|
|
550
|
+
}
|
|
551
|
+
synchronizableUnlock(synchronizableRef) {
|
|
552
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableUnlock(synchronizableRef);
|
|
553
|
+
}
|
|
554
|
+
reportFatalErrorOnJS(message, stack, name, jsEngine) {
|
|
555
|
+
return __privateGet(this, _workletsModuleProxy).reportFatalErrorOnJS(message, stack, name, jsEngine);
|
|
556
|
+
}
|
|
557
|
+
getStaticFeatureFlag(name) {
|
|
558
|
+
return __privateGet(this, _workletsModuleProxy).getStaticFeatureFlag(name);
|
|
559
|
+
}
|
|
560
|
+
setDynamicFeatureFlag(name, value) {
|
|
561
|
+
__privateGet(this, _workletsModuleProxy).setDynamicFeatureFlag(name, value);
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
_workletsModuleProxy = new WeakMap();
|
|
565
|
+
_serializableUndefined = new WeakMap();
|
|
566
|
+
_serializableNull = new WeakMap();
|
|
567
|
+
_serializableTrue = new WeakMap();
|
|
568
|
+
_serializableFalse = new WeakMap();
|
|
569
|
+
|
|
570
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsModule/workletsModuleInstance.js
|
|
571
|
+
var WorkletsModule = SHOULD_BE_USE_WEB2 ? createJSWorkletsModule() : createNativeWorkletsModule();
|
|
572
|
+
|
|
573
|
+
// ../../node_modules/react-native-worklets/lib/module/serializable.js
|
|
574
|
+
var MAGIC_KEY = "REANIMATED_MAGIC_KEY";
|
|
575
|
+
function isHostObject(value) {
|
|
576
|
+
"worklet";
|
|
577
|
+
return MAGIC_KEY in value;
|
|
578
|
+
}
|
|
579
|
+
function isPlainJSObject(object) {
|
|
580
|
+
"worklet";
|
|
581
|
+
return Object.getPrototypeOf(object) === Object.prototype;
|
|
582
|
+
}
|
|
583
|
+
function isTurboModuleLike(object) {
|
|
584
|
+
return isHostObject(Object.getPrototypeOf(object));
|
|
585
|
+
}
|
|
586
|
+
function getFromCache(value) {
|
|
587
|
+
const cached = serializableMappingCache.get(value);
|
|
588
|
+
if (cached === serializableMappingFlag) {
|
|
589
|
+
return value;
|
|
590
|
+
}
|
|
591
|
+
return cached;
|
|
592
|
+
}
|
|
593
|
+
var INACCESSIBLE_OBJECT = {
|
|
594
|
+
__init: () => {
|
|
595
|
+
"worklet";
|
|
596
|
+
return new Proxy({}, {
|
|
597
|
+
get: (_, prop) => {
|
|
598
|
+
if (prop === "_isReanimatedSharedValue" || prop === "__remoteFunction") {
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
throw new WorkletsError(`Trying to access property \`${String(prop)}\` of an object which cannot be sent to the UI runtime.`);
|
|
602
|
+
},
|
|
603
|
+
set: () => {
|
|
604
|
+
throw new WorkletsError("Trying to write to an object which cannot be sent to the UI runtime.");
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
var VALID_ARRAY_VIEWS_NAMES = ["Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt64Array", "BigUint64Array", "DataView"];
|
|
610
|
+
var DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD = 30;
|
|
611
|
+
var processedObjectAtThresholdDepth;
|
|
612
|
+
function createSerializableWeb(value) {
|
|
613
|
+
return value;
|
|
614
|
+
}
|
|
615
|
+
function createSerializableNative(value, shouldPersistRemote = false, depth = 0) {
|
|
616
|
+
detectCyclicObject(value, depth);
|
|
617
|
+
const isObject = typeof value === "object";
|
|
618
|
+
const isFunction = typeof value === "function";
|
|
619
|
+
if (typeof value === "string") {
|
|
620
|
+
return cloneString(value);
|
|
621
|
+
}
|
|
622
|
+
if (typeof value === "number") {
|
|
623
|
+
return cloneNumber(value);
|
|
624
|
+
}
|
|
625
|
+
if (typeof value === "boolean") {
|
|
626
|
+
return cloneBoolean(value);
|
|
627
|
+
}
|
|
628
|
+
if (typeof value === "bigint") {
|
|
629
|
+
return cloneBigInt(value);
|
|
630
|
+
}
|
|
631
|
+
if (value === void 0) {
|
|
632
|
+
return cloneUndefined();
|
|
633
|
+
}
|
|
634
|
+
if (value === null) {
|
|
635
|
+
return cloneNull();
|
|
636
|
+
}
|
|
637
|
+
if (!isObject && !isFunction || value === null) {
|
|
638
|
+
return clonePrimitive(value, shouldPersistRemote);
|
|
639
|
+
}
|
|
640
|
+
const cached = getFromCache(value);
|
|
641
|
+
if (cached !== void 0) {
|
|
642
|
+
return cached;
|
|
643
|
+
}
|
|
644
|
+
if (Array.isArray(value)) {
|
|
645
|
+
return cloneArray(value, shouldPersistRemote, depth);
|
|
646
|
+
}
|
|
647
|
+
if (globalThis._WORKLETS_BUNDLE_MODE && isFunction && value.__bundleData) {
|
|
648
|
+
return cloneImport(value);
|
|
649
|
+
}
|
|
650
|
+
if (isFunction && !isWorkletFunction(value)) {
|
|
651
|
+
return cloneRemoteFunction(value);
|
|
652
|
+
}
|
|
653
|
+
if (isTurboModuleLike(value)) {
|
|
654
|
+
return cloneTurboModuleLike(value, shouldPersistRemote, depth);
|
|
655
|
+
}
|
|
656
|
+
if (isHostObject(value)) {
|
|
657
|
+
return cloneHostObject(value);
|
|
658
|
+
}
|
|
659
|
+
if (isPlainJSObject(value) && value.__init) {
|
|
660
|
+
return cloneInitializer(value, shouldPersistRemote, depth);
|
|
661
|
+
}
|
|
662
|
+
if (isPlainJSObject(value) && value.__workletContextObjectFactory) {
|
|
663
|
+
return cloneContextObject(value);
|
|
664
|
+
}
|
|
665
|
+
if ((isPlainJSObject(value) || isFunction) && isWorkletFunction(value)) {
|
|
666
|
+
return cloneWorklet(value, shouldPersistRemote, depth);
|
|
667
|
+
}
|
|
668
|
+
if (isSynchronizable(value)) {
|
|
669
|
+
return cloneSynchronizable(value);
|
|
670
|
+
}
|
|
671
|
+
if (isPlainJSObject(value) || isFunction) {
|
|
672
|
+
return clonePlainJSObject(value, shouldPersistRemote, depth);
|
|
673
|
+
}
|
|
674
|
+
if (value instanceof Set) {
|
|
675
|
+
return cloneSet(value);
|
|
676
|
+
}
|
|
677
|
+
if (value instanceof Map) {
|
|
678
|
+
return cloneMap(value);
|
|
679
|
+
}
|
|
680
|
+
if (value instanceof RegExp) {
|
|
681
|
+
return cloneRegExp(value);
|
|
682
|
+
}
|
|
683
|
+
if (value instanceof Error) {
|
|
684
|
+
return cloneError(value);
|
|
685
|
+
}
|
|
686
|
+
if (value instanceof ArrayBuffer) {
|
|
687
|
+
return cloneArrayBuffer(value, shouldPersistRemote);
|
|
688
|
+
}
|
|
689
|
+
if (ArrayBuffer.isView(value)) {
|
|
690
|
+
return cloneArrayBufferView(value);
|
|
691
|
+
}
|
|
692
|
+
return inaccessibleObject(value);
|
|
693
|
+
}
|
|
694
|
+
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
695
|
+
createSerializableNative.__bundleData = {
|
|
696
|
+
imported: "createSerializable",
|
|
697
|
+
// @ts-expect-error resolveWeak is defined by Metro
|
|
698
|
+
source: __require.resolveWeak("./index")
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
var createSerializable = SHOULD_BE_USE_WEB2 ? createSerializableWeb : createSerializableNative;
|
|
702
|
+
function detectCyclicObject(value, depth) {
|
|
703
|
+
if (depth >= DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {
|
|
704
|
+
if (depth === DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {
|
|
705
|
+
processedObjectAtThresholdDepth = value;
|
|
706
|
+
} else if (value === processedObjectAtThresholdDepth) {
|
|
707
|
+
throw new WorkletsError("Trying to convert a cyclic object to a serializable. This is not supported.");
|
|
708
|
+
}
|
|
709
|
+
} else {
|
|
710
|
+
processedObjectAtThresholdDepth = void 0;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
function clonePrimitive(value, shouldPersistRemote) {
|
|
714
|
+
return WorkletsModule.createSerializable(value, shouldPersistRemote);
|
|
715
|
+
}
|
|
716
|
+
function cloneString(value) {
|
|
717
|
+
return WorkletsModule.createSerializableString(value);
|
|
718
|
+
}
|
|
719
|
+
function cloneNumber(value) {
|
|
720
|
+
return WorkletsModule.createSerializableNumber(value);
|
|
721
|
+
}
|
|
722
|
+
function cloneBoolean(value) {
|
|
723
|
+
return WorkletsModule.createSerializableBoolean(value);
|
|
724
|
+
}
|
|
725
|
+
function cloneBigInt(value) {
|
|
726
|
+
return WorkletsModule.createSerializableBigInt(value);
|
|
727
|
+
}
|
|
728
|
+
function cloneUndefined() {
|
|
729
|
+
return WorkletsModule.createSerializableUndefined();
|
|
730
|
+
}
|
|
731
|
+
function cloneNull() {
|
|
732
|
+
return WorkletsModule.createSerializableNull();
|
|
733
|
+
}
|
|
734
|
+
function cloneObjectProperties(value, shouldPersistRemote, depth) {
|
|
735
|
+
const clonedProps = {};
|
|
736
|
+
for (const [key, element] of Object.entries(value)) {
|
|
737
|
+
if (key === "__initData" && clonedProps.__initData !== void 0) {
|
|
738
|
+
continue;
|
|
739
|
+
}
|
|
740
|
+
clonedProps[key] = createSerializable(element, shouldPersistRemote, depth + 1);
|
|
741
|
+
}
|
|
742
|
+
return clonedProps;
|
|
743
|
+
}
|
|
744
|
+
function cloneInitializer(value, shouldPersistRemote = false, depth = 0) {
|
|
745
|
+
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
|
|
746
|
+
return WorkletsModule.createSerializableInitializer(clonedProps);
|
|
747
|
+
}
|
|
748
|
+
function cloneArray(value, shouldPersistRemote, depth) {
|
|
749
|
+
const clonedElements = value.map((element) => createSerializable(element, shouldPersistRemote, depth + 1));
|
|
750
|
+
const clone = WorkletsModule.createSerializableArray(clonedElements, shouldPersistRemote);
|
|
751
|
+
serializableMappingCache.set(value, clone);
|
|
752
|
+
serializableMappingCache.set(clone);
|
|
753
|
+
freezeObjectInDev(value);
|
|
754
|
+
return clone;
|
|
755
|
+
}
|
|
756
|
+
function cloneRemoteFunction(value) {
|
|
757
|
+
const clone = WorkletsModule.createSerializableFunction(value);
|
|
758
|
+
serializableMappingCache.set(value, clone);
|
|
759
|
+
serializableMappingCache.set(clone);
|
|
760
|
+
freezeObjectInDev(value);
|
|
761
|
+
return clone;
|
|
762
|
+
}
|
|
763
|
+
function cloneHostObject(value) {
|
|
764
|
+
const clone = WorkletsModule.createSerializableHostObject(value);
|
|
765
|
+
serializableMappingCache.set(value, clone);
|
|
766
|
+
serializableMappingCache.set(clone);
|
|
767
|
+
return clone;
|
|
768
|
+
}
|
|
769
|
+
function cloneWorklet(value, shouldPersistRemote, depth) {
|
|
770
|
+
if (__DEV__) {
|
|
771
|
+
const babelVersion = value.__pluginVersion;
|
|
772
|
+
if (babelVersion !== void 0 && babelVersion !== jsVersion) {
|
|
773
|
+
throw new WorkletsError(`Mismatch between JavaScript code version and Worklets Babel plugin version (${jsVersion} vs. ${babelVersion}).
|
|
774
|
+
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-code-version-and-worklets-babel-plugin-version\` for more details.
|
|
775
|
+
Offending code was: \`${getWorkletCode(value)}\``);
|
|
776
|
+
}
|
|
777
|
+
registerWorkletStackDetails(value.__workletHash, value.__stackDetails);
|
|
778
|
+
}
|
|
779
|
+
if (value.__stackDetails) {
|
|
780
|
+
delete value.__stackDetails;
|
|
781
|
+
}
|
|
782
|
+
const clonedProps = cloneObjectProperties(value, true, depth);
|
|
783
|
+
clonedProps.__initData = createSerializable(value.__initData, true, depth + 1);
|
|
784
|
+
const clone = WorkletsModule.createSerializableWorklet(
|
|
785
|
+
clonedProps,
|
|
786
|
+
// TODO: Check after refactor if we can remove shouldPersistRemote parameter (imho it's redundant here since worklets are always persistent)
|
|
787
|
+
// retain all worklets
|
|
788
|
+
true
|
|
789
|
+
);
|
|
790
|
+
serializableMappingCache.set(value, clone);
|
|
791
|
+
serializableMappingCache.set(clone);
|
|
792
|
+
freezeObjectInDev(value);
|
|
793
|
+
return clone;
|
|
794
|
+
}
|
|
795
|
+
function cloneTurboModuleLike(value, shouldPersistRemote, depth) {
|
|
796
|
+
const proto = Object.getPrototypeOf(value);
|
|
797
|
+
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
|
|
798
|
+
const clone = WorkletsModule.createSerializableTurboModuleLike(clonedProps, proto);
|
|
799
|
+
return clone;
|
|
800
|
+
}
|
|
801
|
+
function cloneContextObject(value) {
|
|
802
|
+
const workletContextObjectFactory = value.__workletContextObjectFactory;
|
|
803
|
+
const handle = cloneInitializer({
|
|
804
|
+
__init: () => {
|
|
805
|
+
"worklet";
|
|
806
|
+
return workletContextObjectFactory();
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
serializableMappingCache.set(value, handle);
|
|
810
|
+
return handle;
|
|
811
|
+
}
|
|
812
|
+
function clonePlainJSObject(value, shouldPersistRemote, depth) {
|
|
813
|
+
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
|
|
814
|
+
const clone = WorkletsModule.createSerializableObject(clonedProps, shouldPersistRemote, value);
|
|
815
|
+
serializableMappingCache.set(value, clone);
|
|
816
|
+
serializableMappingCache.set(clone);
|
|
817
|
+
freezeObjectInDev(value);
|
|
818
|
+
return clone;
|
|
819
|
+
}
|
|
820
|
+
function cloneMap(value) {
|
|
821
|
+
const clonedKeys = [];
|
|
822
|
+
const clonedValues = [];
|
|
823
|
+
for (const [key, element] of value.entries()) {
|
|
824
|
+
clonedKeys.push(createSerializable(key));
|
|
825
|
+
clonedValues.push(createSerializable(element));
|
|
826
|
+
}
|
|
827
|
+
const clone = WorkletsModule.createSerializableMap(clonedKeys, clonedValues);
|
|
828
|
+
serializableMappingCache.set(value, clone);
|
|
829
|
+
serializableMappingCache.set(clone);
|
|
830
|
+
freezeObjectInDev(value);
|
|
831
|
+
return clone;
|
|
832
|
+
}
|
|
833
|
+
function cloneSet(value) {
|
|
834
|
+
const clonedElements = [];
|
|
835
|
+
for (const element of value) {
|
|
836
|
+
clonedElements.push(createSerializable(element));
|
|
837
|
+
}
|
|
838
|
+
const clone = WorkletsModule.createSerializableSet(clonedElements);
|
|
839
|
+
serializableMappingCache.set(value, clone);
|
|
840
|
+
serializableMappingCache.set(clone);
|
|
841
|
+
freezeObjectInDev(value);
|
|
842
|
+
return clone;
|
|
843
|
+
}
|
|
844
|
+
function cloneRegExp(value) {
|
|
845
|
+
const pattern = value.source;
|
|
846
|
+
const flags = value.flags;
|
|
847
|
+
const handle = cloneInitializer({
|
|
848
|
+
__init: () => {
|
|
849
|
+
"worklet";
|
|
850
|
+
return new RegExp(pattern, flags);
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
serializableMappingCache.set(value, handle);
|
|
854
|
+
return handle;
|
|
855
|
+
}
|
|
856
|
+
function cloneError(value) {
|
|
857
|
+
const {
|
|
858
|
+
name,
|
|
859
|
+
message,
|
|
860
|
+
stack
|
|
861
|
+
} = value;
|
|
862
|
+
const handle = cloneInitializer({
|
|
863
|
+
__init: () => {
|
|
864
|
+
"worklet";
|
|
865
|
+
const error = new Error();
|
|
866
|
+
error.name = name;
|
|
867
|
+
error.message = message;
|
|
868
|
+
error.stack = stack;
|
|
869
|
+
return error;
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
serializableMappingCache.set(value, handle);
|
|
873
|
+
return handle;
|
|
874
|
+
}
|
|
875
|
+
function cloneArrayBuffer(value, shouldPersistRemote) {
|
|
876
|
+
const clone = WorkletsModule.createSerializable(value, shouldPersistRemote, value);
|
|
877
|
+
serializableMappingCache.set(value, clone);
|
|
878
|
+
serializableMappingCache.set(clone);
|
|
879
|
+
return clone;
|
|
880
|
+
}
|
|
881
|
+
function cloneArrayBufferView(value) {
|
|
882
|
+
const buffer = value.buffer;
|
|
883
|
+
const typeName = value.constructor.name;
|
|
884
|
+
const handle = cloneInitializer({
|
|
885
|
+
__init: () => {
|
|
886
|
+
"worklet";
|
|
887
|
+
if (!VALID_ARRAY_VIEWS_NAMES.includes(typeName)) {
|
|
888
|
+
throw new WorkletsError(`Invalid array view name \`${typeName}\`.`);
|
|
889
|
+
}
|
|
890
|
+
const constructor = global[typeName];
|
|
891
|
+
if (constructor === void 0) {
|
|
892
|
+
throw new WorkletsError(`Constructor for \`${typeName}\` not found.`);
|
|
893
|
+
}
|
|
894
|
+
return new constructor(buffer);
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
serializableMappingCache.set(value, handle);
|
|
898
|
+
return handle;
|
|
899
|
+
}
|
|
900
|
+
function cloneSynchronizable(value) {
|
|
901
|
+
serializableMappingCache.set(value);
|
|
902
|
+
return value;
|
|
903
|
+
}
|
|
904
|
+
function cloneImport(value) {
|
|
905
|
+
const {
|
|
906
|
+
source,
|
|
907
|
+
imported
|
|
908
|
+
} = value.__bundleData;
|
|
909
|
+
const clone = WorkletsModule.createSerializableImport(source, imported);
|
|
910
|
+
serializableMappingCache.set(value, clone);
|
|
911
|
+
serializableMappingCache.set(clone);
|
|
912
|
+
return clone;
|
|
913
|
+
}
|
|
914
|
+
function inaccessibleObject(value) {
|
|
915
|
+
const clone = createSerializable(INACCESSIBLE_OBJECT);
|
|
916
|
+
serializableMappingCache.set(value, clone);
|
|
917
|
+
return clone;
|
|
918
|
+
}
|
|
919
|
+
var WORKLET_CODE_THRESHOLD = 255;
|
|
920
|
+
function getWorkletCode(value) {
|
|
921
|
+
const code = value?.__initData?.code;
|
|
922
|
+
if (!code) {
|
|
923
|
+
return "unknown";
|
|
924
|
+
}
|
|
925
|
+
if (code.length > WORKLET_CODE_THRESHOLD) {
|
|
926
|
+
return `${code.substring(0, WORKLET_CODE_THRESHOLD)}...`;
|
|
927
|
+
}
|
|
928
|
+
return code;
|
|
929
|
+
}
|
|
930
|
+
function isRemoteFunction(value) {
|
|
931
|
+
"worklet";
|
|
932
|
+
return !!value.__remoteFunction;
|
|
933
|
+
}
|
|
934
|
+
function freezeObjectInDev(value) {
|
|
935
|
+
if (!__DEV__) {
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
Object.entries(value).forEach(([key, element]) => {
|
|
939
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
940
|
+
if (!descriptor.configurable) {
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
Object.defineProperty(value, key, {
|
|
944
|
+
get() {
|
|
945
|
+
return element;
|
|
946
|
+
},
|
|
947
|
+
set() {
|
|
948
|
+
logger.warn(`Tried to modify key \`${key}\` of an object which has been already passed to a worklet. See
|
|
949
|
+
https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-modify-key-of-an-object-which-has-been-converted-to-a-serializable
|
|
950
|
+
for more details.`);
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
});
|
|
954
|
+
Object.preventExtensions(value);
|
|
955
|
+
}
|
|
956
|
+
function makeShareableCloneOnUIRecursiveLEGACY(value) {
|
|
957
|
+
"worklet";
|
|
958
|
+
if (SHOULD_BE_USE_WEB2) {
|
|
959
|
+
return value;
|
|
960
|
+
}
|
|
961
|
+
function cloneRecursive(value2) {
|
|
962
|
+
if (typeof value2 === "object" && value2 !== null || typeof value2 === "function") {
|
|
963
|
+
if (isHostObject(value2)) {
|
|
964
|
+
return global._createSerializableHostObject(value2);
|
|
965
|
+
}
|
|
966
|
+
if (isRemoteFunction(value2)) {
|
|
967
|
+
return value2.__remoteFunction;
|
|
968
|
+
}
|
|
969
|
+
if (Array.isArray(value2)) {
|
|
970
|
+
return global._createSerializableArray(value2.map(cloneRecursive));
|
|
971
|
+
}
|
|
972
|
+
if (value2.__synchronizableRef) {
|
|
973
|
+
return global._createSerializableSynchronizable(value2);
|
|
974
|
+
}
|
|
975
|
+
const toAdapt = {};
|
|
976
|
+
for (const [key, element] of Object.entries(value2)) {
|
|
977
|
+
toAdapt[key] = cloneRecursive(element);
|
|
978
|
+
}
|
|
979
|
+
return global._createSerializable(toAdapt, value2);
|
|
980
|
+
}
|
|
981
|
+
if (typeof value2 === "string") {
|
|
982
|
+
return global._createSerializableString(value2);
|
|
983
|
+
}
|
|
984
|
+
if (typeof value2 === "number") {
|
|
985
|
+
return global._createSerializableNumber(value2);
|
|
986
|
+
}
|
|
987
|
+
if (typeof value2 === "boolean") {
|
|
988
|
+
return global._createSerializableBoolean(value2);
|
|
989
|
+
}
|
|
990
|
+
if (typeof value2 === "bigint") {
|
|
991
|
+
return global._createSerializableBigInt(value2);
|
|
992
|
+
}
|
|
993
|
+
if (value2 === void 0) {
|
|
994
|
+
return global._createSerializableUndefined();
|
|
995
|
+
}
|
|
996
|
+
if (value2 === null) {
|
|
997
|
+
return global._createSerializableNull();
|
|
998
|
+
}
|
|
999
|
+
return global._createSerializable(value2, void 0);
|
|
1000
|
+
}
|
|
1001
|
+
return cloneRecursive(value);
|
|
1002
|
+
}
|
|
1003
|
+
var makeShareableCloneOnUIRecursive = globalThis._WORKLETS_BUNDLE_MODE ? createSerializable : makeShareableCloneOnUIRecursiveLEGACY;
|
|
1004
|
+
|
|
1005
|
+
// ../../node_modules/react-native-worklets/lib/module/threads.js
|
|
1006
|
+
var runOnUIQueue = [];
|
|
1007
|
+
function setupMicrotasks() {
|
|
1008
|
+
"worklet";
|
|
1009
|
+
let microtasksQueue = [];
|
|
1010
|
+
let isExecutingMicrotasksQueue = false;
|
|
1011
|
+
global.queueMicrotask = (callback) => {
|
|
1012
|
+
microtasksQueue.push(callback);
|
|
1013
|
+
};
|
|
1014
|
+
global._microtaskQueueFinalizers = [];
|
|
1015
|
+
global.__callMicrotasks = () => {
|
|
1016
|
+
if (isExecutingMicrotasksQueue) {
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
try {
|
|
1020
|
+
isExecutingMicrotasksQueue = true;
|
|
1021
|
+
for (let index = 0; index < microtasksQueue.length; index += 1) {
|
|
1022
|
+
microtasksQueue[index]();
|
|
1023
|
+
}
|
|
1024
|
+
microtasksQueue = [];
|
|
1025
|
+
global._microtaskQueueFinalizers.forEach((finalizer) => finalizer());
|
|
1026
|
+
} finally {
|
|
1027
|
+
isExecutingMicrotasksQueue = false;
|
|
1028
|
+
}
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
function callMicrotasksOnUIThread() {
|
|
1032
|
+
"worklet";
|
|
1033
|
+
global.__callMicrotasks();
|
|
1034
|
+
}
|
|
1035
|
+
var callMicrotasks = SHOULD_BE_USE_WEB2 ? () => {
|
|
1036
|
+
} : callMicrotasksOnUIThread;
|
|
1037
|
+
function runOnUI(worklet) {
|
|
1038
|
+
if (__DEV__ && !SHOULD_BE_USE_WEB2 && !isWorkletFunction(worklet) && !worklet.__bundleData) {
|
|
1039
|
+
throw new WorkletsError("`runOnUI` can only be used with worklets.");
|
|
1040
|
+
}
|
|
1041
|
+
return (...args) => {
|
|
1042
|
+
if (IS_JEST2) {
|
|
1043
|
+
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
|
1044
|
+
"worklet";
|
|
1045
|
+
worklet(...args);
|
|
1046
|
+
}));
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
if (__DEV__) {
|
|
1050
|
+
createSerializable(worklet);
|
|
1051
|
+
createSerializable(args);
|
|
1052
|
+
}
|
|
1053
|
+
enqueueUI(worklet, args);
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
if (__DEV__) {
|
|
1057
|
+
let runOnUIWorklet = function() {
|
|
1058
|
+
"worklet";
|
|
1059
|
+
throw new WorkletsError("`runOnUI` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.");
|
|
1060
|
+
};
|
|
1061
|
+
const serializableRunOnUIWorklet = createSerializable(runOnUIWorklet);
|
|
1062
|
+
serializableMappingCache.set(runOnUI, serializableRunOnUIWorklet);
|
|
1063
|
+
}
|
|
1064
|
+
function executeOnUIRuntimeSync(worklet) {
|
|
1065
|
+
return (...args) => {
|
|
1066
|
+
return WorkletsModule.executeOnUIRuntimeSync(createSerializable(() => {
|
|
1067
|
+
"worklet";
|
|
1068
|
+
const result = worklet(...args);
|
|
1069
|
+
return makeShareableCloneOnUIRecursive(result);
|
|
1070
|
+
}));
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
function runWorkletOnJS(worklet, ...args) {
|
|
1074
|
+
worklet(...args);
|
|
1075
|
+
}
|
|
1076
|
+
function runOnJS(fun) {
|
|
1077
|
+
"worklet";
|
|
1078
|
+
if (SHOULD_BE_USE_WEB2 || globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
|
1079
|
+
return (...args) => queueMicrotask(args.length ? () => fun(...args) : fun);
|
|
1080
|
+
}
|
|
1081
|
+
if (isWorkletFunction(fun)) {
|
|
1082
|
+
return (...args) => runOnJS(runWorkletOnJS)(fun, ...args);
|
|
1083
|
+
}
|
|
1084
|
+
if (fun.__remoteFunction) {
|
|
1085
|
+
fun = fun.__remoteFunction;
|
|
1086
|
+
}
|
|
1087
|
+
const scheduleOnJS = typeof fun === "function" ? global._scheduleHostFunctionOnJS : global._scheduleRemoteFunctionOnJS;
|
|
1088
|
+
return (...args) => {
|
|
1089
|
+
scheduleOnJS(fun, args.length > 0 ? makeShareableCloneOnUIRecursive(args) : void 0);
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
function runOnUIAsync(worklet) {
|
|
1093
|
+
if (__DEV__ && !SHOULD_BE_USE_WEB2 && !isWorkletFunction(worklet)) {
|
|
1094
|
+
throw new WorkletsError("`runOnUIAsync` can only be used with worklets.");
|
|
1095
|
+
}
|
|
1096
|
+
return (...args) => {
|
|
1097
|
+
return new Promise((resolve) => {
|
|
1098
|
+
if (IS_JEST2) {
|
|
1099
|
+
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
|
1100
|
+
"worklet";
|
|
1101
|
+
worklet(...args);
|
|
1102
|
+
}));
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
if (__DEV__) {
|
|
1106
|
+
createSerializable(worklet);
|
|
1107
|
+
createSerializable(args);
|
|
1108
|
+
}
|
|
1109
|
+
enqueueUI(worklet, args, resolve);
|
|
1110
|
+
});
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
1113
|
+
if (__DEV__) {
|
|
1114
|
+
let runOnUIAsyncWorklet = function() {
|
|
1115
|
+
"worklet";
|
|
1116
|
+
throw new WorkletsError("`runOnUIAsync` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.");
|
|
1117
|
+
};
|
|
1118
|
+
const serializableRunOnUIAsyncWorklet = createSerializable(runOnUIAsyncWorklet);
|
|
1119
|
+
serializableMappingCache.set(runOnUIAsync, serializableRunOnUIAsyncWorklet);
|
|
22
1120
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1121
|
+
function enqueueUI(worklet, args, resolve) {
|
|
1122
|
+
const job = [worklet, args, resolve];
|
|
1123
|
+
runOnUIQueue.push(job);
|
|
1124
|
+
if (runOnUIQueue.length === 1) {
|
|
1125
|
+
flushUIQueue();
|
|
1126
|
+
}
|
|
27
1127
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
1128
|
+
function flushUIQueue() {
|
|
1129
|
+
queueMicrotask(() => {
|
|
1130
|
+
const queue = runOnUIQueue;
|
|
1131
|
+
runOnUIQueue = [];
|
|
1132
|
+
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
|
1133
|
+
"worklet";
|
|
1134
|
+
queue.forEach(([workletFunction, workletArgs, jobResolve]) => {
|
|
1135
|
+
const result = workletFunction(...workletArgs);
|
|
1136
|
+
if (jobResolve) {
|
|
1137
|
+
runOnJS(jobResolve)(result);
|
|
1138
|
+
}
|
|
1139
|
+
});
|
|
1140
|
+
callMicrotasks();
|
|
1141
|
+
}));
|
|
1142
|
+
});
|
|
30
1143
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1144
|
+
|
|
1145
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/requestAnimationFrame.js
|
|
1146
|
+
function setupRequestAnimationFrame() {
|
|
1147
|
+
"worklet";
|
|
1148
|
+
const nativeRequestAnimationFrame = globalThis.requestAnimationFrame;
|
|
1149
|
+
let queuedCallbacks = [];
|
|
1150
|
+
let queuedCallbacksBegin = 0;
|
|
1151
|
+
let queuedCallbacksEnd = 0;
|
|
1152
|
+
let flushedCallbacks = queuedCallbacks;
|
|
1153
|
+
let flushedCallbacksBegin = 0;
|
|
1154
|
+
let flushedCallbacksEnd = 0;
|
|
1155
|
+
let flushRequested = false;
|
|
1156
|
+
globalThis.__flushAnimationFrame = (timestamp) => {
|
|
1157
|
+
flushedCallbacks = queuedCallbacks;
|
|
1158
|
+
queuedCallbacks = [];
|
|
1159
|
+
flushedCallbacksBegin = queuedCallbacksBegin;
|
|
1160
|
+
flushedCallbacksEnd = queuedCallbacksEnd;
|
|
1161
|
+
queuedCallbacksBegin = queuedCallbacksEnd;
|
|
1162
|
+
for (const callback of flushedCallbacks) {
|
|
1163
|
+
callback(timestamp);
|
|
1164
|
+
}
|
|
1165
|
+
flushedCallbacksBegin = flushedCallbacksEnd;
|
|
1166
|
+
callMicrotasks();
|
|
1167
|
+
};
|
|
1168
|
+
globalThis.requestAnimationFrame = (callback) => {
|
|
1169
|
+
const handle = queuedCallbacksEnd++;
|
|
1170
|
+
queuedCallbacks.push(callback);
|
|
1171
|
+
if (!flushRequested) {
|
|
1172
|
+
flushRequested = true;
|
|
1173
|
+
nativeRequestAnimationFrame((timestamp) => {
|
|
1174
|
+
flushRequested = false;
|
|
1175
|
+
globalThis.__frameTimestamp = timestamp;
|
|
1176
|
+
globalThis.__flushAnimationFrame(timestamp);
|
|
1177
|
+
globalThis.__frameTimestamp = void 0;
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
return handle;
|
|
1181
|
+
};
|
|
1182
|
+
globalThis.cancelAnimationFrame = (handle) => {
|
|
1183
|
+
if (handle < flushedCallbacksBegin || handle >= queuedCallbacksEnd) {
|
|
1184
|
+
return;
|
|
1185
|
+
}
|
|
1186
|
+
if (handle < flushedCallbacksEnd) {
|
|
1187
|
+
flushedCallbacks[handle - flushedCallbacksBegin] = () => {
|
|
1188
|
+
};
|
|
1189
|
+
} else {
|
|
1190
|
+
queuedCallbacks[handle - queuedCallbacksBegin] = () => {
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
40
1194
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
1195
|
+
|
|
1196
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js
|
|
1197
|
+
function setupSetTimeout() {
|
|
1198
|
+
"worklet";
|
|
1199
|
+
const timeoutHandleToRafHandle = /* @__PURE__ */ new Map();
|
|
1200
|
+
const setTimeoutPolyfill = (callback, delay = 0, ...args) => {
|
|
1201
|
+
const start = performance.now();
|
|
1202
|
+
let timeoutHandle = 0;
|
|
1203
|
+
const rafCallback = () => {
|
|
1204
|
+
const now = performance.now();
|
|
1205
|
+
if (now - start >= delay) {
|
|
1206
|
+
callback(...args);
|
|
1207
|
+
timeoutHandleToRafHandle.delete(timeoutHandle);
|
|
1208
|
+
} else {
|
|
1209
|
+
const rafHandle = requestAnimationFrame(rafCallback);
|
|
1210
|
+
timeoutHandleToRafHandle.set(timeoutHandle, rafHandle);
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
timeoutHandle = requestAnimationFrame(rafCallback);
|
|
1214
|
+
timeoutHandleToRafHandle.set(timeoutHandle, timeoutHandle);
|
|
1215
|
+
return timeoutHandle;
|
|
1216
|
+
};
|
|
1217
|
+
const clearTimeoutPolyfill = (timeoutHandle) => {
|
|
1218
|
+
const rafHandle = timeoutHandleToRafHandle.get(timeoutHandle);
|
|
1219
|
+
timeoutHandleToRafHandle.delete(timeoutHandle);
|
|
1220
|
+
cancelAnimationFrame(rafHandle);
|
|
1221
|
+
};
|
|
1222
|
+
globalThis.setTimeout = setTimeoutPolyfill;
|
|
1223
|
+
globalThis.clearTimeout = clearTimeoutPolyfill;
|
|
45
1224
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
1225
|
+
|
|
1226
|
+
// ../../node_modules/react-native-worklets/lib/module/synchronizableUnpacker.js
|
|
1227
|
+
function __installUnpacker() {
|
|
1228
|
+
const serializer = !globalThis._WORKLET || globalThis._WORKLETS_BUNDLE_MODE ? (value, _) => createSerializable(value) : globalThis._createSerializable;
|
|
1229
|
+
function synchronizableUnpacker(synchronizableRef) {
|
|
1230
|
+
const synchronizable = synchronizableRef;
|
|
1231
|
+
const proxy = globalThis.__workletsModuleProxy;
|
|
1232
|
+
synchronizable.__synchronizableRef = true;
|
|
1233
|
+
synchronizable.getDirty = () => {
|
|
1234
|
+
return proxy.synchronizableGetDirty(synchronizable);
|
|
1235
|
+
};
|
|
1236
|
+
synchronizable.getBlocking = () => {
|
|
1237
|
+
return proxy.synchronizableGetBlocking(synchronizable);
|
|
1238
|
+
};
|
|
1239
|
+
synchronizable.setBlocking = (valueOrFunction) => {
|
|
1240
|
+
let newValue;
|
|
1241
|
+
if (typeof valueOrFunction === "function") {
|
|
1242
|
+
const func = valueOrFunction;
|
|
1243
|
+
synchronizable.lock();
|
|
1244
|
+
const prev = synchronizable.getBlocking();
|
|
1245
|
+
newValue = func(prev);
|
|
1246
|
+
proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, void 0));
|
|
1247
|
+
synchronizable.unlock();
|
|
1248
|
+
} else {
|
|
1249
|
+
const value = valueOrFunction;
|
|
1250
|
+
newValue = value;
|
|
1251
|
+
proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, void 0));
|
|
1252
|
+
}
|
|
1253
|
+
};
|
|
1254
|
+
synchronizable.lock = () => {
|
|
1255
|
+
proxy.synchronizableLock(synchronizable);
|
|
1256
|
+
};
|
|
1257
|
+
synchronizable.unlock = () => {
|
|
1258
|
+
proxy.synchronizableUnlock(synchronizable);
|
|
1259
|
+
};
|
|
1260
|
+
return synchronizable;
|
|
1261
|
+
}
|
|
1262
|
+
globalThis.__synchronizableUnpacker = synchronizableUnpacker;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
// ../../node_modules/react-native-worklets/lib/module/initializers.js
|
|
1266
|
+
var capturableConsole;
|
|
1267
|
+
function getMemorySafeCapturableConsole() {
|
|
1268
|
+
if (capturableConsole) {
|
|
1269
|
+
return capturableConsole;
|
|
1270
|
+
}
|
|
1271
|
+
const consoleCopy = Object.fromEntries(Object.entries(console).map(([methodName, method]) => {
|
|
1272
|
+
const methodWrapper = function methodWrapper2(...args) {
|
|
1273
|
+
return method(...args);
|
|
1274
|
+
};
|
|
1275
|
+
if (method.name) {
|
|
1276
|
+
Object.defineProperty(methodWrapper, "name", {
|
|
1277
|
+
value: method.name,
|
|
1278
|
+
writable: false
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
return [methodName, methodWrapper];
|
|
1282
|
+
}));
|
|
1283
|
+
capturableConsole = consoleCopy;
|
|
1284
|
+
return consoleCopy;
|
|
1285
|
+
}
|
|
1286
|
+
function setupConsole(boundCapturableConsole) {
|
|
1287
|
+
"worklet";
|
|
1288
|
+
globalThis.console = {
|
|
1289
|
+
assert: runOnJS(boundCapturableConsole.assert),
|
|
1290
|
+
debug: runOnJS(boundCapturableConsole.debug),
|
|
1291
|
+
log: runOnJS(boundCapturableConsole.log),
|
|
1292
|
+
warn: runOnJS(boundCapturableConsole.warn),
|
|
1293
|
+
error: runOnJS(boundCapturableConsole.error),
|
|
1294
|
+
info: runOnJS(boundCapturableConsole.info)
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
var initialized = false;
|
|
1298
|
+
function init() {
|
|
1299
|
+
if (initialized) {
|
|
1300
|
+
return;
|
|
1301
|
+
}
|
|
1302
|
+
initialized = true;
|
|
1303
|
+
if (globalThis.__RUNTIME_KIND === void 0) {
|
|
1304
|
+
globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
|
|
1305
|
+
}
|
|
1306
|
+
initializeRuntime();
|
|
1307
|
+
if (SHOULD_BE_USE_WEB2) {
|
|
1308
|
+
initializeRuntimeOnWeb();
|
|
1309
|
+
}
|
|
1310
|
+
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
|
|
1311
|
+
initializeWorkletRuntime();
|
|
1312
|
+
} else {
|
|
1313
|
+
initializeRNRuntime();
|
|
1314
|
+
if (!SHOULD_BE_USE_WEB2) {
|
|
1315
|
+
installRNBindingsOnUIRuntime();
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
function initializeRuntime() {
|
|
1320
|
+
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
1321
|
+
globalThis.__valueUnpacker = bundleValueUnpacker;
|
|
1322
|
+
}
|
|
1323
|
+
__installUnpacker();
|
|
1324
|
+
}
|
|
1325
|
+
function initializeRNRuntime() {
|
|
1326
|
+
if (__DEV__) {
|
|
1327
|
+
const testWorklet = () => {
|
|
1328
|
+
"worklet";
|
|
1329
|
+
};
|
|
1330
|
+
if (!isWorkletFunction(testWorklet)) {
|
|
1331
|
+
throw new WorkletsError(`Failed to create a worklet. See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#failed-to-create-a-worklet for more details.`);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
registerReportFatalRemoteError();
|
|
1335
|
+
}
|
|
1336
|
+
function initializeWorkletRuntime() {
|
|
1337
|
+
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
1338
|
+
setupCallGuard();
|
|
1339
|
+
if (__DEV__) {
|
|
1340
|
+
const Refresh = new Proxy({}, {
|
|
1341
|
+
get() {
|
|
1342
|
+
return () => {
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
});
|
|
1346
|
+
globalThis.__r.Refresh = Refresh;
|
|
1347
|
+
const modules = __require.getModules();
|
|
1348
|
+
const ReactNativeModuleId = __require.resolveWeak("react-native");
|
|
1349
|
+
const factory = function(_global, _require, _importDefault, _importAll, module, _exports, _dependencyMap) {
|
|
1350
|
+
module.exports = new Proxy({}, {
|
|
1351
|
+
get: function get(_target, prop) {
|
|
1352
|
+
globalThis.console.warn(`You tried to import '${String(prop)}' from 'react-native' module on a Worklet Runtime. Using 'react-native' module on a Worklet Runtime is not allowed.`);
|
|
1353
|
+
return {
|
|
1354
|
+
get() {
|
|
1355
|
+
return void 0;
|
|
1356
|
+
}
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1359
|
+
});
|
|
1360
|
+
};
|
|
1361
|
+
const mod = {
|
|
1362
|
+
dependencyMap: [],
|
|
1363
|
+
factory,
|
|
1364
|
+
hasError: false,
|
|
1365
|
+
importedAll: {},
|
|
1366
|
+
importedDefault: {},
|
|
1367
|
+
isInitialized: false,
|
|
1368
|
+
publicModule: {
|
|
1369
|
+
exports: {}
|
|
1370
|
+
}
|
|
1371
|
+
};
|
|
1372
|
+
modules.set(ReactNativeModuleId, mod);
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
function initializeRuntimeOnWeb() {
|
|
1377
|
+
globalThis._WORKLET = false;
|
|
1378
|
+
globalThis._log = console.log;
|
|
1379
|
+
globalThis._getAnimationTimestamp = () => performance.now();
|
|
1380
|
+
if (IS_JEST2) {
|
|
1381
|
+
globalThis.requestAnimationFrame = mockedRequestAnimationFrame;
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
function installRNBindingsOnUIRuntime() {
|
|
1385
|
+
if (!WorkletsModule) {
|
|
1386
|
+
throw new WorkletsError("Worklets are trying to initialize the UI runtime without a valid WorkletsModule");
|
|
1387
|
+
}
|
|
1388
|
+
const runtimeBoundCapturableConsole = getMemorySafeCapturableConsole();
|
|
1389
|
+
if (!globalThis._WORKLETS_BUNDLE_MODE) {
|
|
1390
|
+
executeOnUIRuntimeSync(setupCallGuard)();
|
|
1391
|
+
executeOnUIRuntimeSync(registerWorkletsError)();
|
|
1392
|
+
}
|
|
1393
|
+
executeOnUIRuntimeSync(() => {
|
|
1394
|
+
"worklet";
|
|
1395
|
+
setupConsole(runtimeBoundCapturableConsole);
|
|
1396
|
+
setupMicrotasks();
|
|
1397
|
+
setupRequestAnimationFrame();
|
|
1398
|
+
setupSetTimeout();
|
|
1399
|
+
setupSetImmediate();
|
|
1400
|
+
setupSetInterval();
|
|
1401
|
+
})();
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
// ../../node_modules/react-native-worklets/lib/module/workletRuntimeEntry.js
|
|
1405
|
+
function bundleModeInit() {
|
|
1406
|
+
if (SHOULD_BE_USE_WEB2) {
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
globalThis._WORKLETS_BUNDLE_MODE = true;
|
|
1410
|
+
const runtimeKind = globalThis.__RUNTIME_KIND;
|
|
1411
|
+
if (runtimeKind && runtimeKind !== RuntimeKind.ReactNative) {
|
|
1412
|
+
init();
|
|
1413
|
+
throw new WorkletsError("Worklets initialized successfully");
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
bundleModeInit();
|
|
1417
|
+
|
|
1418
|
+
// ../../node_modules/react-native-worklets/lib/module/featureFlags/index.js
|
|
1419
|
+
var DynamicFlags = {
|
|
1420
|
+
EXAMPLE_DYNAMIC_FLAG: true,
|
|
1421
|
+
init() {
|
|
1422
|
+
Object.keys(DynamicFlags).forEach((key) => {
|
|
1423
|
+
if (key !== "init" && key !== "setFlag") {
|
|
1424
|
+
WorkletsModule.setDynamicFeatureFlag(key, DynamicFlags[key]);
|
|
1425
|
+
}
|
|
1426
|
+
});
|
|
1427
|
+
},
|
|
1428
|
+
setFlag(name, value) {
|
|
1429
|
+
if (name in DynamicFlags) {
|
|
1430
|
+
DynamicFlags[name] = value;
|
|
1431
|
+
WorkletsModule.setDynamicFeatureFlag(name, value);
|
|
1432
|
+
} else {
|
|
1433
|
+
logger.warn(`The feature flag: '${name}' no longer exists, you can safely remove invocation of \`setDynamicFeatureFlag('${name}')\` from your code.`);
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
};
|
|
1437
|
+
DynamicFlags.init();
|
|
1438
|
+
|
|
1439
|
+
// ../../node_modules/react-native-worklets/lib/module/index.js
|
|
1440
|
+
init();
|
|
1441
|
+
if (globalThis._ALWAYS_FALSE) {
|
|
1442
|
+
bundleModeInit();
|
|
49
1443
|
}
|
|
1444
|
+
|
|
1445
|
+
// src/transitions/easing.ts
|
|
50
1446
|
function ensureWorkletEasing(easing) {
|
|
51
1447
|
if (!easing) return void 0;
|
|
52
1448
|
if (isWorkletFunction(easing)) return easing;
|
|
@@ -57,13 +1453,12 @@ function ensureWorkletEasing(easing) {
|
|
|
57
1453
|
return wrapped;
|
|
58
1454
|
}
|
|
59
1455
|
|
|
60
|
-
// src/transitions/
|
|
1456
|
+
// src/transitions/spring.ts
|
|
61
1457
|
var DEFAULT_SPRING = {
|
|
62
1458
|
tension: 170,
|
|
63
1459
|
friction: 26,
|
|
64
1460
|
mass: 1
|
|
65
1461
|
};
|
|
66
|
-
var DEFAULT_TIMING_DURATION = 250;
|
|
67
1462
|
function springToReanimated(t) {
|
|
68
1463
|
return {
|
|
69
1464
|
stiffness: t.tension ?? DEFAULT_SPRING.tension,
|
|
@@ -74,6 +1469,33 @@ function springToReanimated(t) {
|
|
|
74
1469
|
restDisplacementThreshold: t.restDisplacementThreshold
|
|
75
1470
|
};
|
|
76
1471
|
}
|
|
1472
|
+
|
|
1473
|
+
// src/layout/resolveLayout.ts
|
|
1474
|
+
function resolveLayoutTransition(layout) {
|
|
1475
|
+
if (!layout) return void 0;
|
|
1476
|
+
const cfg = layout === true ? { type: "spring" } : layout;
|
|
1477
|
+
if (cfg.type === "no-animation") return void 0;
|
|
1478
|
+
if (cfg.type === "timing") {
|
|
1479
|
+
let builder2 = LinearTransition.duration(cfg.duration ?? 300);
|
|
1480
|
+
const easing = ensureWorkletEasing(cfg.easing);
|
|
1481
|
+
if (easing) builder2 = builder2.easing(easing);
|
|
1482
|
+
if (cfg.delay) builder2 = builder2.delay(cfg.delay);
|
|
1483
|
+
return builder2;
|
|
1484
|
+
}
|
|
1485
|
+
const spring = cfg.type === "decay" ? { type: "spring" } : cfg;
|
|
1486
|
+
const { stiffness, damping, mass } = springToReanimated({
|
|
1487
|
+
...DEFAULT_SPRING,
|
|
1488
|
+
...spring
|
|
1489
|
+
});
|
|
1490
|
+
let builder = LinearTransition.springify().stiffness(stiffness).damping(damping).mass(mass);
|
|
1491
|
+
if ("delay" in spring && spring.delay) builder = builder.delay(spring.delay);
|
|
1492
|
+
return builder;
|
|
1493
|
+
}
|
|
1494
|
+
var PresenceContext = createContext(null);
|
|
1495
|
+
function usePresence() {
|
|
1496
|
+
return useContext(PresenceContext);
|
|
1497
|
+
}
|
|
1498
|
+
var DEFAULT_TIMING_DURATION = 250;
|
|
77
1499
|
function buildSpring(cfg, toValue, cb) {
|
|
78
1500
|
return withSpring(toValue, springToReanimated(cfg), cb);
|
|
79
1501
|
}
|
|
@@ -178,14 +1600,96 @@ function mergeTransition(base, override) {
|
|
|
178
1600
|
}
|
|
179
1601
|
return { ...base ?? { type: "spring" }, ...override };
|
|
180
1602
|
}
|
|
1603
|
+
|
|
1604
|
+
// src/transitions/keys.ts
|
|
1605
|
+
var TRANSITION_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
1606
|
+
"type",
|
|
1607
|
+
"tension",
|
|
1608
|
+
"friction",
|
|
1609
|
+
"mass",
|
|
1610
|
+
"velocity",
|
|
1611
|
+
"restSpeedThreshold",
|
|
1612
|
+
"restDisplacementThreshold",
|
|
1613
|
+
"duration",
|
|
1614
|
+
"easing",
|
|
1615
|
+
"delay",
|
|
1616
|
+
"repeat",
|
|
1617
|
+
"deceleration",
|
|
1618
|
+
"clamp"
|
|
1619
|
+
]);
|
|
1620
|
+
function isTopLevelTransition(t) {
|
|
1621
|
+
if (t === null || typeof t !== "object") return false;
|
|
1622
|
+
const keys = Object.keys(t);
|
|
1623
|
+
if (keys.length === 0) return false;
|
|
1624
|
+
return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
// src/transitions/sig.ts
|
|
1628
|
+
function stableSig(value) {
|
|
1629
|
+
if (value === void 0) return "";
|
|
1630
|
+
try {
|
|
1631
|
+
return stableStringify(value);
|
|
1632
|
+
} catch {
|
|
1633
|
+
return String(value);
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
function stableStringify(v) {
|
|
1637
|
+
if (v === null || typeof v !== "object") {
|
|
1638
|
+
if (typeof v === "function" || v === void 0) return "null";
|
|
1639
|
+
return JSON.stringify(v);
|
|
1640
|
+
}
|
|
1641
|
+
if (Array.isArray(v)) {
|
|
1642
|
+
return "[" + v.map(stableStringify).join(",") + "]";
|
|
1643
|
+
}
|
|
1644
|
+
const obj = v;
|
|
1645
|
+
const keys = Object.keys(obj).sort();
|
|
1646
|
+
return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
// src/motion/installCheck.ts
|
|
1650
|
+
var alreadyChecked = false;
|
|
1651
|
+
function ensureReanimatedInstalled() {
|
|
1652
|
+
if (!__DEV__ || alreadyChecked) return;
|
|
1653
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV === "test") {
|
|
1654
|
+
return;
|
|
1655
|
+
}
|
|
1656
|
+
alreadyChecked = true;
|
|
1657
|
+
let version;
|
|
1658
|
+
try {
|
|
1659
|
+
const pkg = __require("react-native-reanimated/package.json");
|
|
1660
|
+
version = pkg.version;
|
|
1661
|
+
} catch {
|
|
1662
|
+
}
|
|
1663
|
+
if (version) {
|
|
1664
|
+
const major = parseInt(version.split(".")[0] ?? "0", 10);
|
|
1665
|
+
if (major < 4) {
|
|
1666
|
+
console.error(
|
|
1667
|
+
`[inertia] react-native-reanimated v${version} is installed, but @onlynative/inertia requires v4.0.0 or later. Upgrade with \`pnpm add react-native-reanimated@^4\` (or your package manager's equivalent).`
|
|
1668
|
+
);
|
|
1669
|
+
return;
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
const probe = function probe2() {
|
|
1673
|
+
"worklet";
|
|
1674
|
+
return 0;
|
|
1675
|
+
};
|
|
1676
|
+
if (typeof probe.__workletHash !== "number") {
|
|
1677
|
+
console.error(
|
|
1678
|
+
`[inertia] The Reanimated worklets babel plugin is not configured. Add \`'react-native-worklets/plugin'\` as the LAST entry in the \`plugins\` array of your \`babel.config.js\`, then restart Metro with a fresh cache: \`npx expo start -c\` or \`npx react-native start --reset-cache\`.`
|
|
1679
|
+
);
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
181
1682
|
var TRANSFORM_KEYS = [
|
|
182
1683
|
"translateX",
|
|
183
1684
|
"translateY",
|
|
184
1685
|
"scale",
|
|
185
1686
|
"scaleX",
|
|
186
1687
|
"scaleY",
|
|
187
|
-
"rotate"
|
|
1688
|
+
"rotate",
|
|
1689
|
+
"rotateX",
|
|
1690
|
+
"rotateY"
|
|
188
1691
|
];
|
|
1692
|
+
var ROTATION_KEYS = /* @__PURE__ */ new Set(["rotate", "rotateX", "rotateY"]);
|
|
189
1693
|
var NUMERIC_TOP_LEVEL_KEYS = [
|
|
190
1694
|
"opacity",
|
|
191
1695
|
"width",
|
|
@@ -204,6 +1708,14 @@ var ALL_KEYS = [
|
|
|
204
1708
|
...COLOR_KEYS
|
|
205
1709
|
];
|
|
206
1710
|
var TRANSFORM_KEY_SET = new Set(TRANSFORM_KEYS);
|
|
1711
|
+
var COLOR_KEY_SET = new Set(COLOR_KEYS);
|
|
1712
|
+
var GESTURE_LAYER_NAMES = [
|
|
1713
|
+
"hovered",
|
|
1714
|
+
"focused",
|
|
1715
|
+
"focusVisible",
|
|
1716
|
+
"pressed"
|
|
1717
|
+
];
|
|
1718
|
+
var GESTURE_LAYER_NAME_SET = new Set(GESTURE_LAYER_NAMES);
|
|
207
1719
|
var EXITING_POINTER_EVENTS_STYLE = { pointerEvents: "none" };
|
|
208
1720
|
var DEFAULT_RESTING = {
|
|
209
1721
|
translateX: 0,
|
|
@@ -212,6 +1724,8 @@ var DEFAULT_RESTING = {
|
|
|
212
1724
|
scaleX: 1,
|
|
213
1725
|
scaleY: 1,
|
|
214
1726
|
rotate: 0,
|
|
1727
|
+
rotateX: 0,
|
|
1728
|
+
rotateY: 0,
|
|
215
1729
|
opacity: 1,
|
|
216
1730
|
width: 0,
|
|
217
1731
|
height: 0,
|
|
@@ -225,34 +1739,21 @@ var DEFAULT_RESTING = {
|
|
|
225
1739
|
color: "transparent",
|
|
226
1740
|
tintColor: "transparent"
|
|
227
1741
|
};
|
|
228
|
-
var TRANSITION_KEYS = /* @__PURE__ */ new Set([
|
|
229
|
-
"type",
|
|
230
|
-
"tension",
|
|
231
|
-
"friction",
|
|
232
|
-
"mass",
|
|
233
|
-
"velocity",
|
|
234
|
-
"restSpeedThreshold",
|
|
235
|
-
"restDisplacementThreshold",
|
|
236
|
-
"duration",
|
|
237
|
-
"easing",
|
|
238
|
-
"delay",
|
|
239
|
-
"repeat",
|
|
240
|
-
"deceleration",
|
|
241
|
-
"clamp"
|
|
242
|
-
]);
|
|
243
|
-
function isTopLevelTransition(t) {
|
|
244
|
-
if (t === null || typeof t !== "object") return false;
|
|
245
|
-
const keys = Object.keys(t);
|
|
246
|
-
if (keys.length === 0) return false;
|
|
247
|
-
return keys.every((k) => TRANSITION_KEYS.has(k));
|
|
248
|
-
}
|
|
249
1742
|
function transitionFor(prop, transition) {
|
|
250
1743
|
if (!transition) return void 0;
|
|
251
1744
|
if (isTopLevelTransition(transition)) return transition;
|
|
1745
|
+
if (GESTURE_LAYER_NAME_SET.has(prop)) return void 0;
|
|
252
1746
|
return transition[prop];
|
|
253
1747
|
}
|
|
1748
|
+
function gestureLayerTransitionFor(layer, transition) {
|
|
1749
|
+
if (!transition) return void 0;
|
|
1750
|
+
if (isTopLevelTransition(transition)) return transition;
|
|
1751
|
+
return transition[layer];
|
|
1752
|
+
}
|
|
254
1753
|
function createMotionComponent(Component) {
|
|
1754
|
+
ensureReanimatedInstalled();
|
|
255
1755
|
const AnimatedComponent = Animated.createAnimatedComponent(
|
|
1756
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
256
1757
|
Component
|
|
257
1758
|
);
|
|
258
1759
|
const Motion = forwardRef(function Motion2(props, ref) {
|
|
@@ -264,6 +1765,7 @@ function createMotionComponent(Component) {
|
|
|
264
1765
|
variants,
|
|
265
1766
|
controller,
|
|
266
1767
|
gesture,
|
|
1768
|
+
layout,
|
|
267
1769
|
onAnimationEnd,
|
|
268
1770
|
style,
|
|
269
1771
|
...rest
|
|
@@ -331,13 +1833,19 @@ function createMotionComponent(Component) {
|
|
|
331
1833
|
}
|
|
332
1834
|
return initialRecord?.[key] ?? restValue(animateRecord[key]) ?? DEFAULT_RESTING[key];
|
|
333
1835
|
});
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
1836
|
+
const pressedProgress = useSharedValue(0);
|
|
1837
|
+
const focusedProgress = useSharedValue(0);
|
|
1838
|
+
const focusVisibleProgress = useSharedValue(0);
|
|
1839
|
+
const hoveredProgress = useSharedValue(0);
|
|
1840
|
+
const gestureSV = useSharedValue(
|
|
1841
|
+
resolveGestureLayers(gesture)
|
|
1842
|
+
);
|
|
1843
|
+
const gestureTargetsSig = stableSig(gesture);
|
|
1844
|
+
useEffect(() => {
|
|
1845
|
+
gestureSV.value = resolveGestureLayers(gesture);
|
|
1846
|
+
}, [gestureTargetsSig]);
|
|
1847
|
+
const baseRecord = isExiting && exitRecord ? { ...animateRecord, ...exitRecord } : animateRecord;
|
|
1848
|
+
const baseSig = stableSig(baseRecord) + (isExiting ? "|exit" : "") + (shouldReduceMotion ? "|rm" : "");
|
|
341
1849
|
const transitionSig = stableSig(transition);
|
|
342
1850
|
const safeToRemoveRef = useRef(void 0);
|
|
343
1851
|
safeToRemoveRef.current = presence?.safeToRemove;
|
|
@@ -358,13 +1866,13 @@ function createMotionComponent(Component) {
|
|
|
358
1866
|
};
|
|
359
1867
|
let transformPending = 0;
|
|
360
1868
|
for (const k of ALL_KEYS) {
|
|
361
|
-
if (TRANSFORM_KEY_SET.has(k) &&
|
|
1869
|
+
if (TRANSFORM_KEY_SET.has(k) && baseRecord[k] !== void 0) {
|
|
362
1870
|
transformPending++;
|
|
363
1871
|
}
|
|
364
1872
|
}
|
|
365
1873
|
const transformGroup = transformPending > 0 ? { remaining: transformPending } : void 0;
|
|
366
1874
|
for (const key of ALL_KEYS) {
|
|
367
|
-
const target =
|
|
1875
|
+
const target = baseRecord[key];
|
|
368
1876
|
if (target === void 0) continue;
|
|
369
1877
|
const cfg = shouldReduceMotion ? { type: "no-animation" } : transitionFor(key, transition);
|
|
370
1878
|
if (isExiting) pending++;
|
|
@@ -389,17 +1897,79 @@ function createMotionComponent(Component) {
|
|
|
389
1897
|
if (isExiting && pending === 0) {
|
|
390
1898
|
safeToRemoveRef.current?.();
|
|
391
1899
|
}
|
|
392
|
-
}, [
|
|
1900
|
+
}, [baseSig, transitionSig]);
|
|
1901
|
+
useGestureLayerProgress(
|
|
1902
|
+
pressedProgress,
|
|
1903
|
+
pressed,
|
|
1904
|
+
gesture?.pressed != null,
|
|
1905
|
+
"pressed",
|
|
1906
|
+
transition,
|
|
1907
|
+
isExiting,
|
|
1908
|
+
shouldReduceMotion
|
|
1909
|
+
);
|
|
1910
|
+
useGestureLayerProgress(
|
|
1911
|
+
focusedProgress,
|
|
1912
|
+
focused,
|
|
1913
|
+
gesture?.focused != null,
|
|
1914
|
+
"focused",
|
|
1915
|
+
transition,
|
|
1916
|
+
isExiting,
|
|
1917
|
+
shouldReduceMotion
|
|
1918
|
+
);
|
|
1919
|
+
useGestureLayerProgress(
|
|
1920
|
+
focusVisibleProgress,
|
|
1921
|
+
focusVisible,
|
|
1922
|
+
gesture?.focusVisible != null,
|
|
1923
|
+
"focusVisible",
|
|
1924
|
+
transition,
|
|
1925
|
+
isExiting,
|
|
1926
|
+
shouldReduceMotion
|
|
1927
|
+
);
|
|
1928
|
+
useGestureLayerProgress(
|
|
1929
|
+
hoveredProgress,
|
|
1930
|
+
hovered,
|
|
1931
|
+
gesture?.hovered != null,
|
|
1932
|
+
"hovered",
|
|
1933
|
+
transition,
|
|
1934
|
+
isExiting,
|
|
1935
|
+
shouldReduceMotion
|
|
1936
|
+
);
|
|
393
1937
|
const animatedStyle = useAnimatedStyle(() => {
|
|
394
1938
|
const activeKeys = activeKeysRef.current;
|
|
395
1939
|
const hasTransform = hasTransformRef.current;
|
|
396
1940
|
const out = {};
|
|
397
1941
|
const transform = [];
|
|
1942
|
+
const ph = hoveredProgress.value;
|
|
1943
|
+
const pf = focusedProgress.value;
|
|
1944
|
+
const pfv = focusVisibleProgress.value;
|
|
1945
|
+
const pp = pressedProgress.value;
|
|
1946
|
+
const layers = gestureSV.value;
|
|
1947
|
+
const hoveredLayer = layers ? layers.hovered : null;
|
|
1948
|
+
const focusedLayer = layers ? layers.focused : null;
|
|
1949
|
+
const focusVisibleLayer = layers ? layers.focusVisible : null;
|
|
1950
|
+
const pressedLayer = layers ? layers.pressed : null;
|
|
398
1951
|
for (const key of activeKeys) {
|
|
399
|
-
|
|
1952
|
+
let v = sharedValues[key].value;
|
|
1953
|
+
const isColor = COLOR_KEY_SET.has(key);
|
|
1954
|
+
if (hoveredLayer && ph > 0 && hoveredLayer[key] !== void 0) {
|
|
1955
|
+
const t = hoveredLayer[key];
|
|
1956
|
+
v = isColor ? interpolateColor(ph, [0, 1], [v, t]) : v + (t - v) * ph;
|
|
1957
|
+
}
|
|
1958
|
+
if (focusedLayer && pf > 0 && focusedLayer[key] !== void 0) {
|
|
1959
|
+
const t = focusedLayer[key];
|
|
1960
|
+
v = isColor ? interpolateColor(pf, [0, 1], [v, t]) : v + (t - v) * pf;
|
|
1961
|
+
}
|
|
1962
|
+
if (focusVisibleLayer && pfv > 0 && focusVisibleLayer[key] !== void 0) {
|
|
1963
|
+
const t = focusVisibleLayer[key];
|
|
1964
|
+
v = isColor ? interpolateColor(pfv, [0, 1], [v, t]) : v + (t - v) * pfv;
|
|
1965
|
+
}
|
|
1966
|
+
if (pressedLayer && pp > 0 && pressedLayer[key] !== void 0) {
|
|
1967
|
+
const t = pressedLayer[key];
|
|
1968
|
+
v = isColor ? interpolateColor(pp, [0, 1], [v, t]) : v + (t - v) * pp;
|
|
1969
|
+
}
|
|
400
1970
|
if (TRANSFORM_KEY_SET.has(key)) {
|
|
401
1971
|
transform.push(
|
|
402
|
-
key
|
|
1972
|
+
ROTATION_KEYS.has(key) ? { [key]: `${v}deg` } : { [key]: v }
|
|
403
1973
|
);
|
|
404
1974
|
} else {
|
|
405
1975
|
out[key] = v;
|
|
@@ -420,12 +1990,19 @@ function createMotionComponent(Component) {
|
|
|
420
1990
|
setFocusVisible,
|
|
421
1991
|
setHovered
|
|
422
1992
|
);
|
|
1993
|
+
const layoutSig = stableSig(layout);
|
|
1994
|
+
const layoutTransition = useMemo(
|
|
1995
|
+
() => shouldReduceMotion ? void 0 : resolveLayoutTransition(layout),
|
|
1996
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1997
|
+
[layoutSig, shouldReduceMotion]
|
|
1998
|
+
);
|
|
423
1999
|
return /* @__PURE__ */ jsx(
|
|
424
2000
|
AnimatedComponent,
|
|
425
2001
|
{
|
|
426
2002
|
ref,
|
|
427
2003
|
...rest,
|
|
428
2004
|
...gestureHandlers,
|
|
2005
|
+
layout: layoutTransition,
|
|
429
2006
|
style: mergedStyle
|
|
430
2007
|
}
|
|
431
2008
|
);
|
|
@@ -433,23 +2010,25 @@ function createMotionComponent(Component) {
|
|
|
433
2010
|
Motion.displayName = `Motion(${Component.displayName ?? Component.name ?? "Component"})`;
|
|
434
2011
|
return Motion;
|
|
435
2012
|
}
|
|
436
|
-
function useAnimatableSharedValues(
|
|
437
|
-
const translateX = useSharedValue(
|
|
438
|
-
const translateY = useSharedValue(
|
|
439
|
-
const scale = useSharedValue(
|
|
440
|
-
const scaleX = useSharedValue(
|
|
441
|
-
const scaleY = useSharedValue(
|
|
442
|
-
const rotate = useSharedValue(
|
|
443
|
-
const
|
|
444
|
-
const
|
|
445
|
-
const
|
|
446
|
-
const
|
|
2013
|
+
function useAnimatableSharedValues(init2) {
|
|
2014
|
+
const translateX = useSharedValue(init2("translateX"));
|
|
2015
|
+
const translateY = useSharedValue(init2("translateY"));
|
|
2016
|
+
const scale = useSharedValue(init2("scale"));
|
|
2017
|
+
const scaleX = useSharedValue(init2("scaleX"));
|
|
2018
|
+
const scaleY = useSharedValue(init2("scaleY"));
|
|
2019
|
+
const rotate = useSharedValue(init2("rotate"));
|
|
2020
|
+
const rotateX = useSharedValue(init2("rotateX"));
|
|
2021
|
+
const rotateY = useSharedValue(init2("rotateY"));
|
|
2022
|
+
const opacity = useSharedValue(init2("opacity"));
|
|
2023
|
+
const width = useSharedValue(init2("width"));
|
|
2024
|
+
const height = useSharedValue(init2("height"));
|
|
2025
|
+
const borderRadius = useSharedValue(init2("borderRadius"));
|
|
447
2026
|
const backgroundColor = useSharedValue(
|
|
448
|
-
|
|
2027
|
+
init2("backgroundColor")
|
|
449
2028
|
);
|
|
450
|
-
const borderColor = useSharedValue(
|
|
451
|
-
const color = useSharedValue(
|
|
452
|
-
const tintColor = useSharedValue(
|
|
2029
|
+
const borderColor = useSharedValue(init2("borderColor"));
|
|
2030
|
+
const color = useSharedValue(init2("color"));
|
|
2031
|
+
const tintColor = useSharedValue(init2("tintColor"));
|
|
453
2032
|
const ref = useRef(null);
|
|
454
2033
|
if (ref.current === null) {
|
|
455
2034
|
ref.current = {
|
|
@@ -459,6 +2038,8 @@ function useAnimatableSharedValues(init) {
|
|
|
459
2038
|
scaleX,
|
|
460
2039
|
scaleY,
|
|
461
2040
|
rotate,
|
|
2041
|
+
rotateX,
|
|
2042
|
+
rotateY,
|
|
462
2043
|
opacity,
|
|
463
2044
|
width,
|
|
464
2045
|
height,
|
|
@@ -529,7 +2110,7 @@ function makeKeyCallbackFactory(key, sharedValue, target, onAnimationEndRef, met
|
|
|
529
2110
|
return (rawPhase, step) => {
|
|
530
2111
|
const cb = (finished) => {
|
|
531
2112
|
"worklet";
|
|
532
|
-
runOnJS(dispatch)(rawPhase, step, !!finished, sharedValue.value);
|
|
2113
|
+
runOnJS$1(dispatch)(rawPhase, step, !!finished, sharedValue.value);
|
|
533
2114
|
};
|
|
534
2115
|
return cb;
|
|
535
2116
|
};
|
|
@@ -595,72 +2176,41 @@ function restValue(v) {
|
|
|
595
2176
|
}
|
|
596
2177
|
return void 0;
|
|
597
2178
|
}
|
|
598
|
-
function
|
|
599
|
-
if (
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
return "[" + v.map(stableStringify).join(",") + "]";
|
|
2179
|
+
function resolveGestureLayers(gesture) {
|
|
2180
|
+
if (!gesture) return null;
|
|
2181
|
+
const out = {};
|
|
2182
|
+
for (const layer of GESTURE_LAYER_NAMES) {
|
|
2183
|
+
const subState = gesture[layer];
|
|
2184
|
+
if (!subState) continue;
|
|
2185
|
+
const resolved = {};
|
|
2186
|
+
for (const key of ALL_KEYS) {
|
|
2187
|
+
const raw = subState[key];
|
|
2188
|
+
if (raw === void 0) continue;
|
|
2189
|
+
const t = targetEndValue(raw);
|
|
2190
|
+
if (t !== void 0) resolved[key] = t;
|
|
2191
|
+
}
|
|
2192
|
+
out[layer] = resolved;
|
|
613
2193
|
}
|
|
614
|
-
|
|
615
|
-
const keys = Object.keys(obj).sort();
|
|
616
|
-
return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
|
|
2194
|
+
return out;
|
|
617
2195
|
}
|
|
618
|
-
function
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
gesture.focused,
|
|
626
|
-
gesture.focusVisible,
|
|
627
|
-
gesture.pressed
|
|
628
|
-
];
|
|
629
|
-
for (const sub of subStates) {
|
|
630
|
-
if (!sub) continue;
|
|
631
|
-
for (const k of ALL_KEYS) {
|
|
632
|
-
if (k in sub && !(k in merged)) {
|
|
633
|
-
merged[k] = DEFAULT_RESTING[k];
|
|
634
|
-
}
|
|
2196
|
+
function useGestureLayerProgress(progress, active, declared, layer, transition, isExiting, shouldReduceMotion) {
|
|
2197
|
+
const layerCfgSig = stableSig(gestureLayerTransitionFor(layer, transition));
|
|
2198
|
+
useEffect(() => {
|
|
2199
|
+
if (!declared) return;
|
|
2200
|
+
if (isExiting) {
|
|
2201
|
+
progress.value = 0;
|
|
2202
|
+
return;
|
|
635
2203
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
gesture.hovered
|
|
641
|
-
);
|
|
642
|
-
}
|
|
643
|
-
if (active.focused && gesture.focused) {
|
|
644
|
-
Object.assign(
|
|
645
|
-
merged,
|
|
646
|
-
gesture.focused
|
|
647
|
-
);
|
|
648
|
-
}
|
|
649
|
-
if (active.focusVisible && gesture.focusVisible) {
|
|
650
|
-
Object.assign(
|
|
651
|
-
merged,
|
|
652
|
-
gesture.focusVisible
|
|
653
|
-
);
|
|
654
|
-
}
|
|
655
|
-
if (active.pressed && gesture.pressed) {
|
|
656
|
-
Object.assign(
|
|
657
|
-
merged,
|
|
658
|
-
gesture.pressed
|
|
659
|
-
);
|
|
660
|
-
}
|
|
661
|
-
return merged;
|
|
2204
|
+
const target = active ? 1 : 0;
|
|
2205
|
+
const cfg = shouldReduceMotion ? { type: "no-animation" } : gestureLayerTransitionFor(layer, transition) ?? { type: "spring" };
|
|
2206
|
+
progress.value = resolveTransition(cfg, target);
|
|
2207
|
+
}, [active, declared, isExiting, shouldReduceMotion, layerCfgSig]);
|
|
662
2208
|
}
|
|
663
2209
|
function useGestureHandlers(gesture, rest, setPressed, setFocused, setFocusVisible, setHovered) {
|
|
2210
|
+
const hasPressed = gesture?.pressed ? 1 : 0;
|
|
2211
|
+
const hasFocused = gesture?.focused ? 1 : 0;
|
|
2212
|
+
const hasFocusVisible = gesture?.focusVisible ? 1 : 0;
|
|
2213
|
+
const hasHovered = gesture?.hovered ? 1 : 0;
|
|
664
2214
|
return useMemo(() => {
|
|
665
2215
|
if (!gesture) return {};
|
|
666
2216
|
const handlers = {};
|
|
@@ -693,10 +2243,10 @@ function useGestureHandlers(gesture, rest, setPressed, setFocused, setFocusVisib
|
|
|
693
2243
|
}
|
|
694
2244
|
return handlers;
|
|
695
2245
|
}, [
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
2246
|
+
hasPressed,
|
|
2247
|
+
hasFocused,
|
|
2248
|
+
hasFocusVisible,
|
|
2249
|
+
hasHovered,
|
|
700
2250
|
rest.onTouchStart,
|
|
701
2251
|
rest.onTouchEnd,
|
|
702
2252
|
rest.onTouchCancel,
|