@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
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import { Image, Pressable, ScrollView, Text, View
|
|
1
|
+
import { Platform, TurboModuleRegistry, Image, Pressable, ScrollView, Text, View } from 'react-native';
|
|
2
2
|
import { createContext, forwardRef, useRef, useState, useEffect, useMemo, useContext, Children, isValidElement, useCallback } 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, useAnimatedReaction, useDerivedValue, Extrapolation, useAnimatedScrollHandler, interpolate } from 'react-native-reanimated';
|
|
4
4
|
import { jsx, Fragment } 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
|
};
|
|
@@ -30,28 +42,1464 @@ function MotionConfig({
|
|
|
30
42
|
);
|
|
31
43
|
return /* @__PURE__ */ jsx(MotionConfigContext.Provider, { value, children });
|
|
32
44
|
}
|
|
33
|
-
var modality = "keyboard";
|
|
34
|
-
var installed = false;
|
|
35
|
-
function setKeyboard() {
|
|
36
|
-
modality = "keyboard";
|
|
45
|
+
var modality = "keyboard";
|
|
46
|
+
var installed = false;
|
|
47
|
+
function setKeyboard() {
|
|
48
|
+
modality = "keyboard";
|
|
49
|
+
}
|
|
50
|
+
function setPointer() {
|
|
51
|
+
modality = "pointer";
|
|
52
|
+
}
|
|
53
|
+
function ensureInstalled() {
|
|
54
|
+
if (installed) return;
|
|
55
|
+
if (Platform.OS !== "web") return;
|
|
56
|
+
if (typeof document === "undefined") return;
|
|
57
|
+
document.addEventListener("keydown", setKeyboard, true);
|
|
58
|
+
document.addEventListener("mousedown", setPointer, true);
|
|
59
|
+
document.addEventListener("pointerdown", setPointer, true);
|
|
60
|
+
document.addEventListener("touchstart", setPointer, true);
|
|
61
|
+
installed = true;
|
|
62
|
+
}
|
|
63
|
+
function isFocusVisible() {
|
|
64
|
+
if (Platform.OS !== "web") return true;
|
|
65
|
+
ensureInstalled();
|
|
66
|
+
return modality === "keyboard";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ../../node_modules/react-native-worklets/lib/module/logger.js
|
|
70
|
+
var PREFIX = "[Worklets]";
|
|
71
|
+
function formatMessage(message) {
|
|
72
|
+
return `${PREFIX} ${message}`;
|
|
73
|
+
}
|
|
74
|
+
var logger = {
|
|
75
|
+
warn(message) {
|
|
76
|
+
console.warn(formatMessage(message));
|
|
77
|
+
},
|
|
78
|
+
error(message) {
|
|
79
|
+
console.error(formatMessage(message));
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// ../../node_modules/react-native-worklets/lib/module/runtimeKind.js
|
|
84
|
+
var RuntimeKind = /* @__PURE__ */ (function(RuntimeKind2) {
|
|
85
|
+
RuntimeKind2[RuntimeKind2["ReactNative"] = 1] = "ReactNative";
|
|
86
|
+
RuntimeKind2[RuntimeKind2["UI"] = 2] = "UI";
|
|
87
|
+
RuntimeKind2[RuntimeKind2["Worker"] = 3] = "Worker";
|
|
88
|
+
return RuntimeKind2;
|
|
89
|
+
})({});
|
|
90
|
+
if (globalThis.__RUNTIME_KIND === void 0) {
|
|
91
|
+
globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsError.js
|
|
95
|
+
function WorkletsErrorConstructor(message) {
|
|
96
|
+
"worklet";
|
|
97
|
+
const prefix = "[Worklets]";
|
|
98
|
+
const errorInstance = new Error(message ? `${prefix} ${message}` : prefix);
|
|
99
|
+
errorInstance.name = `WorkletsError`;
|
|
100
|
+
return errorInstance;
|
|
101
|
+
}
|
|
102
|
+
function registerWorkletsError() {
|
|
103
|
+
"worklet";
|
|
104
|
+
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
|
|
105
|
+
globalThis.WorkletsError = WorkletsErrorConstructor;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
var WorkletsError = WorkletsErrorConstructor;
|
|
109
|
+
|
|
110
|
+
// ../../node_modules/react-native-worklets/lib/module/bundleUnpacker.js
|
|
111
|
+
var handleCache = /* @__PURE__ */ new WeakMap();
|
|
112
|
+
function bundleValueUnpacker(objectToUnpack, category, remoteFunctionName) {
|
|
113
|
+
const workletHash = objectToUnpack.__workletHash;
|
|
114
|
+
if (workletHash !== void 0) {
|
|
115
|
+
return getWorklet(workletHash, objectToUnpack.__closure);
|
|
116
|
+
} else if (objectToUnpack.__init !== void 0) {
|
|
117
|
+
let value = handleCache.get(objectToUnpack);
|
|
118
|
+
if (value === void 0) {
|
|
119
|
+
value = objectToUnpack.__init();
|
|
120
|
+
handleCache.set(objectToUnpack, value);
|
|
121
|
+
}
|
|
122
|
+
return value;
|
|
123
|
+
} else if (category === "RemoteFunction") {
|
|
124
|
+
const remoteFunctionHolder = () => {
|
|
125
|
+
const label = remoteFunctionName ? `function \`${remoteFunctionName}\`` : "anonymous function";
|
|
126
|
+
throw new WorkletsError(`Tried to synchronously call a non-worklet ${label} on the UI thread.
|
|
127
|
+
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.`);
|
|
128
|
+
};
|
|
129
|
+
remoteFunctionHolder.__remoteFunction = objectToUnpack;
|
|
130
|
+
return remoteFunctionHolder;
|
|
131
|
+
} else {
|
|
132
|
+
throw new WorkletsError(`Data type in category "${category}" not recognized by value unpacker: "${globalThis._toString(objectToUnpack)}".`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function getWorklet(workletHash, closureVariables) {
|
|
136
|
+
let worklet;
|
|
137
|
+
if (__DEV__) {
|
|
138
|
+
try {
|
|
139
|
+
worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
|
|
140
|
+
} catch (_e) {
|
|
141
|
+
logger.error("Unable to resolve worklet with hash " + workletHash + ". Try reloading the app.");
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
|
|
145
|
+
}
|
|
146
|
+
return worklet;
|
|
147
|
+
}
|
|
148
|
+
var metroRequire = globalThis.__r;
|
|
149
|
+
function getWorkletFromMetroRequire(workletHash, closureVariables) {
|
|
150
|
+
const factory = metroRequire(workletHash).default;
|
|
151
|
+
return factory(closureVariables);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ../../node_modules/react-native-worklets/lib/module/callGuard.js
|
|
155
|
+
function callGuardDEV(fn, ...args) {
|
|
156
|
+
"worklet";
|
|
157
|
+
try {
|
|
158
|
+
return fn(...args);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
if (globalThis.__workletsModuleProxy) {
|
|
161
|
+
const {
|
|
162
|
+
message,
|
|
163
|
+
stack,
|
|
164
|
+
name,
|
|
165
|
+
jsEngine
|
|
166
|
+
} = error;
|
|
167
|
+
globalThis.__workletsModuleProxy.reportFatalErrorOnJS(message, stack ?? "", name ?? "WorkletsError", jsEngine ?? "Worklets");
|
|
168
|
+
} else {
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function setupCallGuard() {
|
|
174
|
+
"worklet";
|
|
175
|
+
if (!globalThis.__callGuardDEV) {
|
|
176
|
+
globalThis.__callGuardDEV = callGuardDEV;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ../../node_modules/react-native-worklets/lib/module/errors.js
|
|
181
|
+
var _workletStackDetails = /* @__PURE__ */ new Map();
|
|
182
|
+
function registerWorkletStackDetails(hash, stackDetails) {
|
|
183
|
+
_workletStackDetails.set(hash, stackDetails);
|
|
184
|
+
}
|
|
185
|
+
function getBundleOffset(error) {
|
|
186
|
+
const frame = error.stack?.split("\n")?.[0];
|
|
187
|
+
if (frame) {
|
|
188
|
+
const parsedFrame = /@([^@]+):(\d+):(\d+)/.exec(frame);
|
|
189
|
+
if (parsedFrame) {
|
|
190
|
+
const [, file, line, col] = parsedFrame;
|
|
191
|
+
return [file, Number(line), Number(col)];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return ["unknown", 0, 0];
|
|
195
|
+
}
|
|
196
|
+
function processStack(stack) {
|
|
197
|
+
if (stack === "" || stack === void 0) {
|
|
198
|
+
return void 0;
|
|
199
|
+
}
|
|
200
|
+
const workletStackEntries = stack.match(/worklet_(\d+):(\d+):(\d+)/g);
|
|
201
|
+
let result = stack;
|
|
202
|
+
workletStackEntries?.forEach((match) => {
|
|
203
|
+
const [, hash, origLine, origCol] = match.split(/:|_/).map(Number);
|
|
204
|
+
const errorDetails = _workletStackDetails.get(hash);
|
|
205
|
+
if (!errorDetails) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const [error, lineOffset, colOffset] = errorDetails;
|
|
209
|
+
const [bundleFile, bundleLine, bundleCol] = getBundleOffset(error);
|
|
210
|
+
const line = origLine + bundleLine + lineOffset;
|
|
211
|
+
const col = origCol + bundleCol + colOffset;
|
|
212
|
+
result = result.replace(match, `${bundleFile}:${line}:${col}`);
|
|
213
|
+
});
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
216
|
+
function reportFatalRemoteError({
|
|
217
|
+
message,
|
|
218
|
+
stack,
|
|
219
|
+
name,
|
|
220
|
+
jsEngine
|
|
221
|
+
}, force) {
|
|
222
|
+
const error = new WorkletsError();
|
|
223
|
+
error.message = message;
|
|
224
|
+
error.stack = processStack(stack);
|
|
225
|
+
error.name = name;
|
|
226
|
+
error.jsEngine = jsEngine;
|
|
227
|
+
if (force) {
|
|
228
|
+
throw error;
|
|
229
|
+
} else {
|
|
230
|
+
globalThis.ErrorUtils.reportFatalError(error);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function registerReportFatalRemoteError() {
|
|
234
|
+
globalThis.__reportFatalRemoteError = reportFatalRemoteError;
|
|
235
|
+
}
|
|
236
|
+
var IS_JEST = !!process.env.JEST_WORKER_ID;
|
|
237
|
+
var IS_WEB = Platform.OS === "web";
|
|
238
|
+
var IS_WINDOWS = Platform.OS === "windows";
|
|
239
|
+
var SHOULD_BE_USE_WEB = IS_JEST || IS_WEB || IS_WINDOWS;
|
|
240
|
+
|
|
241
|
+
// ../../node_modules/react-native-worklets/lib/module/PlatformChecker/index.js
|
|
242
|
+
var IS_JEST2 = false;
|
|
243
|
+
var SHOULD_BE_USE_WEB2 = false;
|
|
244
|
+
if (globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
|
245
|
+
IS_JEST2 = IS_JEST;
|
|
246
|
+
SHOULD_BE_USE_WEB2 = SHOULD_BE_USE_WEB;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/common/setImmediatePolyfill.js
|
|
250
|
+
function setupSetImmediate() {
|
|
251
|
+
"worklet";
|
|
252
|
+
const setImmediatePolyfill = (callback, ...args) => {
|
|
253
|
+
return setTimeout(callback, 0, ...args);
|
|
254
|
+
};
|
|
255
|
+
const clearImmediatePolyfill = (immediateHandle) => {
|
|
256
|
+
clearTimeout(immediateHandle);
|
|
257
|
+
};
|
|
258
|
+
globalThis.setImmediate = setImmediatePolyfill;
|
|
259
|
+
globalThis.clearImmediate = clearImmediatePolyfill;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/common/setIntervalPolyfill.js
|
|
263
|
+
function setupSetInterval() {
|
|
264
|
+
"worklet";
|
|
265
|
+
const intervalHandleToTimeoutHandle = /* @__PURE__ */ new Map();
|
|
266
|
+
const setIntervalPolyfill = (callback, delay = 0, ...args) => {
|
|
267
|
+
let intervalHandle = 0;
|
|
268
|
+
const repeatingCallback = () => {
|
|
269
|
+
const timeoutHandle = setTimeout(repeatingCallback, delay);
|
|
270
|
+
intervalHandleToTimeoutHandle.set(intervalHandle, timeoutHandle);
|
|
271
|
+
callback(...args);
|
|
272
|
+
};
|
|
273
|
+
intervalHandle = setTimeout(repeatingCallback, delay);
|
|
274
|
+
intervalHandleToTimeoutHandle.set(intervalHandle, intervalHandle);
|
|
275
|
+
return intervalHandle;
|
|
276
|
+
};
|
|
277
|
+
const clearIntervalPolyfill = (intervalHandle) => {
|
|
278
|
+
const timeoutHandle = intervalHandleToTimeoutHandle.get(intervalHandle);
|
|
279
|
+
clearTimeout(timeoutHandle);
|
|
280
|
+
intervalHandleToTimeoutHandle.delete(intervalHandle);
|
|
281
|
+
};
|
|
282
|
+
globalThis.setInterval = setIntervalPolyfill;
|
|
283
|
+
globalThis.clearInterval = clearIntervalPolyfill;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js
|
|
287
|
+
function mockedRequestAnimationFrame(callback) {
|
|
288
|
+
return setTimeout(() => callback(performance.now()), 0);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// ../../node_modules/react-native-worklets/lib/module/isSynchronizable.js
|
|
292
|
+
function isSynchronizable(value) {
|
|
293
|
+
return typeof value === "object" && value !== null && "__synchronizableRef" in value && value.__synchronizableRef === true;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// ../../node_modules/react-native-worklets/lib/module/serializableMappingCache.js
|
|
297
|
+
var serializableMappingFlag = /* @__PURE__ */ Symbol("serializable flag");
|
|
298
|
+
var cache = SHOULD_BE_USE_WEB2 ? null : /* @__PURE__ */ new WeakMap();
|
|
299
|
+
var serializableMappingCache = SHOULD_BE_USE_WEB2 ? {
|
|
300
|
+
set() {
|
|
301
|
+
},
|
|
302
|
+
get() {
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
} : {
|
|
306
|
+
set(serializable, serializableRef) {
|
|
307
|
+
cache.set(serializable, serializableRef || serializableMappingFlag);
|
|
308
|
+
},
|
|
309
|
+
get: cache.get.bind(cache)
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// ../../node_modules/react-native-worklets/lib/module/utils/jsVersion.js
|
|
313
|
+
var jsVersion = "0.5.1";
|
|
314
|
+
|
|
315
|
+
// ../../node_modules/react-native-worklets/lib/module/workletFunction.js
|
|
316
|
+
function isWorkletFunction(value) {
|
|
317
|
+
"worklet";
|
|
318
|
+
return (
|
|
319
|
+
// `__workletHash` isn't extracted in Worklet Runtimes.
|
|
320
|
+
typeof value === "function" && !!value.__workletHash
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsModule/JSWorklets.js
|
|
325
|
+
function createJSWorkletsModule() {
|
|
326
|
+
return new JSWorklets();
|
|
327
|
+
}
|
|
328
|
+
var requestAnimationFrameImpl = IS_JEST2 || !globalThis.requestAnimationFrame ? mockedRequestAnimationFrame : globalThis.requestAnimationFrame;
|
|
329
|
+
var JSWorklets = class {
|
|
330
|
+
createSerializable() {
|
|
331
|
+
throw new WorkletsError("createSerializable should never be called in JSWorklets.");
|
|
332
|
+
}
|
|
333
|
+
createSerializableString() {
|
|
334
|
+
throw new WorkletsError("createSerializableString should never be called in JSWorklets.");
|
|
335
|
+
}
|
|
336
|
+
createSerializableNumber() {
|
|
337
|
+
throw new WorkletsError("createSerializableNumber should never be called in JSWorklets.");
|
|
338
|
+
}
|
|
339
|
+
createSerializableBoolean() {
|
|
340
|
+
throw new WorkletsError("createSerializableBoolean should never be called in JSWorklets.");
|
|
341
|
+
}
|
|
342
|
+
createSerializableBigInt() {
|
|
343
|
+
throw new WorkletsError("createSerializableBigInt should never be called in JSWorklets.");
|
|
344
|
+
}
|
|
345
|
+
createSerializableUndefined() {
|
|
346
|
+
throw new WorkletsError("createSerializableUndefined should never be called in JSWorklets.");
|
|
347
|
+
}
|
|
348
|
+
createSerializableNull() {
|
|
349
|
+
throw new WorkletsError("createSerializableNull should never be called in JSWorklets.");
|
|
350
|
+
}
|
|
351
|
+
createSerializableTurboModuleLike() {
|
|
352
|
+
throw new WorkletsError("createSerializableTurboModuleLike should never be called in JSWorklets.");
|
|
353
|
+
}
|
|
354
|
+
createSerializableObject() {
|
|
355
|
+
throw new WorkletsError("createSerializableObject should never be called in JSWorklets.");
|
|
356
|
+
}
|
|
357
|
+
createSerializableMap() {
|
|
358
|
+
throw new WorkletsError("createSerializableMap should never be called in JSWorklets.");
|
|
359
|
+
}
|
|
360
|
+
createSerializableSet() {
|
|
361
|
+
throw new WorkletsError("createSerializableSet should never be called in JSWorklets.");
|
|
362
|
+
}
|
|
363
|
+
createSerializableImport() {
|
|
364
|
+
throw new WorkletsError("createSerializableImport should never be called in JSWorklets.");
|
|
365
|
+
}
|
|
366
|
+
createSerializableHostObject() {
|
|
367
|
+
throw new WorkletsError("createSerializableHostObject should never be called in JSWorklets.");
|
|
368
|
+
}
|
|
369
|
+
createSerializableArray() {
|
|
370
|
+
throw new WorkletsError("createSerializableArray should never be called in JSWorklets.");
|
|
371
|
+
}
|
|
372
|
+
createSerializableInitializer() {
|
|
373
|
+
throw new WorkletsError("createSerializableInitializer should never be called in JSWorklets.");
|
|
374
|
+
}
|
|
375
|
+
createSerializableFunction() {
|
|
376
|
+
throw new WorkletsError("createSerializableFunction should never be called in JSWorklets.");
|
|
377
|
+
}
|
|
378
|
+
createSerializableWorklet() {
|
|
379
|
+
throw new WorkletsError("createSerializableWorklet should never be called in JSWorklets.");
|
|
380
|
+
}
|
|
381
|
+
scheduleOnUI(worklet) {
|
|
382
|
+
requestAnimationFrameImpl(worklet);
|
|
383
|
+
}
|
|
384
|
+
executeOnUIRuntimeSync() {
|
|
385
|
+
throw new WorkletsError("`executeOnUIRuntimeSync` is not available in JSWorklets.");
|
|
386
|
+
}
|
|
387
|
+
createWorkletRuntime() {
|
|
388
|
+
throw new WorkletsError("createWorkletRuntime is not available in JSWorklets.");
|
|
389
|
+
}
|
|
390
|
+
scheduleOnRuntime() {
|
|
391
|
+
throw new WorkletsError("scheduleOnRuntime is not available in JSWorklets.");
|
|
392
|
+
}
|
|
393
|
+
createSynchronizable() {
|
|
394
|
+
throw new WorkletsError("createSynchronizable should never be called in JSWorklets.");
|
|
395
|
+
}
|
|
396
|
+
synchronizableGetDirty() {
|
|
397
|
+
throw new WorkletsError("synchronizableGetDirty should never be called in JSWorklets.");
|
|
398
|
+
}
|
|
399
|
+
synchronizableGetBlocking() {
|
|
400
|
+
throw new WorkletsError("synchronizableGetBlocking should never be called in JSWorklets.");
|
|
401
|
+
}
|
|
402
|
+
synchronizableSetBlocking() {
|
|
403
|
+
throw new WorkletsError("synchronizableSetBlocking should never be called in JSWorklets.");
|
|
404
|
+
}
|
|
405
|
+
synchronizableLock() {
|
|
406
|
+
throw new WorkletsError("synchronizableLock should never be called in JSWorklets.");
|
|
407
|
+
}
|
|
408
|
+
synchronizableUnlock() {
|
|
409
|
+
throw new WorkletsError("synchronizableUnlock should never be called in JSWorklets.");
|
|
410
|
+
}
|
|
411
|
+
reportFatalErrorOnJS() {
|
|
412
|
+
throw new WorkletsError("reportFatalErrorOnJS should never be called in JSWorklets.");
|
|
413
|
+
}
|
|
414
|
+
getStaticFeatureFlag() {
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
setDynamicFeatureFlag() {
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
var NativeWorkletsModule_default = TurboModuleRegistry.get("WorkletsModule");
|
|
421
|
+
|
|
422
|
+
// ../../node_modules/react-native-worklets/lib/module/specs/index.js
|
|
423
|
+
var WorkletsTurboModule = globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative ? NativeWorkletsModule_default : (
|
|
424
|
+
// In Bundle Mode, on Worklet Runtimes `RNWorkletsTurboModule` isn't
|
|
425
|
+
// available and shouldn't be accessed. We return null here
|
|
426
|
+
// to keep the same codebase for the Bundle Mode and legacy behavior.
|
|
427
|
+
null
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
// ../../node_modules/react-native-worklets/lib/module/utils/checkCppVersion.js
|
|
431
|
+
function checkCppVersion() {
|
|
432
|
+
const cppVersion = global._WORKLETS_VERSION_CPP;
|
|
433
|
+
if (cppVersion === void 0) {
|
|
434
|
+
logger.warn(`Couldn't determine the version of the native part of Worklets.
|
|
435
|
+
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#couldnt-determine-the-version-of-the-native-part-of-worklets\` for more details.`);
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
const ok = matchVersion(jsVersion, cppVersion);
|
|
439
|
+
if (!ok) {
|
|
440
|
+
throw new WorkletsError(`Mismatch between JavaScript part and native part of Worklets (${jsVersion} vs ${cppVersion}).
|
|
441
|
+
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-part-and-native-part-of-worklets\` for more details.`);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
function matchVersion(version1, version2) {
|
|
445
|
+
if (version1.match(/^\d+\.\d+\.\d+$/) && version2.match(/^\d+\.\d+\.\d+$/)) {
|
|
446
|
+
const [major1, minor1] = version1.split(".");
|
|
447
|
+
const [major2, minor2] = version2.split(".");
|
|
448
|
+
return major1 === major2 && minor1 === minor2;
|
|
449
|
+
} else {
|
|
450
|
+
return version1 === version2;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsModule/NativeWorklets.js
|
|
455
|
+
function createNativeWorkletsModule() {
|
|
456
|
+
return new NativeWorklets();
|
|
457
|
+
}
|
|
458
|
+
var _workletsModuleProxy, _serializableUndefined, _serializableNull, _serializableTrue, _serializableFalse;
|
|
459
|
+
var NativeWorklets = class {
|
|
460
|
+
constructor() {
|
|
461
|
+
__privateAdd(this, _workletsModuleProxy);
|
|
462
|
+
__privateAdd(this, _serializableUndefined);
|
|
463
|
+
__privateAdd(this, _serializableNull);
|
|
464
|
+
__privateAdd(this, _serializableTrue);
|
|
465
|
+
__privateAdd(this, _serializableFalse);
|
|
466
|
+
globalThis._WORKLETS_VERSION_JS = jsVersion;
|
|
467
|
+
if (global.__workletsModuleProxy === void 0 && globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
|
468
|
+
WorkletsTurboModule?.installTurboModule();
|
|
469
|
+
}
|
|
470
|
+
if (global.__workletsModuleProxy === void 0) {
|
|
471
|
+
throw new WorkletsError(`Native part of Worklets doesn't seem to be initialized.
|
|
472
|
+
See https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#native-part-of-worklets-doesnt-seem-to-be-initialized for more details.`);
|
|
473
|
+
}
|
|
474
|
+
if (__DEV__) {
|
|
475
|
+
checkCppVersion();
|
|
476
|
+
}
|
|
477
|
+
__privateSet(this, _workletsModuleProxy, global.__workletsModuleProxy);
|
|
478
|
+
__privateSet(this, _serializableNull, __privateGet(this, _workletsModuleProxy).createSerializableNull());
|
|
479
|
+
__privateSet(this, _serializableUndefined, __privateGet(this, _workletsModuleProxy).createSerializableUndefined());
|
|
480
|
+
__privateSet(this, _serializableTrue, __privateGet(this, _workletsModuleProxy).createSerializableBoolean(true));
|
|
481
|
+
__privateSet(this, _serializableFalse, __privateGet(this, _workletsModuleProxy).createSerializableBoolean(false));
|
|
482
|
+
}
|
|
483
|
+
createSerializable(value, shouldPersistRemote, nativeStateSource) {
|
|
484
|
+
return __privateGet(this, _workletsModuleProxy).createSerializable(value, shouldPersistRemote, nativeStateSource);
|
|
485
|
+
}
|
|
486
|
+
createSerializableImport(from, to) {
|
|
487
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableImport(from, to);
|
|
488
|
+
}
|
|
489
|
+
createSerializableString(str) {
|
|
490
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableString(str);
|
|
491
|
+
}
|
|
492
|
+
createSerializableNumber(num) {
|
|
493
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableNumber(num);
|
|
494
|
+
}
|
|
495
|
+
createSerializableBoolean(bool) {
|
|
496
|
+
return bool ? __privateGet(this, _serializableTrue) : __privateGet(this, _serializableFalse);
|
|
497
|
+
}
|
|
498
|
+
createSerializableBigInt(bigInt) {
|
|
499
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableBigInt(bigInt);
|
|
500
|
+
}
|
|
501
|
+
createSerializableUndefined() {
|
|
502
|
+
return __privateGet(this, _serializableUndefined);
|
|
503
|
+
}
|
|
504
|
+
createSerializableNull() {
|
|
505
|
+
return __privateGet(this, _serializableNull);
|
|
506
|
+
}
|
|
507
|
+
createSerializableTurboModuleLike(props, proto) {
|
|
508
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableTurboModuleLike(props, proto);
|
|
509
|
+
}
|
|
510
|
+
createSerializableObject(obj, shouldRetainRemote, nativeStateSource) {
|
|
511
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableObject(obj, shouldRetainRemote, nativeStateSource);
|
|
512
|
+
}
|
|
513
|
+
createSerializableHostObject(obj) {
|
|
514
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableHostObject(obj);
|
|
515
|
+
}
|
|
516
|
+
createSerializableArray(array, shouldRetainRemote) {
|
|
517
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableArray(array, shouldRetainRemote);
|
|
518
|
+
}
|
|
519
|
+
createSerializableMap(keys, values) {
|
|
520
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableMap(keys, values);
|
|
521
|
+
}
|
|
522
|
+
createSerializableSet(values) {
|
|
523
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableSet(values);
|
|
524
|
+
}
|
|
525
|
+
createSerializableInitializer(obj) {
|
|
526
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableInitializer(obj);
|
|
527
|
+
}
|
|
528
|
+
createSerializableFunction(func) {
|
|
529
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableFunction(func);
|
|
530
|
+
}
|
|
531
|
+
createSerializableWorklet(worklet, shouldPersistRemote) {
|
|
532
|
+
return __privateGet(this, _workletsModuleProxy).createSerializableWorklet(worklet, shouldPersistRemote);
|
|
533
|
+
}
|
|
534
|
+
scheduleOnUI(serializable) {
|
|
535
|
+
return __privateGet(this, _workletsModuleProxy).scheduleOnUI(serializable);
|
|
536
|
+
}
|
|
537
|
+
executeOnUIRuntimeSync(serializable) {
|
|
538
|
+
return __privateGet(this, _workletsModuleProxy).executeOnUIRuntimeSync(serializable);
|
|
539
|
+
}
|
|
540
|
+
createWorkletRuntime(name, initializer, useDefaultQueue, customQueue, enableEventLoop) {
|
|
541
|
+
return __privateGet(this, _workletsModuleProxy).createWorkletRuntime(name, initializer, useDefaultQueue, customQueue, enableEventLoop);
|
|
542
|
+
}
|
|
543
|
+
scheduleOnRuntime(workletRuntime, serializableWorklet) {
|
|
544
|
+
return __privateGet(this, _workletsModuleProxy).scheduleOnRuntime(workletRuntime, serializableWorklet);
|
|
545
|
+
}
|
|
546
|
+
createSynchronizable(value) {
|
|
547
|
+
return __privateGet(this, _workletsModuleProxy).createSynchronizable(value);
|
|
548
|
+
}
|
|
549
|
+
synchronizableGetDirty(synchronizableRef) {
|
|
550
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableGetDirty(synchronizableRef);
|
|
551
|
+
}
|
|
552
|
+
synchronizableGetBlocking(synchronizableRef) {
|
|
553
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableGetBlocking(synchronizableRef);
|
|
554
|
+
}
|
|
555
|
+
synchronizableSetBlocking(synchronizableRef, value) {
|
|
556
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableSetBlocking(synchronizableRef, value);
|
|
557
|
+
}
|
|
558
|
+
synchronizableLock(synchronizableRef) {
|
|
559
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableLock(synchronizableRef);
|
|
560
|
+
}
|
|
561
|
+
synchronizableUnlock(synchronizableRef) {
|
|
562
|
+
return __privateGet(this, _workletsModuleProxy).synchronizableUnlock(synchronizableRef);
|
|
563
|
+
}
|
|
564
|
+
reportFatalErrorOnJS(message, stack, name, jsEngine) {
|
|
565
|
+
return __privateGet(this, _workletsModuleProxy).reportFatalErrorOnJS(message, stack, name, jsEngine);
|
|
566
|
+
}
|
|
567
|
+
getStaticFeatureFlag(name) {
|
|
568
|
+
return __privateGet(this, _workletsModuleProxy).getStaticFeatureFlag(name);
|
|
569
|
+
}
|
|
570
|
+
setDynamicFeatureFlag(name, value) {
|
|
571
|
+
__privateGet(this, _workletsModuleProxy).setDynamicFeatureFlag(name, value);
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
_workletsModuleProxy = new WeakMap();
|
|
575
|
+
_serializableUndefined = new WeakMap();
|
|
576
|
+
_serializableNull = new WeakMap();
|
|
577
|
+
_serializableTrue = new WeakMap();
|
|
578
|
+
_serializableFalse = new WeakMap();
|
|
579
|
+
|
|
580
|
+
// ../../node_modules/react-native-worklets/lib/module/WorkletsModule/workletsModuleInstance.js
|
|
581
|
+
var WorkletsModule = SHOULD_BE_USE_WEB2 ? createJSWorkletsModule() : createNativeWorkletsModule();
|
|
582
|
+
|
|
583
|
+
// ../../node_modules/react-native-worklets/lib/module/serializable.js
|
|
584
|
+
var MAGIC_KEY = "REANIMATED_MAGIC_KEY";
|
|
585
|
+
function isHostObject(value) {
|
|
586
|
+
"worklet";
|
|
587
|
+
return MAGIC_KEY in value;
|
|
588
|
+
}
|
|
589
|
+
function isPlainJSObject(object) {
|
|
590
|
+
"worklet";
|
|
591
|
+
return Object.getPrototypeOf(object) === Object.prototype;
|
|
592
|
+
}
|
|
593
|
+
function isTurboModuleLike(object) {
|
|
594
|
+
return isHostObject(Object.getPrototypeOf(object));
|
|
595
|
+
}
|
|
596
|
+
function getFromCache(value) {
|
|
597
|
+
const cached = serializableMappingCache.get(value);
|
|
598
|
+
if (cached === serializableMappingFlag) {
|
|
599
|
+
return value;
|
|
600
|
+
}
|
|
601
|
+
return cached;
|
|
602
|
+
}
|
|
603
|
+
var INACCESSIBLE_OBJECT = {
|
|
604
|
+
__init: () => {
|
|
605
|
+
"worklet";
|
|
606
|
+
return new Proxy({}, {
|
|
607
|
+
get: (_, prop) => {
|
|
608
|
+
if (prop === "_isReanimatedSharedValue" || prop === "__remoteFunction") {
|
|
609
|
+
return false;
|
|
610
|
+
}
|
|
611
|
+
throw new WorkletsError(`Trying to access property \`${String(prop)}\` of an object which cannot be sent to the UI runtime.`);
|
|
612
|
+
},
|
|
613
|
+
set: () => {
|
|
614
|
+
throw new WorkletsError("Trying to write to an object which cannot be sent to the UI runtime.");
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
var VALID_ARRAY_VIEWS_NAMES = ["Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt64Array", "BigUint64Array", "DataView"];
|
|
620
|
+
var DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD = 30;
|
|
621
|
+
var processedObjectAtThresholdDepth;
|
|
622
|
+
function createSerializableWeb(value) {
|
|
623
|
+
return value;
|
|
624
|
+
}
|
|
625
|
+
function createSerializableNative(value, shouldPersistRemote = false, depth = 0) {
|
|
626
|
+
detectCyclicObject(value, depth);
|
|
627
|
+
const isObject = typeof value === "object";
|
|
628
|
+
const isFunction = typeof value === "function";
|
|
629
|
+
if (typeof value === "string") {
|
|
630
|
+
return cloneString(value);
|
|
631
|
+
}
|
|
632
|
+
if (typeof value === "number") {
|
|
633
|
+
return cloneNumber(value);
|
|
634
|
+
}
|
|
635
|
+
if (typeof value === "boolean") {
|
|
636
|
+
return cloneBoolean(value);
|
|
637
|
+
}
|
|
638
|
+
if (typeof value === "bigint") {
|
|
639
|
+
return cloneBigInt(value);
|
|
640
|
+
}
|
|
641
|
+
if (value === void 0) {
|
|
642
|
+
return cloneUndefined();
|
|
643
|
+
}
|
|
644
|
+
if (value === null) {
|
|
645
|
+
return cloneNull();
|
|
646
|
+
}
|
|
647
|
+
if (!isObject && !isFunction || value === null) {
|
|
648
|
+
return clonePrimitive(value, shouldPersistRemote);
|
|
649
|
+
}
|
|
650
|
+
const cached = getFromCache(value);
|
|
651
|
+
if (cached !== void 0) {
|
|
652
|
+
return cached;
|
|
653
|
+
}
|
|
654
|
+
if (Array.isArray(value)) {
|
|
655
|
+
return cloneArray(value, shouldPersistRemote, depth);
|
|
656
|
+
}
|
|
657
|
+
if (globalThis._WORKLETS_BUNDLE_MODE && isFunction && value.__bundleData) {
|
|
658
|
+
return cloneImport(value);
|
|
659
|
+
}
|
|
660
|
+
if (isFunction && !isWorkletFunction(value)) {
|
|
661
|
+
return cloneRemoteFunction(value);
|
|
662
|
+
}
|
|
663
|
+
if (isTurboModuleLike(value)) {
|
|
664
|
+
return cloneTurboModuleLike(value, shouldPersistRemote, depth);
|
|
665
|
+
}
|
|
666
|
+
if (isHostObject(value)) {
|
|
667
|
+
return cloneHostObject(value);
|
|
668
|
+
}
|
|
669
|
+
if (isPlainJSObject(value) && value.__init) {
|
|
670
|
+
return cloneInitializer(value, shouldPersistRemote, depth);
|
|
671
|
+
}
|
|
672
|
+
if (isPlainJSObject(value) && value.__workletContextObjectFactory) {
|
|
673
|
+
return cloneContextObject(value);
|
|
674
|
+
}
|
|
675
|
+
if ((isPlainJSObject(value) || isFunction) && isWorkletFunction(value)) {
|
|
676
|
+
return cloneWorklet(value, shouldPersistRemote, depth);
|
|
677
|
+
}
|
|
678
|
+
if (isSynchronizable(value)) {
|
|
679
|
+
return cloneSynchronizable(value);
|
|
680
|
+
}
|
|
681
|
+
if (isPlainJSObject(value) || isFunction) {
|
|
682
|
+
return clonePlainJSObject(value, shouldPersistRemote, depth);
|
|
683
|
+
}
|
|
684
|
+
if (value instanceof Set) {
|
|
685
|
+
return cloneSet(value);
|
|
686
|
+
}
|
|
687
|
+
if (value instanceof Map) {
|
|
688
|
+
return cloneMap(value);
|
|
689
|
+
}
|
|
690
|
+
if (value instanceof RegExp) {
|
|
691
|
+
return cloneRegExp(value);
|
|
692
|
+
}
|
|
693
|
+
if (value instanceof Error) {
|
|
694
|
+
return cloneError(value);
|
|
695
|
+
}
|
|
696
|
+
if (value instanceof ArrayBuffer) {
|
|
697
|
+
return cloneArrayBuffer(value, shouldPersistRemote);
|
|
698
|
+
}
|
|
699
|
+
if (ArrayBuffer.isView(value)) {
|
|
700
|
+
return cloneArrayBufferView(value);
|
|
701
|
+
}
|
|
702
|
+
return inaccessibleObject(value);
|
|
703
|
+
}
|
|
704
|
+
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
705
|
+
createSerializableNative.__bundleData = {
|
|
706
|
+
imported: "createSerializable",
|
|
707
|
+
// @ts-expect-error resolveWeak is defined by Metro
|
|
708
|
+
source: __require.resolveWeak("./index")
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
var createSerializable = SHOULD_BE_USE_WEB2 ? createSerializableWeb : createSerializableNative;
|
|
712
|
+
function detectCyclicObject(value, depth) {
|
|
713
|
+
if (depth >= DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {
|
|
714
|
+
if (depth === DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {
|
|
715
|
+
processedObjectAtThresholdDepth = value;
|
|
716
|
+
} else if (value === processedObjectAtThresholdDepth) {
|
|
717
|
+
throw new WorkletsError("Trying to convert a cyclic object to a serializable. This is not supported.");
|
|
718
|
+
}
|
|
719
|
+
} else {
|
|
720
|
+
processedObjectAtThresholdDepth = void 0;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
function clonePrimitive(value, shouldPersistRemote) {
|
|
724
|
+
return WorkletsModule.createSerializable(value, shouldPersistRemote);
|
|
725
|
+
}
|
|
726
|
+
function cloneString(value) {
|
|
727
|
+
return WorkletsModule.createSerializableString(value);
|
|
728
|
+
}
|
|
729
|
+
function cloneNumber(value) {
|
|
730
|
+
return WorkletsModule.createSerializableNumber(value);
|
|
731
|
+
}
|
|
732
|
+
function cloneBoolean(value) {
|
|
733
|
+
return WorkletsModule.createSerializableBoolean(value);
|
|
734
|
+
}
|
|
735
|
+
function cloneBigInt(value) {
|
|
736
|
+
return WorkletsModule.createSerializableBigInt(value);
|
|
737
|
+
}
|
|
738
|
+
function cloneUndefined() {
|
|
739
|
+
return WorkletsModule.createSerializableUndefined();
|
|
740
|
+
}
|
|
741
|
+
function cloneNull() {
|
|
742
|
+
return WorkletsModule.createSerializableNull();
|
|
743
|
+
}
|
|
744
|
+
function cloneObjectProperties(value, shouldPersistRemote, depth) {
|
|
745
|
+
const clonedProps = {};
|
|
746
|
+
for (const [key, element] of Object.entries(value)) {
|
|
747
|
+
if (key === "__initData" && clonedProps.__initData !== void 0) {
|
|
748
|
+
continue;
|
|
749
|
+
}
|
|
750
|
+
clonedProps[key] = createSerializable(element, shouldPersistRemote, depth + 1);
|
|
751
|
+
}
|
|
752
|
+
return clonedProps;
|
|
753
|
+
}
|
|
754
|
+
function cloneInitializer(value, shouldPersistRemote = false, depth = 0) {
|
|
755
|
+
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
|
|
756
|
+
return WorkletsModule.createSerializableInitializer(clonedProps);
|
|
757
|
+
}
|
|
758
|
+
function cloneArray(value, shouldPersistRemote, depth) {
|
|
759
|
+
const clonedElements = value.map((element) => createSerializable(element, shouldPersistRemote, depth + 1));
|
|
760
|
+
const clone = WorkletsModule.createSerializableArray(clonedElements, shouldPersistRemote);
|
|
761
|
+
serializableMappingCache.set(value, clone);
|
|
762
|
+
serializableMappingCache.set(clone);
|
|
763
|
+
freezeObjectInDev(value);
|
|
764
|
+
return clone;
|
|
765
|
+
}
|
|
766
|
+
function cloneRemoteFunction(value) {
|
|
767
|
+
const clone = WorkletsModule.createSerializableFunction(value);
|
|
768
|
+
serializableMappingCache.set(value, clone);
|
|
769
|
+
serializableMappingCache.set(clone);
|
|
770
|
+
freezeObjectInDev(value);
|
|
771
|
+
return clone;
|
|
772
|
+
}
|
|
773
|
+
function cloneHostObject(value) {
|
|
774
|
+
const clone = WorkletsModule.createSerializableHostObject(value);
|
|
775
|
+
serializableMappingCache.set(value, clone);
|
|
776
|
+
serializableMappingCache.set(clone);
|
|
777
|
+
return clone;
|
|
778
|
+
}
|
|
779
|
+
function cloneWorklet(value, shouldPersistRemote, depth) {
|
|
780
|
+
if (__DEV__) {
|
|
781
|
+
const babelVersion = value.__pluginVersion;
|
|
782
|
+
if (babelVersion !== void 0 && babelVersion !== jsVersion) {
|
|
783
|
+
throw new WorkletsError(`Mismatch between JavaScript code version and Worklets Babel plugin version (${jsVersion} vs. ${babelVersion}).
|
|
784
|
+
See \`https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#mismatch-between-javascript-code-version-and-worklets-babel-plugin-version\` for more details.
|
|
785
|
+
Offending code was: \`${getWorkletCode(value)}\``);
|
|
786
|
+
}
|
|
787
|
+
registerWorkletStackDetails(value.__workletHash, value.__stackDetails);
|
|
788
|
+
}
|
|
789
|
+
if (value.__stackDetails) {
|
|
790
|
+
delete value.__stackDetails;
|
|
791
|
+
}
|
|
792
|
+
const clonedProps = cloneObjectProperties(value, true, depth);
|
|
793
|
+
clonedProps.__initData = createSerializable(value.__initData, true, depth + 1);
|
|
794
|
+
const clone = WorkletsModule.createSerializableWorklet(
|
|
795
|
+
clonedProps,
|
|
796
|
+
// TODO: Check after refactor if we can remove shouldPersistRemote parameter (imho it's redundant here since worklets are always persistent)
|
|
797
|
+
// retain all worklets
|
|
798
|
+
true
|
|
799
|
+
);
|
|
800
|
+
serializableMappingCache.set(value, clone);
|
|
801
|
+
serializableMappingCache.set(clone);
|
|
802
|
+
freezeObjectInDev(value);
|
|
803
|
+
return clone;
|
|
804
|
+
}
|
|
805
|
+
function cloneTurboModuleLike(value, shouldPersistRemote, depth) {
|
|
806
|
+
const proto = Object.getPrototypeOf(value);
|
|
807
|
+
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
|
|
808
|
+
const clone = WorkletsModule.createSerializableTurboModuleLike(clonedProps, proto);
|
|
809
|
+
return clone;
|
|
810
|
+
}
|
|
811
|
+
function cloneContextObject(value) {
|
|
812
|
+
const workletContextObjectFactory = value.__workletContextObjectFactory;
|
|
813
|
+
const handle = cloneInitializer({
|
|
814
|
+
__init: () => {
|
|
815
|
+
"worklet";
|
|
816
|
+
return workletContextObjectFactory();
|
|
817
|
+
}
|
|
818
|
+
});
|
|
819
|
+
serializableMappingCache.set(value, handle);
|
|
820
|
+
return handle;
|
|
821
|
+
}
|
|
822
|
+
function clonePlainJSObject(value, shouldPersistRemote, depth) {
|
|
823
|
+
const clonedProps = cloneObjectProperties(value, shouldPersistRemote, depth);
|
|
824
|
+
const clone = WorkletsModule.createSerializableObject(clonedProps, shouldPersistRemote, value);
|
|
825
|
+
serializableMappingCache.set(value, clone);
|
|
826
|
+
serializableMappingCache.set(clone);
|
|
827
|
+
freezeObjectInDev(value);
|
|
828
|
+
return clone;
|
|
829
|
+
}
|
|
830
|
+
function cloneMap(value) {
|
|
831
|
+
const clonedKeys = [];
|
|
832
|
+
const clonedValues = [];
|
|
833
|
+
for (const [key, element] of value.entries()) {
|
|
834
|
+
clonedKeys.push(createSerializable(key));
|
|
835
|
+
clonedValues.push(createSerializable(element));
|
|
836
|
+
}
|
|
837
|
+
const clone = WorkletsModule.createSerializableMap(clonedKeys, clonedValues);
|
|
838
|
+
serializableMappingCache.set(value, clone);
|
|
839
|
+
serializableMappingCache.set(clone);
|
|
840
|
+
freezeObjectInDev(value);
|
|
841
|
+
return clone;
|
|
842
|
+
}
|
|
843
|
+
function cloneSet(value) {
|
|
844
|
+
const clonedElements = [];
|
|
845
|
+
for (const element of value) {
|
|
846
|
+
clonedElements.push(createSerializable(element));
|
|
847
|
+
}
|
|
848
|
+
const clone = WorkletsModule.createSerializableSet(clonedElements);
|
|
849
|
+
serializableMappingCache.set(value, clone);
|
|
850
|
+
serializableMappingCache.set(clone);
|
|
851
|
+
freezeObjectInDev(value);
|
|
852
|
+
return clone;
|
|
853
|
+
}
|
|
854
|
+
function cloneRegExp(value) {
|
|
855
|
+
const pattern = value.source;
|
|
856
|
+
const flags = value.flags;
|
|
857
|
+
const handle = cloneInitializer({
|
|
858
|
+
__init: () => {
|
|
859
|
+
"worklet";
|
|
860
|
+
return new RegExp(pattern, flags);
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
serializableMappingCache.set(value, handle);
|
|
864
|
+
return handle;
|
|
865
|
+
}
|
|
866
|
+
function cloneError(value) {
|
|
867
|
+
const {
|
|
868
|
+
name,
|
|
869
|
+
message,
|
|
870
|
+
stack
|
|
871
|
+
} = value;
|
|
872
|
+
const handle = cloneInitializer({
|
|
873
|
+
__init: () => {
|
|
874
|
+
"worklet";
|
|
875
|
+
const error = new Error();
|
|
876
|
+
error.name = name;
|
|
877
|
+
error.message = message;
|
|
878
|
+
error.stack = stack;
|
|
879
|
+
return error;
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
serializableMappingCache.set(value, handle);
|
|
883
|
+
return handle;
|
|
884
|
+
}
|
|
885
|
+
function cloneArrayBuffer(value, shouldPersistRemote) {
|
|
886
|
+
const clone = WorkletsModule.createSerializable(value, shouldPersistRemote, value);
|
|
887
|
+
serializableMappingCache.set(value, clone);
|
|
888
|
+
serializableMappingCache.set(clone);
|
|
889
|
+
return clone;
|
|
890
|
+
}
|
|
891
|
+
function cloneArrayBufferView(value) {
|
|
892
|
+
const buffer = value.buffer;
|
|
893
|
+
const typeName = value.constructor.name;
|
|
894
|
+
const handle = cloneInitializer({
|
|
895
|
+
__init: () => {
|
|
896
|
+
"worklet";
|
|
897
|
+
if (!VALID_ARRAY_VIEWS_NAMES.includes(typeName)) {
|
|
898
|
+
throw new WorkletsError(`Invalid array view name \`${typeName}\`.`);
|
|
899
|
+
}
|
|
900
|
+
const constructor = global[typeName];
|
|
901
|
+
if (constructor === void 0) {
|
|
902
|
+
throw new WorkletsError(`Constructor for \`${typeName}\` not found.`);
|
|
903
|
+
}
|
|
904
|
+
return new constructor(buffer);
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
serializableMappingCache.set(value, handle);
|
|
908
|
+
return handle;
|
|
909
|
+
}
|
|
910
|
+
function cloneSynchronizable(value) {
|
|
911
|
+
serializableMappingCache.set(value);
|
|
912
|
+
return value;
|
|
913
|
+
}
|
|
914
|
+
function cloneImport(value) {
|
|
915
|
+
const {
|
|
916
|
+
source,
|
|
917
|
+
imported
|
|
918
|
+
} = value.__bundleData;
|
|
919
|
+
const clone = WorkletsModule.createSerializableImport(source, imported);
|
|
920
|
+
serializableMappingCache.set(value, clone);
|
|
921
|
+
serializableMappingCache.set(clone);
|
|
922
|
+
return clone;
|
|
923
|
+
}
|
|
924
|
+
function inaccessibleObject(value) {
|
|
925
|
+
const clone = createSerializable(INACCESSIBLE_OBJECT);
|
|
926
|
+
serializableMappingCache.set(value, clone);
|
|
927
|
+
return clone;
|
|
928
|
+
}
|
|
929
|
+
var WORKLET_CODE_THRESHOLD = 255;
|
|
930
|
+
function getWorkletCode(value) {
|
|
931
|
+
const code = value?.__initData?.code;
|
|
932
|
+
if (!code) {
|
|
933
|
+
return "unknown";
|
|
934
|
+
}
|
|
935
|
+
if (code.length > WORKLET_CODE_THRESHOLD) {
|
|
936
|
+
return `${code.substring(0, WORKLET_CODE_THRESHOLD)}...`;
|
|
937
|
+
}
|
|
938
|
+
return code;
|
|
939
|
+
}
|
|
940
|
+
function isRemoteFunction(value) {
|
|
941
|
+
"worklet";
|
|
942
|
+
return !!value.__remoteFunction;
|
|
943
|
+
}
|
|
944
|
+
function freezeObjectInDev(value) {
|
|
945
|
+
if (!__DEV__) {
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
Object.entries(value).forEach(([key, element]) => {
|
|
949
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
950
|
+
if (!descriptor.configurable) {
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
Object.defineProperty(value, key, {
|
|
954
|
+
get() {
|
|
955
|
+
return element;
|
|
956
|
+
},
|
|
957
|
+
set() {
|
|
958
|
+
logger.warn(`Tried to modify key \`${key}\` of an object which has been already passed to a worklet. See
|
|
959
|
+
https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-modify-key-of-an-object-which-has-been-converted-to-a-serializable
|
|
960
|
+
for more details.`);
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
});
|
|
964
|
+
Object.preventExtensions(value);
|
|
965
|
+
}
|
|
966
|
+
function makeShareableCloneOnUIRecursiveLEGACY(value) {
|
|
967
|
+
"worklet";
|
|
968
|
+
if (SHOULD_BE_USE_WEB2) {
|
|
969
|
+
return value;
|
|
970
|
+
}
|
|
971
|
+
function cloneRecursive(value2) {
|
|
972
|
+
if (typeof value2 === "object" && value2 !== null || typeof value2 === "function") {
|
|
973
|
+
if (isHostObject(value2)) {
|
|
974
|
+
return global._createSerializableHostObject(value2);
|
|
975
|
+
}
|
|
976
|
+
if (isRemoteFunction(value2)) {
|
|
977
|
+
return value2.__remoteFunction;
|
|
978
|
+
}
|
|
979
|
+
if (Array.isArray(value2)) {
|
|
980
|
+
return global._createSerializableArray(value2.map(cloneRecursive));
|
|
981
|
+
}
|
|
982
|
+
if (value2.__synchronizableRef) {
|
|
983
|
+
return global._createSerializableSynchronizable(value2);
|
|
984
|
+
}
|
|
985
|
+
const toAdapt = {};
|
|
986
|
+
for (const [key, element] of Object.entries(value2)) {
|
|
987
|
+
toAdapt[key] = cloneRecursive(element);
|
|
988
|
+
}
|
|
989
|
+
return global._createSerializable(toAdapt, value2);
|
|
990
|
+
}
|
|
991
|
+
if (typeof value2 === "string") {
|
|
992
|
+
return global._createSerializableString(value2);
|
|
993
|
+
}
|
|
994
|
+
if (typeof value2 === "number") {
|
|
995
|
+
return global._createSerializableNumber(value2);
|
|
996
|
+
}
|
|
997
|
+
if (typeof value2 === "boolean") {
|
|
998
|
+
return global._createSerializableBoolean(value2);
|
|
999
|
+
}
|
|
1000
|
+
if (typeof value2 === "bigint") {
|
|
1001
|
+
return global._createSerializableBigInt(value2);
|
|
1002
|
+
}
|
|
1003
|
+
if (value2 === void 0) {
|
|
1004
|
+
return global._createSerializableUndefined();
|
|
1005
|
+
}
|
|
1006
|
+
if (value2 === null) {
|
|
1007
|
+
return global._createSerializableNull();
|
|
1008
|
+
}
|
|
1009
|
+
return global._createSerializable(value2, void 0);
|
|
1010
|
+
}
|
|
1011
|
+
return cloneRecursive(value);
|
|
1012
|
+
}
|
|
1013
|
+
var makeShareableCloneOnUIRecursive = globalThis._WORKLETS_BUNDLE_MODE ? createSerializable : makeShareableCloneOnUIRecursiveLEGACY;
|
|
1014
|
+
|
|
1015
|
+
// ../../node_modules/react-native-worklets/lib/module/threads.js
|
|
1016
|
+
var runOnUIQueue = [];
|
|
1017
|
+
function setupMicrotasks() {
|
|
1018
|
+
"worklet";
|
|
1019
|
+
let microtasksQueue = [];
|
|
1020
|
+
let isExecutingMicrotasksQueue = false;
|
|
1021
|
+
global.queueMicrotask = (callback) => {
|
|
1022
|
+
microtasksQueue.push(callback);
|
|
1023
|
+
};
|
|
1024
|
+
global._microtaskQueueFinalizers = [];
|
|
1025
|
+
global.__callMicrotasks = () => {
|
|
1026
|
+
if (isExecutingMicrotasksQueue) {
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1029
|
+
try {
|
|
1030
|
+
isExecutingMicrotasksQueue = true;
|
|
1031
|
+
for (let index = 0; index < microtasksQueue.length; index += 1) {
|
|
1032
|
+
microtasksQueue[index]();
|
|
1033
|
+
}
|
|
1034
|
+
microtasksQueue = [];
|
|
1035
|
+
global._microtaskQueueFinalizers.forEach((finalizer) => finalizer());
|
|
1036
|
+
} finally {
|
|
1037
|
+
isExecutingMicrotasksQueue = false;
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
function callMicrotasksOnUIThread() {
|
|
1042
|
+
"worklet";
|
|
1043
|
+
global.__callMicrotasks();
|
|
1044
|
+
}
|
|
1045
|
+
var callMicrotasks = SHOULD_BE_USE_WEB2 ? () => {
|
|
1046
|
+
} : callMicrotasksOnUIThread;
|
|
1047
|
+
function runOnUI(worklet) {
|
|
1048
|
+
if (__DEV__ && !SHOULD_BE_USE_WEB2 && !isWorkletFunction(worklet) && !worklet.__bundleData) {
|
|
1049
|
+
throw new WorkletsError("`runOnUI` can only be used with worklets.");
|
|
1050
|
+
}
|
|
1051
|
+
return (...args) => {
|
|
1052
|
+
if (IS_JEST2) {
|
|
1053
|
+
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
|
1054
|
+
"worklet";
|
|
1055
|
+
worklet(...args);
|
|
1056
|
+
}));
|
|
1057
|
+
return;
|
|
1058
|
+
}
|
|
1059
|
+
if (__DEV__) {
|
|
1060
|
+
createSerializable(worklet);
|
|
1061
|
+
createSerializable(args);
|
|
1062
|
+
}
|
|
1063
|
+
enqueueUI(worklet, args);
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
if (__DEV__) {
|
|
1067
|
+
let runOnUIWorklet = function() {
|
|
1068
|
+
"worklet";
|
|
1069
|
+
throw new WorkletsError("`runOnUI` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.");
|
|
1070
|
+
};
|
|
1071
|
+
const serializableRunOnUIWorklet = createSerializable(runOnUIWorklet);
|
|
1072
|
+
serializableMappingCache.set(runOnUI, serializableRunOnUIWorklet);
|
|
1073
|
+
}
|
|
1074
|
+
function executeOnUIRuntimeSync(worklet) {
|
|
1075
|
+
return (...args) => {
|
|
1076
|
+
return WorkletsModule.executeOnUIRuntimeSync(createSerializable(() => {
|
|
1077
|
+
"worklet";
|
|
1078
|
+
const result = worklet(...args);
|
|
1079
|
+
return makeShareableCloneOnUIRecursive(result);
|
|
1080
|
+
}));
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
function runWorkletOnJS(worklet, ...args) {
|
|
1084
|
+
worklet(...args);
|
|
1085
|
+
}
|
|
1086
|
+
function runOnJS(fun) {
|
|
1087
|
+
"worklet";
|
|
1088
|
+
if (SHOULD_BE_USE_WEB2 || globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
|
1089
|
+
return (...args) => queueMicrotask(args.length ? () => fun(...args) : fun);
|
|
1090
|
+
}
|
|
1091
|
+
if (isWorkletFunction(fun)) {
|
|
1092
|
+
return (...args) => runOnJS(runWorkletOnJS)(fun, ...args);
|
|
1093
|
+
}
|
|
1094
|
+
if (fun.__remoteFunction) {
|
|
1095
|
+
fun = fun.__remoteFunction;
|
|
1096
|
+
}
|
|
1097
|
+
const scheduleOnJS = typeof fun === "function" ? global._scheduleHostFunctionOnJS : global._scheduleRemoteFunctionOnJS;
|
|
1098
|
+
return (...args) => {
|
|
1099
|
+
scheduleOnJS(fun, args.length > 0 ? makeShareableCloneOnUIRecursive(args) : void 0);
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
function runOnUIAsync(worklet) {
|
|
1103
|
+
if (__DEV__ && !SHOULD_BE_USE_WEB2 && !isWorkletFunction(worklet)) {
|
|
1104
|
+
throw new WorkletsError("`runOnUIAsync` can only be used with worklets.");
|
|
1105
|
+
}
|
|
1106
|
+
return (...args) => {
|
|
1107
|
+
return new Promise((resolve) => {
|
|
1108
|
+
if (IS_JEST2) {
|
|
1109
|
+
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
|
1110
|
+
"worklet";
|
|
1111
|
+
worklet(...args);
|
|
1112
|
+
}));
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
if (__DEV__) {
|
|
1116
|
+
createSerializable(worklet);
|
|
1117
|
+
createSerializable(args);
|
|
1118
|
+
}
|
|
1119
|
+
enqueueUI(worklet, args, resolve);
|
|
1120
|
+
});
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1123
|
+
if (__DEV__) {
|
|
1124
|
+
let runOnUIAsyncWorklet = function() {
|
|
1125
|
+
"worklet";
|
|
1126
|
+
throw new WorkletsError("`runOnUIAsync` cannot be called on the UI runtime. Please call the function synchronously or use `queueMicrotask` or `requestAnimationFrame` instead.");
|
|
1127
|
+
};
|
|
1128
|
+
const serializableRunOnUIAsyncWorklet = createSerializable(runOnUIAsyncWorklet);
|
|
1129
|
+
serializableMappingCache.set(runOnUIAsync, serializableRunOnUIAsyncWorklet);
|
|
1130
|
+
}
|
|
1131
|
+
function enqueueUI(worklet, args, resolve) {
|
|
1132
|
+
const job = [worklet, args, resolve];
|
|
1133
|
+
runOnUIQueue.push(job);
|
|
1134
|
+
if (runOnUIQueue.length === 1) {
|
|
1135
|
+
flushUIQueue();
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
function flushUIQueue() {
|
|
1139
|
+
queueMicrotask(() => {
|
|
1140
|
+
const queue = runOnUIQueue;
|
|
1141
|
+
runOnUIQueue = [];
|
|
1142
|
+
WorkletsModule.scheduleOnUI(createSerializable(() => {
|
|
1143
|
+
"worklet";
|
|
1144
|
+
queue.forEach(([workletFunction, workletArgs, jobResolve]) => {
|
|
1145
|
+
const result = workletFunction(...workletArgs);
|
|
1146
|
+
if (jobResolve) {
|
|
1147
|
+
runOnJS(jobResolve)(result);
|
|
1148
|
+
}
|
|
1149
|
+
});
|
|
1150
|
+
callMicrotasks();
|
|
1151
|
+
}));
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/requestAnimationFrame.js
|
|
1156
|
+
function setupRequestAnimationFrame() {
|
|
1157
|
+
"worklet";
|
|
1158
|
+
const nativeRequestAnimationFrame = globalThis.requestAnimationFrame;
|
|
1159
|
+
let queuedCallbacks = [];
|
|
1160
|
+
let queuedCallbacksBegin = 0;
|
|
1161
|
+
let queuedCallbacksEnd = 0;
|
|
1162
|
+
let flushedCallbacks = queuedCallbacks;
|
|
1163
|
+
let flushedCallbacksBegin = 0;
|
|
1164
|
+
let flushedCallbacksEnd = 0;
|
|
1165
|
+
let flushRequested = false;
|
|
1166
|
+
globalThis.__flushAnimationFrame = (timestamp) => {
|
|
1167
|
+
flushedCallbacks = queuedCallbacks;
|
|
1168
|
+
queuedCallbacks = [];
|
|
1169
|
+
flushedCallbacksBegin = queuedCallbacksBegin;
|
|
1170
|
+
flushedCallbacksEnd = queuedCallbacksEnd;
|
|
1171
|
+
queuedCallbacksBegin = queuedCallbacksEnd;
|
|
1172
|
+
for (const callback of flushedCallbacks) {
|
|
1173
|
+
callback(timestamp);
|
|
1174
|
+
}
|
|
1175
|
+
flushedCallbacksBegin = flushedCallbacksEnd;
|
|
1176
|
+
callMicrotasks();
|
|
1177
|
+
};
|
|
1178
|
+
globalThis.requestAnimationFrame = (callback) => {
|
|
1179
|
+
const handle = queuedCallbacksEnd++;
|
|
1180
|
+
queuedCallbacks.push(callback);
|
|
1181
|
+
if (!flushRequested) {
|
|
1182
|
+
flushRequested = true;
|
|
1183
|
+
nativeRequestAnimationFrame((timestamp) => {
|
|
1184
|
+
flushRequested = false;
|
|
1185
|
+
globalThis.__frameTimestamp = timestamp;
|
|
1186
|
+
globalThis.__flushAnimationFrame(timestamp);
|
|
1187
|
+
globalThis.__frameTimestamp = void 0;
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
return handle;
|
|
1191
|
+
};
|
|
1192
|
+
globalThis.cancelAnimationFrame = (handle) => {
|
|
1193
|
+
if (handle < flushedCallbacksBegin || handle >= queuedCallbacksEnd) {
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
if (handle < flushedCallbacksEnd) {
|
|
1197
|
+
flushedCallbacks[handle - flushedCallbacksBegin] = () => {
|
|
1198
|
+
};
|
|
1199
|
+
} else {
|
|
1200
|
+
queuedCallbacks[handle - queuedCallbacksBegin] = () => {
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
// ../../node_modules/react-native-worklets/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js
|
|
1207
|
+
function setupSetTimeout() {
|
|
1208
|
+
"worklet";
|
|
1209
|
+
const timeoutHandleToRafHandle = /* @__PURE__ */ new Map();
|
|
1210
|
+
const setTimeoutPolyfill = (callback, delay = 0, ...args) => {
|
|
1211
|
+
const start = performance.now();
|
|
1212
|
+
let timeoutHandle = 0;
|
|
1213
|
+
const rafCallback = () => {
|
|
1214
|
+
const now = performance.now();
|
|
1215
|
+
if (now - start >= delay) {
|
|
1216
|
+
callback(...args);
|
|
1217
|
+
timeoutHandleToRafHandle.delete(timeoutHandle);
|
|
1218
|
+
} else {
|
|
1219
|
+
const rafHandle = requestAnimationFrame(rafCallback);
|
|
1220
|
+
timeoutHandleToRafHandle.set(timeoutHandle, rafHandle);
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
timeoutHandle = requestAnimationFrame(rafCallback);
|
|
1224
|
+
timeoutHandleToRafHandle.set(timeoutHandle, timeoutHandle);
|
|
1225
|
+
return timeoutHandle;
|
|
1226
|
+
};
|
|
1227
|
+
const clearTimeoutPolyfill = (timeoutHandle) => {
|
|
1228
|
+
const rafHandle = timeoutHandleToRafHandle.get(timeoutHandle);
|
|
1229
|
+
timeoutHandleToRafHandle.delete(timeoutHandle);
|
|
1230
|
+
cancelAnimationFrame(rafHandle);
|
|
1231
|
+
};
|
|
1232
|
+
globalThis.setTimeout = setTimeoutPolyfill;
|
|
1233
|
+
globalThis.clearTimeout = clearTimeoutPolyfill;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
// ../../node_modules/react-native-worklets/lib/module/synchronizableUnpacker.js
|
|
1237
|
+
function __installUnpacker() {
|
|
1238
|
+
const serializer = !globalThis._WORKLET || globalThis._WORKLETS_BUNDLE_MODE ? (value, _) => createSerializable(value) : globalThis._createSerializable;
|
|
1239
|
+
function synchronizableUnpacker(synchronizableRef) {
|
|
1240
|
+
const synchronizable = synchronizableRef;
|
|
1241
|
+
const proxy = globalThis.__workletsModuleProxy;
|
|
1242
|
+
synchronizable.__synchronizableRef = true;
|
|
1243
|
+
synchronizable.getDirty = () => {
|
|
1244
|
+
return proxy.synchronizableGetDirty(synchronizable);
|
|
1245
|
+
};
|
|
1246
|
+
synchronizable.getBlocking = () => {
|
|
1247
|
+
return proxy.synchronizableGetBlocking(synchronizable);
|
|
1248
|
+
};
|
|
1249
|
+
synchronizable.setBlocking = (valueOrFunction) => {
|
|
1250
|
+
let newValue;
|
|
1251
|
+
if (typeof valueOrFunction === "function") {
|
|
1252
|
+
const func = valueOrFunction;
|
|
1253
|
+
synchronizable.lock();
|
|
1254
|
+
const prev = synchronizable.getBlocking();
|
|
1255
|
+
newValue = func(prev);
|
|
1256
|
+
proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, void 0));
|
|
1257
|
+
synchronizable.unlock();
|
|
1258
|
+
} else {
|
|
1259
|
+
const value = valueOrFunction;
|
|
1260
|
+
newValue = value;
|
|
1261
|
+
proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, void 0));
|
|
1262
|
+
}
|
|
1263
|
+
};
|
|
1264
|
+
synchronizable.lock = () => {
|
|
1265
|
+
proxy.synchronizableLock(synchronizable);
|
|
1266
|
+
};
|
|
1267
|
+
synchronizable.unlock = () => {
|
|
1268
|
+
proxy.synchronizableUnlock(synchronizable);
|
|
1269
|
+
};
|
|
1270
|
+
return synchronizable;
|
|
1271
|
+
}
|
|
1272
|
+
globalThis.__synchronizableUnpacker = synchronizableUnpacker;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
// ../../node_modules/react-native-worklets/lib/module/initializers.js
|
|
1276
|
+
var capturableConsole;
|
|
1277
|
+
function getMemorySafeCapturableConsole() {
|
|
1278
|
+
if (capturableConsole) {
|
|
1279
|
+
return capturableConsole;
|
|
1280
|
+
}
|
|
1281
|
+
const consoleCopy = Object.fromEntries(Object.entries(console).map(([methodName, method]) => {
|
|
1282
|
+
const methodWrapper = function methodWrapper2(...args) {
|
|
1283
|
+
return method(...args);
|
|
1284
|
+
};
|
|
1285
|
+
if (method.name) {
|
|
1286
|
+
Object.defineProperty(methodWrapper, "name", {
|
|
1287
|
+
value: method.name,
|
|
1288
|
+
writable: false
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
return [methodName, methodWrapper];
|
|
1292
|
+
}));
|
|
1293
|
+
capturableConsole = consoleCopy;
|
|
1294
|
+
return consoleCopy;
|
|
1295
|
+
}
|
|
1296
|
+
function setupConsole(boundCapturableConsole) {
|
|
1297
|
+
"worklet";
|
|
1298
|
+
globalThis.console = {
|
|
1299
|
+
assert: runOnJS(boundCapturableConsole.assert),
|
|
1300
|
+
debug: runOnJS(boundCapturableConsole.debug),
|
|
1301
|
+
log: runOnJS(boundCapturableConsole.log),
|
|
1302
|
+
warn: runOnJS(boundCapturableConsole.warn),
|
|
1303
|
+
error: runOnJS(boundCapturableConsole.error),
|
|
1304
|
+
info: runOnJS(boundCapturableConsole.info)
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
var initialized = false;
|
|
1308
|
+
function init() {
|
|
1309
|
+
if (initialized) {
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1312
|
+
initialized = true;
|
|
1313
|
+
if (globalThis.__RUNTIME_KIND === void 0) {
|
|
1314
|
+
globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
|
|
1315
|
+
}
|
|
1316
|
+
initializeRuntime();
|
|
1317
|
+
if (SHOULD_BE_USE_WEB2) {
|
|
1318
|
+
initializeRuntimeOnWeb();
|
|
1319
|
+
}
|
|
1320
|
+
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
|
|
1321
|
+
initializeWorkletRuntime();
|
|
1322
|
+
} else {
|
|
1323
|
+
initializeRNRuntime();
|
|
1324
|
+
if (!SHOULD_BE_USE_WEB2) {
|
|
1325
|
+
installRNBindingsOnUIRuntime();
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
function initializeRuntime() {
|
|
1330
|
+
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
1331
|
+
globalThis.__valueUnpacker = bundleValueUnpacker;
|
|
1332
|
+
}
|
|
1333
|
+
__installUnpacker();
|
|
1334
|
+
}
|
|
1335
|
+
function initializeRNRuntime() {
|
|
1336
|
+
if (__DEV__) {
|
|
1337
|
+
const testWorklet = () => {
|
|
1338
|
+
"worklet";
|
|
1339
|
+
};
|
|
1340
|
+
if (!isWorkletFunction(testWorklet)) {
|
|
1341
|
+
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.`);
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
registerReportFatalRemoteError();
|
|
1345
|
+
}
|
|
1346
|
+
function initializeWorkletRuntime() {
|
|
1347
|
+
if (globalThis._WORKLETS_BUNDLE_MODE) {
|
|
1348
|
+
setupCallGuard();
|
|
1349
|
+
if (__DEV__) {
|
|
1350
|
+
const Refresh = new Proxy({}, {
|
|
1351
|
+
get() {
|
|
1352
|
+
return () => {
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1355
|
+
});
|
|
1356
|
+
globalThis.__r.Refresh = Refresh;
|
|
1357
|
+
const modules = __require.getModules();
|
|
1358
|
+
const ReactNativeModuleId = __require.resolveWeak("react-native");
|
|
1359
|
+
const factory = function(_global, _require, _importDefault, _importAll, module, _exports, _dependencyMap) {
|
|
1360
|
+
module.exports = new Proxy({}, {
|
|
1361
|
+
get: function get(_target, prop) {
|
|
1362
|
+
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.`);
|
|
1363
|
+
return {
|
|
1364
|
+
get() {
|
|
1365
|
+
return void 0;
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
}
|
|
1369
|
+
});
|
|
1370
|
+
};
|
|
1371
|
+
const mod = {
|
|
1372
|
+
dependencyMap: [],
|
|
1373
|
+
factory,
|
|
1374
|
+
hasError: false,
|
|
1375
|
+
importedAll: {},
|
|
1376
|
+
importedDefault: {},
|
|
1377
|
+
isInitialized: false,
|
|
1378
|
+
publicModule: {
|
|
1379
|
+
exports: {}
|
|
1380
|
+
}
|
|
1381
|
+
};
|
|
1382
|
+
modules.set(ReactNativeModuleId, mod);
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
function initializeRuntimeOnWeb() {
|
|
1387
|
+
globalThis._WORKLET = false;
|
|
1388
|
+
globalThis._log = console.log;
|
|
1389
|
+
globalThis._getAnimationTimestamp = () => performance.now();
|
|
1390
|
+
if (IS_JEST2) {
|
|
1391
|
+
globalThis.requestAnimationFrame = mockedRequestAnimationFrame;
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
function installRNBindingsOnUIRuntime() {
|
|
1395
|
+
if (!WorkletsModule) {
|
|
1396
|
+
throw new WorkletsError("Worklets are trying to initialize the UI runtime without a valid WorkletsModule");
|
|
1397
|
+
}
|
|
1398
|
+
const runtimeBoundCapturableConsole = getMemorySafeCapturableConsole();
|
|
1399
|
+
if (!globalThis._WORKLETS_BUNDLE_MODE) {
|
|
1400
|
+
executeOnUIRuntimeSync(setupCallGuard)();
|
|
1401
|
+
executeOnUIRuntimeSync(registerWorkletsError)();
|
|
1402
|
+
}
|
|
1403
|
+
executeOnUIRuntimeSync(() => {
|
|
1404
|
+
"worklet";
|
|
1405
|
+
setupConsole(runtimeBoundCapturableConsole);
|
|
1406
|
+
setupMicrotasks();
|
|
1407
|
+
setupRequestAnimationFrame();
|
|
1408
|
+
setupSetTimeout();
|
|
1409
|
+
setupSetImmediate();
|
|
1410
|
+
setupSetInterval();
|
|
1411
|
+
})();
|
|
37
1412
|
}
|
|
38
|
-
|
|
39
|
-
|
|
1413
|
+
|
|
1414
|
+
// ../../node_modules/react-native-worklets/lib/module/workletRuntimeEntry.js
|
|
1415
|
+
function bundleModeInit() {
|
|
1416
|
+
if (SHOULD_BE_USE_WEB2) {
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
globalThis._WORKLETS_BUNDLE_MODE = true;
|
|
1420
|
+
const runtimeKind = globalThis.__RUNTIME_KIND;
|
|
1421
|
+
if (runtimeKind && runtimeKind !== RuntimeKind.ReactNative) {
|
|
1422
|
+
init();
|
|
1423
|
+
throw new WorkletsError("Worklets initialized successfully");
|
|
1424
|
+
}
|
|
40
1425
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
1426
|
+
bundleModeInit();
|
|
1427
|
+
|
|
1428
|
+
// ../../node_modules/react-native-worklets/lib/module/featureFlags/index.js
|
|
1429
|
+
var DynamicFlags = {
|
|
1430
|
+
EXAMPLE_DYNAMIC_FLAG: true,
|
|
1431
|
+
init() {
|
|
1432
|
+
Object.keys(DynamicFlags).forEach((key) => {
|
|
1433
|
+
if (key !== "init" && key !== "setFlag") {
|
|
1434
|
+
WorkletsModule.setDynamicFeatureFlag(key, DynamicFlags[key]);
|
|
1435
|
+
}
|
|
1436
|
+
});
|
|
1437
|
+
},
|
|
1438
|
+
setFlag(name, value) {
|
|
1439
|
+
if (name in DynamicFlags) {
|
|
1440
|
+
DynamicFlags[name] = value;
|
|
1441
|
+
WorkletsModule.setDynamicFeatureFlag(name, value);
|
|
1442
|
+
} else {
|
|
1443
|
+
logger.warn(`The feature flag: '${name}' no longer exists, you can safely remove invocation of \`setDynamicFeatureFlag('${name}')\` from your code.`);
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
};
|
|
1447
|
+
DynamicFlags.init();
|
|
1448
|
+
|
|
1449
|
+
// ../../node_modules/react-native-worklets/lib/module/index.js
|
|
1450
|
+
init();
|
|
1451
|
+
if (globalThis._ALWAYS_FALSE) {
|
|
1452
|
+
bundleModeInit();
|
|
50
1453
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return
|
|
1454
|
+
|
|
1455
|
+
// src/transitions/easing.ts
|
|
1456
|
+
function ensureWorkletEasing(easing) {
|
|
1457
|
+
if (!easing) return void 0;
|
|
1458
|
+
if (isWorkletFunction(easing)) return easing;
|
|
1459
|
+
const wrapped = (t) => {
|
|
1460
|
+
"worklet";
|
|
1461
|
+
return easing(t);
|
|
1462
|
+
};
|
|
1463
|
+
return wrapped;
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
// src/transitions/spring.ts
|
|
1467
|
+
var DEFAULT_SPRING = {
|
|
1468
|
+
tension: 170,
|
|
1469
|
+
friction: 26,
|
|
1470
|
+
mass: 1
|
|
1471
|
+
};
|
|
1472
|
+
function springToReanimated(t) {
|
|
1473
|
+
return {
|
|
1474
|
+
stiffness: t.tension ?? DEFAULT_SPRING.tension,
|
|
1475
|
+
damping: t.friction ?? DEFAULT_SPRING.friction,
|
|
1476
|
+
mass: t.mass ?? DEFAULT_SPRING.mass,
|
|
1477
|
+
velocity: t.velocity,
|
|
1478
|
+
restSpeedThreshold: t.restSpeedThreshold,
|
|
1479
|
+
restDisplacementThreshold: t.restDisplacementThreshold
|
|
1480
|
+
};
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
// src/layout/resolveLayout.ts
|
|
1484
|
+
function resolveLayoutTransition(layout) {
|
|
1485
|
+
if (!layout) return void 0;
|
|
1486
|
+
const cfg = layout === true ? { type: "spring" } : layout;
|
|
1487
|
+
if (cfg.type === "no-animation") return void 0;
|
|
1488
|
+
if (cfg.type === "timing") {
|
|
1489
|
+
let builder2 = LinearTransition.duration(cfg.duration ?? 300);
|
|
1490
|
+
const easing = ensureWorkletEasing(cfg.easing);
|
|
1491
|
+
if (easing) builder2 = builder2.easing(easing);
|
|
1492
|
+
if (cfg.delay) builder2 = builder2.delay(cfg.delay);
|
|
1493
|
+
return builder2;
|
|
1494
|
+
}
|
|
1495
|
+
const spring = cfg.type === "decay" ? { type: "spring" } : cfg;
|
|
1496
|
+
const { stiffness, damping, mass } = springToReanimated({
|
|
1497
|
+
...DEFAULT_SPRING,
|
|
1498
|
+
...spring
|
|
1499
|
+
});
|
|
1500
|
+
let builder = LinearTransition.springify().stiffness(stiffness).damping(damping).mass(mass);
|
|
1501
|
+
if ("delay" in spring && spring.delay) builder = builder.delay(spring.delay);
|
|
1502
|
+
return builder;
|
|
55
1503
|
}
|
|
56
1504
|
var PresenceContext = createContext(null);
|
|
57
1505
|
function usePresence() {
|
|
@@ -148,33 +1596,7 @@ function PresenceItem({
|
|
|
148
1596
|
);
|
|
149
1597
|
return /* @__PURE__ */ jsx(PresenceContext.Provider, { value, children });
|
|
150
1598
|
}
|
|
151
|
-
function ensureWorkletEasing(easing) {
|
|
152
|
-
if (!easing) return void 0;
|
|
153
|
-
if (isWorkletFunction(easing)) return easing;
|
|
154
|
-
const wrapped = (t) => {
|
|
155
|
-
"worklet";
|
|
156
|
-
return easing(t);
|
|
157
|
-
};
|
|
158
|
-
return wrapped;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// src/transitions/resolve.ts
|
|
162
|
-
var DEFAULT_SPRING = {
|
|
163
|
-
tension: 170,
|
|
164
|
-
friction: 26,
|
|
165
|
-
mass: 1
|
|
166
|
-
};
|
|
167
1599
|
var DEFAULT_TIMING_DURATION = 250;
|
|
168
|
-
function springToReanimated(t) {
|
|
169
|
-
return {
|
|
170
|
-
stiffness: t.tension ?? DEFAULT_SPRING.tension,
|
|
171
|
-
damping: t.friction ?? DEFAULT_SPRING.friction,
|
|
172
|
-
mass: t.mass ?? DEFAULT_SPRING.mass,
|
|
173
|
-
velocity: t.velocity,
|
|
174
|
-
restSpeedThreshold: t.restSpeedThreshold,
|
|
175
|
-
restDisplacementThreshold: t.restDisplacementThreshold
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
1600
|
function buildSpring(cfg, toValue, cb) {
|
|
179
1601
|
return withSpring(toValue, springToReanimated(cfg), cb);
|
|
180
1602
|
}
|
|
@@ -279,14 +1701,96 @@ function mergeTransition(base, override) {
|
|
|
279
1701
|
}
|
|
280
1702
|
return { ...base ?? { type: "spring" }, ...override };
|
|
281
1703
|
}
|
|
1704
|
+
|
|
1705
|
+
// src/transitions/keys.ts
|
|
1706
|
+
var TRANSITION_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
1707
|
+
"type",
|
|
1708
|
+
"tension",
|
|
1709
|
+
"friction",
|
|
1710
|
+
"mass",
|
|
1711
|
+
"velocity",
|
|
1712
|
+
"restSpeedThreshold",
|
|
1713
|
+
"restDisplacementThreshold",
|
|
1714
|
+
"duration",
|
|
1715
|
+
"easing",
|
|
1716
|
+
"delay",
|
|
1717
|
+
"repeat",
|
|
1718
|
+
"deceleration",
|
|
1719
|
+
"clamp"
|
|
1720
|
+
]);
|
|
1721
|
+
function isTopLevelTransition(t) {
|
|
1722
|
+
if (t === null || typeof t !== "object") return false;
|
|
1723
|
+
const keys = Object.keys(t);
|
|
1724
|
+
if (keys.length === 0) return false;
|
|
1725
|
+
return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
// src/transitions/sig.ts
|
|
1729
|
+
function stableSig(value) {
|
|
1730
|
+
if (value === void 0) return "";
|
|
1731
|
+
try {
|
|
1732
|
+
return stableStringify(value);
|
|
1733
|
+
} catch {
|
|
1734
|
+
return String(value);
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
function stableStringify(v) {
|
|
1738
|
+
if (v === null || typeof v !== "object") {
|
|
1739
|
+
if (typeof v === "function" || v === void 0) return "null";
|
|
1740
|
+
return JSON.stringify(v);
|
|
1741
|
+
}
|
|
1742
|
+
if (Array.isArray(v)) {
|
|
1743
|
+
return "[" + v.map(stableStringify).join(",") + "]";
|
|
1744
|
+
}
|
|
1745
|
+
const obj = v;
|
|
1746
|
+
const keys = Object.keys(obj).sort();
|
|
1747
|
+
return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
// src/motion/installCheck.ts
|
|
1751
|
+
var alreadyChecked = false;
|
|
1752
|
+
function ensureReanimatedInstalled() {
|
|
1753
|
+
if (!__DEV__ || alreadyChecked) return;
|
|
1754
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV === "test") {
|
|
1755
|
+
return;
|
|
1756
|
+
}
|
|
1757
|
+
alreadyChecked = true;
|
|
1758
|
+
let version;
|
|
1759
|
+
try {
|
|
1760
|
+
const pkg = __require("react-native-reanimated/package.json");
|
|
1761
|
+
version = pkg.version;
|
|
1762
|
+
} catch {
|
|
1763
|
+
}
|
|
1764
|
+
if (version) {
|
|
1765
|
+
const major = parseInt(version.split(".")[0] ?? "0", 10);
|
|
1766
|
+
if (major < 4) {
|
|
1767
|
+
console.error(
|
|
1768
|
+
`[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).`
|
|
1769
|
+
);
|
|
1770
|
+
return;
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
const probe = function probe2() {
|
|
1774
|
+
"worklet";
|
|
1775
|
+
return 0;
|
|
1776
|
+
};
|
|
1777
|
+
if (typeof probe.__workletHash !== "number") {
|
|
1778
|
+
console.error(
|
|
1779
|
+
`[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\`.`
|
|
1780
|
+
);
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
282
1783
|
var TRANSFORM_KEYS = [
|
|
283
1784
|
"translateX",
|
|
284
1785
|
"translateY",
|
|
285
1786
|
"scale",
|
|
286
1787
|
"scaleX",
|
|
287
1788
|
"scaleY",
|
|
288
|
-
"rotate"
|
|
1789
|
+
"rotate",
|
|
1790
|
+
"rotateX",
|
|
1791
|
+
"rotateY"
|
|
289
1792
|
];
|
|
1793
|
+
var ROTATION_KEYS = /* @__PURE__ */ new Set(["rotate", "rotateX", "rotateY"]);
|
|
290
1794
|
var NUMERIC_TOP_LEVEL_KEYS = [
|
|
291
1795
|
"opacity",
|
|
292
1796
|
"width",
|
|
@@ -305,6 +1809,14 @@ var ALL_KEYS = [
|
|
|
305
1809
|
...COLOR_KEYS
|
|
306
1810
|
];
|
|
307
1811
|
var TRANSFORM_KEY_SET = new Set(TRANSFORM_KEYS);
|
|
1812
|
+
var COLOR_KEY_SET = new Set(COLOR_KEYS);
|
|
1813
|
+
var GESTURE_LAYER_NAMES = [
|
|
1814
|
+
"hovered",
|
|
1815
|
+
"focused",
|
|
1816
|
+
"focusVisible",
|
|
1817
|
+
"pressed"
|
|
1818
|
+
];
|
|
1819
|
+
var GESTURE_LAYER_NAME_SET = new Set(GESTURE_LAYER_NAMES);
|
|
308
1820
|
var EXITING_POINTER_EVENTS_STYLE = { pointerEvents: "none" };
|
|
309
1821
|
var DEFAULT_RESTING = {
|
|
310
1822
|
translateX: 0,
|
|
@@ -313,6 +1825,8 @@ var DEFAULT_RESTING = {
|
|
|
313
1825
|
scaleX: 1,
|
|
314
1826
|
scaleY: 1,
|
|
315
1827
|
rotate: 0,
|
|
1828
|
+
rotateX: 0,
|
|
1829
|
+
rotateY: 0,
|
|
316
1830
|
opacity: 1,
|
|
317
1831
|
width: 0,
|
|
318
1832
|
height: 0,
|
|
@@ -326,34 +1840,21 @@ var DEFAULT_RESTING = {
|
|
|
326
1840
|
color: "transparent",
|
|
327
1841
|
tintColor: "transparent"
|
|
328
1842
|
};
|
|
329
|
-
var TRANSITION_KEYS = /* @__PURE__ */ new Set([
|
|
330
|
-
"type",
|
|
331
|
-
"tension",
|
|
332
|
-
"friction",
|
|
333
|
-
"mass",
|
|
334
|
-
"velocity",
|
|
335
|
-
"restSpeedThreshold",
|
|
336
|
-
"restDisplacementThreshold",
|
|
337
|
-
"duration",
|
|
338
|
-
"easing",
|
|
339
|
-
"delay",
|
|
340
|
-
"repeat",
|
|
341
|
-
"deceleration",
|
|
342
|
-
"clamp"
|
|
343
|
-
]);
|
|
344
|
-
function isTopLevelTransition(t) {
|
|
345
|
-
if (t === null || typeof t !== "object") return false;
|
|
346
|
-
const keys = Object.keys(t);
|
|
347
|
-
if (keys.length === 0) return false;
|
|
348
|
-
return keys.every((k) => TRANSITION_KEYS.has(k));
|
|
349
|
-
}
|
|
350
1843
|
function transitionFor(prop, transition) {
|
|
351
1844
|
if (!transition) return void 0;
|
|
352
1845
|
if (isTopLevelTransition(transition)) return transition;
|
|
1846
|
+
if (GESTURE_LAYER_NAME_SET.has(prop)) return void 0;
|
|
353
1847
|
return transition[prop];
|
|
354
1848
|
}
|
|
1849
|
+
function gestureLayerTransitionFor(layer, transition) {
|
|
1850
|
+
if (!transition) return void 0;
|
|
1851
|
+
if (isTopLevelTransition(transition)) return transition;
|
|
1852
|
+
return transition[layer];
|
|
1853
|
+
}
|
|
355
1854
|
function createMotionComponent(Component) {
|
|
1855
|
+
ensureReanimatedInstalled();
|
|
356
1856
|
const AnimatedComponent = Animated.createAnimatedComponent(
|
|
1857
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
357
1858
|
Component
|
|
358
1859
|
);
|
|
359
1860
|
const Motion2 = forwardRef(function Motion3(props, ref) {
|
|
@@ -365,6 +1866,7 @@ function createMotionComponent(Component) {
|
|
|
365
1866
|
variants,
|
|
366
1867
|
controller,
|
|
367
1868
|
gesture,
|
|
1869
|
+
layout,
|
|
368
1870
|
onAnimationEnd,
|
|
369
1871
|
style,
|
|
370
1872
|
...rest
|
|
@@ -432,13 +1934,19 @@ function createMotionComponent(Component) {
|
|
|
432
1934
|
}
|
|
433
1935
|
return initialRecord?.[key] ?? restValue(animateRecord[key]) ?? DEFAULT_RESTING[key];
|
|
434
1936
|
});
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
1937
|
+
const pressedProgress = useSharedValue(0);
|
|
1938
|
+
const focusedProgress = useSharedValue(0);
|
|
1939
|
+
const focusVisibleProgress = useSharedValue(0);
|
|
1940
|
+
const hoveredProgress = useSharedValue(0);
|
|
1941
|
+
const gestureSV = useSharedValue(
|
|
1942
|
+
resolveGestureLayers(gesture)
|
|
1943
|
+
);
|
|
1944
|
+
const gestureTargetsSig = stableSig(gesture);
|
|
1945
|
+
useEffect(() => {
|
|
1946
|
+
gestureSV.value = resolveGestureLayers(gesture);
|
|
1947
|
+
}, [gestureTargetsSig]);
|
|
1948
|
+
const baseRecord = isExiting && exitRecord ? { ...animateRecord, ...exitRecord } : animateRecord;
|
|
1949
|
+
const baseSig = stableSig(baseRecord) + (isExiting ? "|exit" : "") + (shouldReduceMotion ? "|rm" : "");
|
|
442
1950
|
const transitionSig = stableSig(transition);
|
|
443
1951
|
const safeToRemoveRef = useRef(void 0);
|
|
444
1952
|
safeToRemoveRef.current = presence?.safeToRemove;
|
|
@@ -459,13 +1967,13 @@ function createMotionComponent(Component) {
|
|
|
459
1967
|
};
|
|
460
1968
|
let transformPending = 0;
|
|
461
1969
|
for (const k of ALL_KEYS) {
|
|
462
|
-
if (TRANSFORM_KEY_SET.has(k) &&
|
|
1970
|
+
if (TRANSFORM_KEY_SET.has(k) && baseRecord[k] !== void 0) {
|
|
463
1971
|
transformPending++;
|
|
464
1972
|
}
|
|
465
1973
|
}
|
|
466
1974
|
const transformGroup = transformPending > 0 ? { remaining: transformPending } : void 0;
|
|
467
1975
|
for (const key of ALL_KEYS) {
|
|
468
|
-
const target =
|
|
1976
|
+
const target = baseRecord[key];
|
|
469
1977
|
if (target === void 0) continue;
|
|
470
1978
|
const cfg = shouldReduceMotion ? { type: "no-animation" } : transitionFor(key, transition);
|
|
471
1979
|
if (isExiting) pending++;
|
|
@@ -490,17 +1998,79 @@ function createMotionComponent(Component) {
|
|
|
490
1998
|
if (isExiting && pending === 0) {
|
|
491
1999
|
safeToRemoveRef.current?.();
|
|
492
2000
|
}
|
|
493
|
-
}, [
|
|
2001
|
+
}, [baseSig, transitionSig]);
|
|
2002
|
+
useGestureLayerProgress(
|
|
2003
|
+
pressedProgress,
|
|
2004
|
+
pressed,
|
|
2005
|
+
gesture?.pressed != null,
|
|
2006
|
+
"pressed",
|
|
2007
|
+
transition,
|
|
2008
|
+
isExiting,
|
|
2009
|
+
shouldReduceMotion
|
|
2010
|
+
);
|
|
2011
|
+
useGestureLayerProgress(
|
|
2012
|
+
focusedProgress,
|
|
2013
|
+
focused,
|
|
2014
|
+
gesture?.focused != null,
|
|
2015
|
+
"focused",
|
|
2016
|
+
transition,
|
|
2017
|
+
isExiting,
|
|
2018
|
+
shouldReduceMotion
|
|
2019
|
+
);
|
|
2020
|
+
useGestureLayerProgress(
|
|
2021
|
+
focusVisibleProgress,
|
|
2022
|
+
focusVisible,
|
|
2023
|
+
gesture?.focusVisible != null,
|
|
2024
|
+
"focusVisible",
|
|
2025
|
+
transition,
|
|
2026
|
+
isExiting,
|
|
2027
|
+
shouldReduceMotion
|
|
2028
|
+
);
|
|
2029
|
+
useGestureLayerProgress(
|
|
2030
|
+
hoveredProgress,
|
|
2031
|
+
hovered,
|
|
2032
|
+
gesture?.hovered != null,
|
|
2033
|
+
"hovered",
|
|
2034
|
+
transition,
|
|
2035
|
+
isExiting,
|
|
2036
|
+
shouldReduceMotion
|
|
2037
|
+
);
|
|
494
2038
|
const animatedStyle = useAnimatedStyle(() => {
|
|
495
2039
|
const activeKeys = activeKeysRef.current;
|
|
496
2040
|
const hasTransform = hasTransformRef.current;
|
|
497
2041
|
const out = {};
|
|
498
2042
|
const transform = [];
|
|
2043
|
+
const ph = hoveredProgress.value;
|
|
2044
|
+
const pf = focusedProgress.value;
|
|
2045
|
+
const pfv = focusVisibleProgress.value;
|
|
2046
|
+
const pp = pressedProgress.value;
|
|
2047
|
+
const layers = gestureSV.value;
|
|
2048
|
+
const hoveredLayer = layers ? layers.hovered : null;
|
|
2049
|
+
const focusedLayer = layers ? layers.focused : null;
|
|
2050
|
+
const focusVisibleLayer = layers ? layers.focusVisible : null;
|
|
2051
|
+
const pressedLayer = layers ? layers.pressed : null;
|
|
499
2052
|
for (const key of activeKeys) {
|
|
500
|
-
|
|
2053
|
+
let v = sharedValues[key].value;
|
|
2054
|
+
const isColor = COLOR_KEY_SET.has(key);
|
|
2055
|
+
if (hoveredLayer && ph > 0 && hoveredLayer[key] !== void 0) {
|
|
2056
|
+
const t = hoveredLayer[key];
|
|
2057
|
+
v = isColor ? interpolateColor(ph, [0, 1], [v, t]) : v + (t - v) * ph;
|
|
2058
|
+
}
|
|
2059
|
+
if (focusedLayer && pf > 0 && focusedLayer[key] !== void 0) {
|
|
2060
|
+
const t = focusedLayer[key];
|
|
2061
|
+
v = isColor ? interpolateColor(pf, [0, 1], [v, t]) : v + (t - v) * pf;
|
|
2062
|
+
}
|
|
2063
|
+
if (focusVisibleLayer && pfv > 0 && focusVisibleLayer[key] !== void 0) {
|
|
2064
|
+
const t = focusVisibleLayer[key];
|
|
2065
|
+
v = isColor ? interpolateColor(pfv, [0, 1], [v, t]) : v + (t - v) * pfv;
|
|
2066
|
+
}
|
|
2067
|
+
if (pressedLayer && pp > 0 && pressedLayer[key] !== void 0) {
|
|
2068
|
+
const t = pressedLayer[key];
|
|
2069
|
+
v = isColor ? interpolateColor(pp, [0, 1], [v, t]) : v + (t - v) * pp;
|
|
2070
|
+
}
|
|
501
2071
|
if (TRANSFORM_KEY_SET.has(key)) {
|
|
502
2072
|
transform.push(
|
|
503
|
-
key
|
|
2073
|
+
ROTATION_KEYS.has(key) ? { [key]: `${v}deg` } : { [key]: v }
|
|
504
2074
|
);
|
|
505
2075
|
} else {
|
|
506
2076
|
out[key] = v;
|
|
@@ -521,12 +2091,19 @@ function createMotionComponent(Component) {
|
|
|
521
2091
|
setFocusVisible,
|
|
522
2092
|
setHovered
|
|
523
2093
|
);
|
|
2094
|
+
const layoutSig = stableSig(layout);
|
|
2095
|
+
const layoutTransition = useMemo(
|
|
2096
|
+
() => shouldReduceMotion ? void 0 : resolveLayoutTransition(layout),
|
|
2097
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2098
|
+
[layoutSig, shouldReduceMotion]
|
|
2099
|
+
);
|
|
524
2100
|
return /* @__PURE__ */ jsx(
|
|
525
2101
|
AnimatedComponent,
|
|
526
2102
|
{
|
|
527
2103
|
ref,
|
|
528
2104
|
...rest,
|
|
529
2105
|
...gestureHandlers,
|
|
2106
|
+
layout: layoutTransition,
|
|
530
2107
|
style: mergedStyle
|
|
531
2108
|
}
|
|
532
2109
|
);
|
|
@@ -534,23 +2111,25 @@ function createMotionComponent(Component) {
|
|
|
534
2111
|
Motion2.displayName = `Motion(${Component.displayName ?? Component.name ?? "Component"})`;
|
|
535
2112
|
return Motion2;
|
|
536
2113
|
}
|
|
537
|
-
function useAnimatableSharedValues(
|
|
538
|
-
const translateX = useSharedValue(
|
|
539
|
-
const translateY = useSharedValue(
|
|
540
|
-
const scale = useSharedValue(
|
|
541
|
-
const scaleX = useSharedValue(
|
|
542
|
-
const scaleY = useSharedValue(
|
|
543
|
-
const rotate = useSharedValue(
|
|
544
|
-
const
|
|
545
|
-
const
|
|
546
|
-
const
|
|
547
|
-
const
|
|
2114
|
+
function useAnimatableSharedValues(init2) {
|
|
2115
|
+
const translateX = useSharedValue(init2("translateX"));
|
|
2116
|
+
const translateY = useSharedValue(init2("translateY"));
|
|
2117
|
+
const scale = useSharedValue(init2("scale"));
|
|
2118
|
+
const scaleX = useSharedValue(init2("scaleX"));
|
|
2119
|
+
const scaleY = useSharedValue(init2("scaleY"));
|
|
2120
|
+
const rotate = useSharedValue(init2("rotate"));
|
|
2121
|
+
const rotateX = useSharedValue(init2("rotateX"));
|
|
2122
|
+
const rotateY = useSharedValue(init2("rotateY"));
|
|
2123
|
+
const opacity = useSharedValue(init2("opacity"));
|
|
2124
|
+
const width = useSharedValue(init2("width"));
|
|
2125
|
+
const height = useSharedValue(init2("height"));
|
|
2126
|
+
const borderRadius = useSharedValue(init2("borderRadius"));
|
|
548
2127
|
const backgroundColor = useSharedValue(
|
|
549
|
-
|
|
2128
|
+
init2("backgroundColor")
|
|
550
2129
|
);
|
|
551
|
-
const borderColor = useSharedValue(
|
|
552
|
-
const color = useSharedValue(
|
|
553
|
-
const tintColor = useSharedValue(
|
|
2130
|
+
const borderColor = useSharedValue(init2("borderColor"));
|
|
2131
|
+
const color = useSharedValue(init2("color"));
|
|
2132
|
+
const tintColor = useSharedValue(init2("tintColor"));
|
|
554
2133
|
const ref = useRef(null);
|
|
555
2134
|
if (ref.current === null) {
|
|
556
2135
|
ref.current = {
|
|
@@ -560,6 +2139,8 @@ function useAnimatableSharedValues(init) {
|
|
|
560
2139
|
scaleX,
|
|
561
2140
|
scaleY,
|
|
562
2141
|
rotate,
|
|
2142
|
+
rotateX,
|
|
2143
|
+
rotateY,
|
|
563
2144
|
opacity,
|
|
564
2145
|
width,
|
|
565
2146
|
height,
|
|
@@ -630,7 +2211,7 @@ function makeKeyCallbackFactory(key, sharedValue, target, onAnimationEndRef, met
|
|
|
630
2211
|
return (rawPhase, step) => {
|
|
631
2212
|
const cb = (finished) => {
|
|
632
2213
|
"worklet";
|
|
633
|
-
runOnJS(dispatch)(rawPhase, step, !!finished, sharedValue.value);
|
|
2214
|
+
runOnJS$1(dispatch)(rawPhase, step, !!finished, sharedValue.value);
|
|
634
2215
|
};
|
|
635
2216
|
return cb;
|
|
636
2217
|
};
|
|
@@ -696,72 +2277,41 @@ function restValue(v) {
|
|
|
696
2277
|
}
|
|
697
2278
|
return void 0;
|
|
698
2279
|
}
|
|
699
|
-
function
|
|
700
|
-
if (
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
return "[" + v.map(stableStringify).join(",") + "]";
|
|
2280
|
+
function resolveGestureLayers(gesture) {
|
|
2281
|
+
if (!gesture) return null;
|
|
2282
|
+
const out = {};
|
|
2283
|
+
for (const layer of GESTURE_LAYER_NAMES) {
|
|
2284
|
+
const subState = gesture[layer];
|
|
2285
|
+
if (!subState) continue;
|
|
2286
|
+
const resolved = {};
|
|
2287
|
+
for (const key of ALL_KEYS) {
|
|
2288
|
+
const raw = subState[key];
|
|
2289
|
+
if (raw === void 0) continue;
|
|
2290
|
+
const t = targetEndValue(raw);
|
|
2291
|
+
if (t !== void 0) resolved[key] = t;
|
|
2292
|
+
}
|
|
2293
|
+
out[layer] = resolved;
|
|
714
2294
|
}
|
|
715
|
-
|
|
716
|
-
const keys = Object.keys(obj).sort();
|
|
717
|
-
return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
|
|
2295
|
+
return out;
|
|
718
2296
|
}
|
|
719
|
-
function
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
if (!sub) continue;
|
|
732
|
-
for (const k of ALL_KEYS) {
|
|
733
|
-
if (k in sub && !(k in merged)) {
|
|
734
|
-
merged[k] = DEFAULT_RESTING[k];
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
if (active.hovered && gesture.hovered) {
|
|
739
|
-
Object.assign(
|
|
740
|
-
merged,
|
|
741
|
-
gesture.hovered
|
|
742
|
-
);
|
|
743
|
-
}
|
|
744
|
-
if (active.focused && gesture.focused) {
|
|
745
|
-
Object.assign(
|
|
746
|
-
merged,
|
|
747
|
-
gesture.focused
|
|
748
|
-
);
|
|
749
|
-
}
|
|
750
|
-
if (active.focusVisible && gesture.focusVisible) {
|
|
751
|
-
Object.assign(
|
|
752
|
-
merged,
|
|
753
|
-
gesture.focusVisible
|
|
754
|
-
);
|
|
755
|
-
}
|
|
756
|
-
if (active.pressed && gesture.pressed) {
|
|
757
|
-
Object.assign(
|
|
758
|
-
merged,
|
|
759
|
-
gesture.pressed
|
|
760
|
-
);
|
|
761
|
-
}
|
|
762
|
-
return merged;
|
|
2297
|
+
function useGestureLayerProgress(progress, active, declared, layer, transition, isExiting, shouldReduceMotion) {
|
|
2298
|
+
const layerCfgSig = stableSig(gestureLayerTransitionFor(layer, transition));
|
|
2299
|
+
useEffect(() => {
|
|
2300
|
+
if (!declared) return;
|
|
2301
|
+
if (isExiting) {
|
|
2302
|
+
progress.value = 0;
|
|
2303
|
+
return;
|
|
2304
|
+
}
|
|
2305
|
+
const target = active ? 1 : 0;
|
|
2306
|
+
const cfg = shouldReduceMotion ? { type: "no-animation" } : gestureLayerTransitionFor(layer, transition) ?? { type: "spring" };
|
|
2307
|
+
progress.value = resolveTransition(cfg, target);
|
|
2308
|
+
}, [active, declared, isExiting, shouldReduceMotion, layerCfgSig]);
|
|
763
2309
|
}
|
|
764
2310
|
function useGestureHandlers(gesture, rest, setPressed, setFocused, setFocusVisible, setHovered) {
|
|
2311
|
+
const hasPressed = gesture?.pressed ? 1 : 0;
|
|
2312
|
+
const hasFocused = gesture?.focused ? 1 : 0;
|
|
2313
|
+
const hasFocusVisible = gesture?.focusVisible ? 1 : 0;
|
|
2314
|
+
const hasHovered = gesture?.hovered ? 1 : 0;
|
|
765
2315
|
return useMemo(() => {
|
|
766
2316
|
if (!gesture) return {};
|
|
767
2317
|
const handlers = {};
|
|
@@ -794,10 +2344,10 @@ function useGestureHandlers(gesture, rest, setPressed, setFocused, setFocusVisib
|
|
|
794
2344
|
}
|
|
795
2345
|
return handlers;
|
|
796
2346
|
}, [
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
2347
|
+
hasPressed,
|
|
2348
|
+
hasFocused,
|
|
2349
|
+
hasFocusVisible,
|
|
2350
|
+
hasHovered,
|
|
801
2351
|
rest.onTouchStart,
|
|
802
2352
|
rest.onTouchEnd,
|
|
803
2353
|
rest.onTouchCancel,
|
|
@@ -832,6 +2382,155 @@ var Motion = {
|
|
|
832
2382
|
Pressable: MotionPressable,
|
|
833
2383
|
ScrollView: MotionScrollView
|
|
834
2384
|
};
|
|
2385
|
+
function useAnimation(target, transition) {
|
|
2386
|
+
const output = useSharedValue(target);
|
|
2387
|
+
const shouldReduceMotion = useShouldReduceMotion();
|
|
2388
|
+
const cfgSig = stableSig(transition);
|
|
2389
|
+
useEffect(() => {
|
|
2390
|
+
const cfg = shouldReduceMotion ? { type: "no-animation" } : transition ?? { type: "spring" };
|
|
2391
|
+
output.value = resolveTransition(cfg, target);
|
|
2392
|
+
}, [target, cfgSig, shouldReduceMotion]);
|
|
2393
|
+
return output;
|
|
2394
|
+
}
|
|
2395
|
+
function useGesture(transition) {
|
|
2396
|
+
const pressed = useSharedValue(0);
|
|
2397
|
+
const focused = useSharedValue(0);
|
|
2398
|
+
const focusVisible = useSharedValue(0);
|
|
2399
|
+
const hovered = useSharedValue(0);
|
|
2400
|
+
const shouldReduceMotion = useShouldReduceMotion();
|
|
2401
|
+
const setLayer = useCallback(
|
|
2402
|
+
(sv, layer, target) => {
|
|
2403
|
+
const cfg = shouldReduceMotion ? { type: "no-animation" } : layerTransition(layer, transition) ?? { type: "spring" };
|
|
2404
|
+
sv.value = resolveTransition(cfg, target);
|
|
2405
|
+
},
|
|
2406
|
+
// The transition is intentionally read on every call rather than cooked
|
|
2407
|
+
// into the dep array — a fresh literal each render would otherwise
|
|
2408
|
+
// rebuild the handler bag and break composing consumers that key off
|
|
2409
|
+
// handler identity. `transition` is read inside the callback closure;
|
|
2410
|
+
// shared values are stable so the only dep that matters is the reduce-
|
|
2411
|
+
// motion flag.
|
|
2412
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2413
|
+
[shouldReduceMotion]
|
|
2414
|
+
);
|
|
2415
|
+
const handlers = useMemo(
|
|
2416
|
+
() => ({
|
|
2417
|
+
onPressIn: () => setLayer(pressed, "pressed", 1),
|
|
2418
|
+
onPressOut: () => setLayer(pressed, "pressed", 0),
|
|
2419
|
+
onHoverIn: () => setLayer(hovered, "hovered", 1),
|
|
2420
|
+
onHoverOut: () => setLayer(hovered, "hovered", 0),
|
|
2421
|
+
onFocus: () => {
|
|
2422
|
+
setLayer(focused, "focused", 1);
|
|
2423
|
+
if (isFocusVisible()) setLayer(focusVisible, "focusVisible", 1);
|
|
2424
|
+
},
|
|
2425
|
+
onBlur: () => {
|
|
2426
|
+
setLayer(focused, "focused", 0);
|
|
2427
|
+
setLayer(focusVisible, "focusVisible", 0);
|
|
2428
|
+
}
|
|
2429
|
+
}),
|
|
2430
|
+
[setLayer, pressed, focused, focusVisible, hovered]
|
|
2431
|
+
);
|
|
2432
|
+
return { pressed, focused, focusVisible, hovered, handlers };
|
|
2433
|
+
}
|
|
2434
|
+
function layerTransition(layer, transition) {
|
|
2435
|
+
if (!transition) return void 0;
|
|
2436
|
+
if (isTopLevelTransition(transition)) return transition;
|
|
2437
|
+
return transition[layer];
|
|
2438
|
+
}
|
|
2439
|
+
function useMotionValue(initial) {
|
|
2440
|
+
return useSharedValue(initial);
|
|
2441
|
+
}
|
|
2442
|
+
function useSpring(target, config) {
|
|
2443
|
+
const reanimConfig = useMemo(
|
|
2444
|
+
() => springToReanimated(config ?? {}),
|
|
2445
|
+
[
|
|
2446
|
+
config?.tension,
|
|
2447
|
+
config?.friction,
|
|
2448
|
+
config?.mass,
|
|
2449
|
+
config?.velocity,
|
|
2450
|
+
config?.restSpeedThreshold,
|
|
2451
|
+
config?.restDisplacementThreshold
|
|
2452
|
+
]
|
|
2453
|
+
);
|
|
2454
|
+
const isSharedTarget = isSharedValue(target);
|
|
2455
|
+
const initial = isSharedTarget ? target.value : target;
|
|
2456
|
+
const output = useSharedValue(initial);
|
|
2457
|
+
useEffect(() => {
|
|
2458
|
+
if (isSharedTarget) return;
|
|
2459
|
+
output.value = withSpring(target, reanimConfig);
|
|
2460
|
+
}, [isSharedTarget, target, reanimConfig]);
|
|
2461
|
+
useAnimatedReaction(
|
|
2462
|
+
() => {
|
|
2463
|
+
"worklet";
|
|
2464
|
+
if (!isSharedTarget) return null;
|
|
2465
|
+
return target.value;
|
|
2466
|
+
},
|
|
2467
|
+
(next, prev) => {
|
|
2468
|
+
"worklet";
|
|
2469
|
+
if (next === null || next === prev) return;
|
|
2470
|
+
output.value = withSpring(next, reanimConfig);
|
|
2471
|
+
},
|
|
2472
|
+
[isSharedTarget, reanimConfig]
|
|
2473
|
+
);
|
|
2474
|
+
return output;
|
|
2475
|
+
}
|
|
2476
|
+
function isSharedValue(v) {
|
|
2477
|
+
return typeof v === "object" && v !== null && "value" in v;
|
|
2478
|
+
}
|
|
2479
|
+
function useTransform(arg1, inputRange, outputRange, options) {
|
|
2480
|
+
let producer;
|
|
2481
|
+
if (typeof arg1 === "function") {
|
|
2482
|
+
const userFn = arg1;
|
|
2483
|
+
producer = isWorkletFunction(userFn) ? userFn : () => {
|
|
2484
|
+
"worklet";
|
|
2485
|
+
return userFn();
|
|
2486
|
+
};
|
|
2487
|
+
} else {
|
|
2488
|
+
const source = arg1;
|
|
2489
|
+
const input = inputRange;
|
|
2490
|
+
const output = outputRange;
|
|
2491
|
+
const isColor = output.length > 0 && typeof output[0] === "string";
|
|
2492
|
+
const extrapolateLeft = mapExtrapolation(options?.extrapolateLeft);
|
|
2493
|
+
const extrapolateRight = mapExtrapolation(options?.extrapolateRight);
|
|
2494
|
+
producer = isColor ? () => {
|
|
2495
|
+
"worklet";
|
|
2496
|
+
return interpolateColor(
|
|
2497
|
+
source.value,
|
|
2498
|
+
input,
|
|
2499
|
+
output
|
|
2500
|
+
);
|
|
2501
|
+
} : () => {
|
|
2502
|
+
"worklet";
|
|
2503
|
+
return interpolate(
|
|
2504
|
+
source.value,
|
|
2505
|
+
input,
|
|
2506
|
+
output,
|
|
2507
|
+
{ extrapolateLeft, extrapolateRight }
|
|
2508
|
+
);
|
|
2509
|
+
};
|
|
2510
|
+
}
|
|
2511
|
+
return useDerivedValue(producer);
|
|
2512
|
+
}
|
|
2513
|
+
function mapExtrapolation(mode) {
|
|
2514
|
+
if (mode === "identity") return Extrapolation.IDENTITY;
|
|
2515
|
+
if (mode === "extend") return Extrapolation.EXTEND;
|
|
2516
|
+
return Extrapolation.CLAMP;
|
|
2517
|
+
}
|
|
2518
|
+
function useScroll() {
|
|
2519
|
+
const scrollX = useSharedValue(0);
|
|
2520
|
+
const scrollY = useSharedValue(0);
|
|
2521
|
+
const handler = useAnimatedScrollHandler({
|
|
2522
|
+
onScroll: (event) => {
|
|
2523
|
+
"worklet";
|
|
2524
|
+
scrollX.value = event.contentOffset.x;
|
|
2525
|
+
scrollY.value = event.contentOffset.y;
|
|
2526
|
+
}
|
|
2527
|
+
});
|
|
2528
|
+
return {
|
|
2529
|
+
scrollX,
|
|
2530
|
+
scrollY,
|
|
2531
|
+
onScroll: handler
|
|
2532
|
+
};
|
|
2533
|
+
}
|
|
835
2534
|
function useVariants(variants, initial) {
|
|
836
2535
|
const variantsRef = useRef(variants);
|
|
837
2536
|
return useMemo(() => {
|
|
@@ -865,6 +2564,6 @@ function useVariants(variants, initial) {
|
|
|
865
2564
|
}, []);
|
|
866
2565
|
}
|
|
867
2566
|
|
|
868
|
-
export { Motion, MotionConfig, MotionImage, MotionPressable, MotionScrollView, MotionText, MotionView, Presence, createMotionComponent, ensureWorkletEasing, resolveAnimatableValue, resolveTransition, useMotionConfig, usePresence, useShouldReduceMotion, useVariants };
|
|
2567
|
+
export { Motion, MotionConfig, MotionImage, MotionPressable, MotionScrollView, MotionText, MotionView, Presence, createMotionComponent, ensureWorkletEasing, resolveAnimatableValue, resolveTransition, useAnimation, useGesture, useMotionConfig, useMotionValue, usePresence, useScroll, useShouldReduceMotion, useSpring, useTransform, useVariants };
|
|
869
2568
|
//# sourceMappingURL=index.mjs.map
|
|
870
2569
|
//# sourceMappingURL=index.mjs.map
|