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