@amazon-devices/react-native-worklets 1.0.1 → 1.0.2
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/kepler-compatibility.json +2 -1
- package/lib/module/index.js +0 -25
- package/package.json +1 -1
- package/src/index.ts +0 -52
- package/bundleMode/index.js +0 -59
- package/lib/module/PlatformChecker/PlatformChecker.js +0 -8
- package/lib/module/PlatformChecker/index.js +0 -18
- package/lib/module/WorkletsError.js +0 -29
- package/lib/module/WorkletsModule/JSWorklets.js +0 -111
- package/lib/module/WorkletsModule/NativeWorklets.js +0 -126
- package/lib/module/WorkletsModule/index.js +0 -4
- package/lib/module/WorkletsModule/workletsModuleInstance.js +0 -7
- package/lib/module/WorkletsModule/workletsModuleInstance.web.js +0 -5
- package/lib/module/WorkletsModule/workletsModuleProxy.js +0 -4
- package/lib/module/bundleUnpacker.js +0 -47
- package/lib/module/callGuard.js +0 -30
- package/lib/module/deprecated.js +0 -20
- package/lib/module/errors.js +0 -69
- package/lib/module/featureFlags/index.js +0 -48
- package/lib/module/initializers.js +0 -221
- package/lib/module/isSynchronizable.js +0 -6
- package/lib/module/logger.js +0 -15
- package/lib/module/privateGlobals.d.js +0 -7
- package/lib/module/publicGlobals.js +0 -6
- package/lib/module/runLoop/common/setImmediatePolyfill.js +0 -15
- package/lib/module/runLoop/common/setIntervalPolyfill.js +0 -26
- package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js +0 -10
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +0 -52
- package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js +0 -32
- package/lib/module/runLoop/workletRuntime/index.js +0 -19
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js +0 -11
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +0 -48
- package/lib/module/runLoop/workletRuntime/setTimeout.js +0 -28
- package/lib/module/runLoop/workletRuntime/taskQueue.js +0 -37
- package/lib/module/runtimeKind.js +0 -39
- package/lib/module/runtimes.js +0 -100
- package/lib/module/serializable.js +0 -568
- package/lib/module/serializableMappingCache.js +0 -37
- package/lib/module/specs/NativeWorkletsModule.js +0 -5
- package/lib/module/specs/NativeWorkletsModule.kepler.js +0 -7
- package/lib/module/specs/index.js +0 -10
- package/lib/module/synchronizable.js +0 -9
- package/lib/module/synchronizableUnpacker.js +0 -42
- package/lib/module/threads.js +0 -347
- package/lib/module/utils/checkCppVersion.js +0 -30
- package/lib/module/utils/jsVersion.js +0 -9
- package/lib/module/valueUnpacker.js +0 -60
- package/lib/module/workletFunction.js +0 -37
- package/lib/module/workletRuntimeEntry.js +0 -32
- package/lib/module/workletTypes.js +0 -12
- package/scripts/validate-react-native-version.js +0 -43
- package/src/PlatformChecker/PlatformChecker.ts +0 -7
- package/src/PlatformChecker/index.ts +0 -30
- package/src/WorkletsError.ts +0 -36
- package/src/WorkletsModule/JSWorklets.ts +0 -200
- package/src/WorkletsModule/NativeWorklets.ts +0 -256
- package/src/WorkletsModule/index.ts +0 -7
- package/src/WorkletsModule/workletsModuleInstance.ts +0 -9
- package/src/WorkletsModule/workletsModuleInstance.web.ts +0 -5
- package/src/WorkletsModule/workletsModuleProxy.ts +0 -126
- package/src/bundleUnpacker.ts +0 -75
- package/src/callGuard.ts +0 -33
- package/src/deprecated.ts +0 -32
- package/src/errors.ts +0 -80
- package/src/featureFlags/index.ts +0 -72
- package/src/initializers.ts +0 -262
- package/src/isSynchronizable.ts +0 -13
- package/src/logger.ts +0 -16
- package/src/publicGlobals.ts +0 -39
- package/src/runLoop/common/setImmediatePolyfill.ts +0 -20
- package/src/runLoop/common/setIntervalPolyfill.ts +0 -38
- package/src/runLoop/uiRuntime/mockedRequestAnimationFrame.ts +0 -11
- package/src/runLoop/uiRuntime/requestAnimationFrame.ts +0 -66
- package/src/runLoop/uiRuntime/setTimeoutPolyfill.ts +0 -40
- package/src/runLoop/workletRuntime/index.ts +0 -18
- package/src/runLoop/workletRuntime/queueMicrotask.ts +0 -13
- package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +0 -61
- package/src/runLoop/workletRuntime/setTimeout.ts +0 -37
- package/src/runLoop/workletRuntime/taskQueue.ts +0 -44
- package/src/runtimeKind.ts +0 -37
- package/src/runtimes.ts +0 -193
- package/src/serializable.ts +0 -801
- package/src/serializableMappingCache.ts +0 -42
- package/src/specs/NativeWorkletsModule.kepler.ts +0 -11
- package/src/specs/NativeWorkletsModule.ts +0 -9
- package/src/specs/index.ts +0 -13
- package/src/synchronizable.ts +0 -32
- package/src/synchronizableUnpacker.ts +0 -67
- package/src/threads.ts +0 -452
- package/src/utils/checkCppVersion.ts +0 -34
- package/src/utils/jsVersion.ts +0 -7
- package/src/valueUnpacker.ts +0 -90
- package/src/workletFunction.ts +0 -42
- package/src/workletRuntimeEntry.ts +0 -35
- package/src/workletTypes.ts +0 -81
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
export function setupSetTimeout() {
|
|
4
|
-
'worklet';
|
|
5
|
-
|
|
6
|
-
const timeoutHandleToRafHandle: Map<number, number> = new Map();
|
|
7
|
-
|
|
8
|
-
const setTimeoutPolyfill = (
|
|
9
|
-
callback: (...args: unknown[]) => void,
|
|
10
|
-
delay: number = 0,
|
|
11
|
-
...args: unknown[]
|
|
12
|
-
) => {
|
|
13
|
-
const start = performance.now();
|
|
14
|
-
let timeoutHandle = 0;
|
|
15
|
-
|
|
16
|
-
const rafCallback = () => {
|
|
17
|
-
const now = performance.now();
|
|
18
|
-
if (now - start >= delay) {
|
|
19
|
-
callback(...args);
|
|
20
|
-
timeoutHandleToRafHandle.delete(timeoutHandle);
|
|
21
|
-
} else {
|
|
22
|
-
const rafHandle = requestAnimationFrame(rafCallback);
|
|
23
|
-
timeoutHandleToRafHandle.set(timeoutHandle, rafHandle);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
timeoutHandle = requestAnimationFrame(rafCallback);
|
|
28
|
-
timeoutHandleToRafHandle.set(timeoutHandle, timeoutHandle);
|
|
29
|
-
return timeoutHandle;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const clearTimeoutPolyfill = (timeoutHandle: number) => {
|
|
33
|
-
const rafHandle = timeoutHandleToRafHandle.get(timeoutHandle);
|
|
34
|
-
timeoutHandleToRafHandle.delete(timeoutHandle);
|
|
35
|
-
cancelAnimationFrame(rafHandle!);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
globalThis.setTimeout = setTimeoutPolyfill as typeof setTimeout;
|
|
39
|
-
globalThis.clearTimeout = clearTimeoutPolyfill as typeof clearTimeout;
|
|
40
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { setupSetImmediate } from '../common/setImmediatePolyfill';
|
|
4
|
-
import { setupSetInterval } from '../common/setIntervalPolyfill';
|
|
5
|
-
import { setupQueueMicrotask } from './queueMicrotask';
|
|
6
|
-
import { setupRequestAnimationFrame } from './requestAnimationFramePolyfill';
|
|
7
|
-
import { setupSetTimeout } from './setTimeout';
|
|
8
|
-
import { setupTaskQueue } from './taskQueue';
|
|
9
|
-
|
|
10
|
-
export function setupRunLoop(animationQueuePollingRate: number) {
|
|
11
|
-
'worklet';
|
|
12
|
-
setupTaskQueue();
|
|
13
|
-
setupQueueMicrotask();
|
|
14
|
-
setupSetTimeout();
|
|
15
|
-
setupRequestAnimationFrame(animationQueuePollingRate);
|
|
16
|
-
setupSetImmediate();
|
|
17
|
-
setupSetInterval();
|
|
18
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { pushMicrotask } from './taskQueue';
|
|
4
|
-
|
|
5
|
-
export function setupQueueMicrotask() {
|
|
6
|
-
'worklet';
|
|
7
|
-
globalThis.queueMicrotask = function (
|
|
8
|
-
callback: (...args: unknown[]) => void,
|
|
9
|
-
...args: unknown[]
|
|
10
|
-
) {
|
|
11
|
-
pushMicrotask(() => callback(...args));
|
|
12
|
-
} as typeof queueMicrotask;
|
|
13
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
export function setupRequestAnimationFrame(animationQueuePollingRate: number) {
|
|
4
|
-
'worklet';
|
|
5
|
-
const timeoutInterval = animationQueuePollingRate;
|
|
6
|
-
|
|
7
|
-
let queuedCallbacks: ((timestamp: number) => void)[] = [];
|
|
8
|
-
let queuedCallbacksBegin = 0;
|
|
9
|
-
let queuedCallbacksEnd = 0;
|
|
10
|
-
|
|
11
|
-
let flushedCallbacks = queuedCallbacks;
|
|
12
|
-
let flushedCallbacksBegin = 0;
|
|
13
|
-
let flushedCallbacksEnd = 0;
|
|
14
|
-
|
|
15
|
-
let flushRequested = false;
|
|
16
|
-
|
|
17
|
-
function flushAnimationFrame() {
|
|
18
|
-
flushRequested = false;
|
|
19
|
-
const timestamp = performance.now();
|
|
20
|
-
|
|
21
|
-
flushedCallbacks = queuedCallbacks;
|
|
22
|
-
queuedCallbacks = [];
|
|
23
|
-
|
|
24
|
-
flushedCallbacksBegin = queuedCallbacksBegin;
|
|
25
|
-
flushedCallbacksEnd = queuedCallbacksEnd;
|
|
26
|
-
queuedCallbacksBegin = queuedCallbacksEnd;
|
|
27
|
-
|
|
28
|
-
for (const callback of flushedCallbacks) {
|
|
29
|
-
callback(timestamp);
|
|
30
|
-
globalThis.__flushMicrotasks();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
flushedCallbacksBegin = flushedCallbacksEnd;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
globalThis.requestAnimationFrame = (
|
|
37
|
-
callback: (timestamp: number) => void
|
|
38
|
-
): number => {
|
|
39
|
-
const handle = queuedCallbacksEnd++;
|
|
40
|
-
|
|
41
|
-
queuedCallbacks.push(callback);
|
|
42
|
-
if (!flushRequested) {
|
|
43
|
-
flushRequested = true;
|
|
44
|
-
|
|
45
|
-
setTimeout(flushAnimationFrame, timeoutInterval);
|
|
46
|
-
}
|
|
47
|
-
return handle;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
globalThis.cancelAnimationFrame = (handle: number) => {
|
|
51
|
-
if (handle < flushedCallbacksBegin || handle >= queuedCallbacksEnd) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (handle < flushedCallbacksEnd) {
|
|
56
|
-
flushedCallbacks[handle - flushedCallbacksBegin] = () => {};
|
|
57
|
-
} else {
|
|
58
|
-
queuedCallbacks[handle - queuedCallbacksBegin] = () => {};
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { pushTask } from './taskQueue';
|
|
4
|
-
|
|
5
|
-
export function setupSetTimeout() {
|
|
6
|
-
'worklet';
|
|
7
|
-
|
|
8
|
-
const pendingHandlers: Set<number> = new Set();
|
|
9
|
-
let ID = 0;
|
|
10
|
-
|
|
11
|
-
const setTimeoutPolyfill = (
|
|
12
|
-
callback: (...args: unknown[]) => void,
|
|
13
|
-
delay: number = 0,
|
|
14
|
-
...args: unknown[]
|
|
15
|
-
) => {
|
|
16
|
-
const handlerId = ID++;
|
|
17
|
-
|
|
18
|
-
const timeoutCallback = () => {
|
|
19
|
-
if (!pendingHandlers.has(handlerId)) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
callback(...args);
|
|
23
|
-
pendingHandlers.delete(handlerId);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
pendingHandlers.add(handlerId);
|
|
27
|
-
pushTask(timeoutCallback, handlerId, delay);
|
|
28
|
-
return handlerId;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const clearTimeoutPolyfill = (timeoutHandle: number) => {
|
|
32
|
-
pendingHandlers.delete(timeoutHandle);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
globalThis.setTimeout = setTimeoutPolyfill as typeof setTimeout;
|
|
36
|
-
globalThis.clearTimeout = clearTimeoutPolyfill as typeof clearTimeout;
|
|
37
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
type Callback = () => void;
|
|
4
|
-
|
|
5
|
-
export type Queue = {
|
|
6
|
-
microtasks: Array<Callback>;
|
|
7
|
-
timeoutCallbacks: Map<number, Callback>;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export function setupTaskQueue() {
|
|
11
|
-
'worklet';
|
|
12
|
-
const queue: Queue = {
|
|
13
|
-
microtasks: [],
|
|
14
|
-
timeoutCallbacks: new Map(),
|
|
15
|
-
};
|
|
16
|
-
globalThis._taskQueue = queue;
|
|
17
|
-
|
|
18
|
-
globalThis.__runTimeoutCallback = function (handlerId: number) {
|
|
19
|
-
const task = queue.timeoutCallbacks.get(handlerId);
|
|
20
|
-
task?.();
|
|
21
|
-
queue.timeoutCallbacks.delete(handlerId);
|
|
22
|
-
globalThis.__flushMicrotasks();
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
globalThis.__flushMicrotasks = function () {
|
|
26
|
-
for (let i = 0; i < queue.microtasks.length; i++) {
|
|
27
|
-
queue.microtasks[i]();
|
|
28
|
-
}
|
|
29
|
-
queue.microtasks = [];
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function pushMicrotask(callback: Callback) {
|
|
34
|
-
'worklet';
|
|
35
|
-
const queue = globalThis._taskQueue;
|
|
36
|
-
queue.microtasks.push(callback);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function pushTask(callback: Callback, handlerId: number, delay: number) {
|
|
40
|
-
'worklet';
|
|
41
|
-
const queue = globalThis._taskQueue;
|
|
42
|
-
queue.timeoutCallbacks.set(handlerId, callback);
|
|
43
|
-
globalThis._scheduleTimeoutCallback(delay, handlerId);
|
|
44
|
-
}
|
package/src/runtimeKind.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
export enum RuntimeKind {
|
|
4
|
-
/**
|
|
5
|
-
* The React Native runtime, which is the main runtime for React Native where
|
|
6
|
-
* React exists and where components are rendered.
|
|
7
|
-
*/
|
|
8
|
-
ReactNative = 1,
|
|
9
|
-
/**
|
|
10
|
-
* The UI runtime, which is a special runtime that executes on the UI thread,
|
|
11
|
-
* mostly used for animations and gestures.
|
|
12
|
-
*/
|
|
13
|
-
UI = 2,
|
|
14
|
-
/** Additional runtime created on-demand by the user. */
|
|
15
|
-
Worker = 3,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Programmatic way to check the current runtime kind. It's useful when you need
|
|
20
|
-
* specific implementations for different runtimes created by Worklets.
|
|
21
|
-
*
|
|
22
|
-
* For more optimized calls you can check the value of
|
|
23
|
-
* `globalThis.__RUNTIME_KIND` directly.
|
|
24
|
-
*
|
|
25
|
-
* @returns The kind of the current runtime.
|
|
26
|
-
*/
|
|
27
|
-
export function getRuntimeKind(): RuntimeKind {
|
|
28
|
-
'worklet';
|
|
29
|
-
return globalThis.__RUNTIME_KIND;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (globalThis.__RUNTIME_KIND === undefined) {
|
|
33
|
-
// In Jest environments eager imports make this file to evaluate before
|
|
34
|
-
// `initializers.ts` file, therefore we have to set the RuntimeKind here,
|
|
35
|
-
// just to be safe.
|
|
36
|
-
globalThis.__RUNTIME_KIND = RuntimeKind.ReactNative;
|
|
37
|
-
}
|
package/src/runtimes.ts
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { setupCallGuard } from './callGuard';
|
|
4
|
-
import { getMemorySafeCapturableConsole, setupConsole } from './initializers';
|
|
5
|
-
import { SHOULD_BE_USE_WEB } from './PlatformChecker';
|
|
6
|
-
import { setupRunLoop } from './runLoop/workletRuntime';
|
|
7
|
-
import { RuntimeKind } from './runtimeKind';
|
|
8
|
-
import {
|
|
9
|
-
createSerializable,
|
|
10
|
-
makeShareableCloneOnUIRecursive,
|
|
11
|
-
} from './serializable';
|
|
12
|
-
import { isWorkletFunction } from './workletFunction';
|
|
13
|
-
import { registerWorkletsError, WorkletsError } from './WorkletsError';
|
|
14
|
-
import { WorkletsModule } from './WorkletsModule';
|
|
15
|
-
import type { WorkletFunction, WorkletRuntime } from './workletTypes';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Lets you create a new JS runtime which can be used to run worklets possibly
|
|
19
|
-
* on different threads than JS or UI thread.
|
|
20
|
-
*
|
|
21
|
-
* @param config - Runtime configuration object - {@link WorkletRuntimeConfig}.
|
|
22
|
-
* @returns WorkletRuntime which is a
|
|
23
|
-
* `jsi::HostObject<worklets::WorkletRuntime>` - {@link WorkletRuntime}
|
|
24
|
-
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/createWorkletRuntime/
|
|
25
|
-
*/
|
|
26
|
-
// @ts-expect-error Public API overload.
|
|
27
|
-
export function createWorkletRuntime(
|
|
28
|
-
config?: WorkletRuntimeConfig
|
|
29
|
-
): WorkletRuntime;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @deprecated Please use the new config object signature instead:
|
|
33
|
-
* `createWorkletRuntime({ name, initializer })`
|
|
34
|
-
*
|
|
35
|
-
* Lets you create a new JS runtime which can be used to run worklets possibly
|
|
36
|
-
* on different threads than JS or UI thread.
|
|
37
|
-
* @param name - A name used to identify the runtime which will appear in
|
|
38
|
-
* devices list in Chrome DevTools.
|
|
39
|
-
* @param initializer - An optional worklet that will be run synchronously on
|
|
40
|
-
* the same thread immediately after the runtime is created.
|
|
41
|
-
* @returns WorkletRuntime which is a
|
|
42
|
-
* `jsi::HostObject<worklets::WorkletRuntime>` - {@link WorkletRuntime}
|
|
43
|
-
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/createWorkletRuntime/
|
|
44
|
-
*/
|
|
45
|
-
export function createWorkletRuntime(
|
|
46
|
-
name?: string,
|
|
47
|
-
initializer?: () => void
|
|
48
|
-
): WorkletRuntime;
|
|
49
|
-
|
|
50
|
-
export function createWorkletRuntime(
|
|
51
|
-
nameOrConfig?: string | WorkletRuntimeConfigInternal,
|
|
52
|
-
initializer?: WorkletFunction<[], void>
|
|
53
|
-
): WorkletRuntime {
|
|
54
|
-
const runtimeBoundCapturableConsole = getMemorySafeCapturableConsole();
|
|
55
|
-
|
|
56
|
-
let name: string;
|
|
57
|
-
let initializerFn: (() => void) | undefined;
|
|
58
|
-
let useDefaultQueue = true;
|
|
59
|
-
let customQueue: object | undefined;
|
|
60
|
-
let animationQueuePollingRate: number;
|
|
61
|
-
let enableEventLoop = true;
|
|
62
|
-
if (typeof nameOrConfig === 'string') {
|
|
63
|
-
name = nameOrConfig;
|
|
64
|
-
initializerFn = initializer;
|
|
65
|
-
} else {
|
|
66
|
-
// TODO: Make anonymous name globally unique.
|
|
67
|
-
name = nameOrConfig?.name ?? 'anonymous';
|
|
68
|
-
initializerFn = nameOrConfig?.initializer;
|
|
69
|
-
useDefaultQueue = nameOrConfig?.useDefaultQueue ?? true;
|
|
70
|
-
customQueue = nameOrConfig?.customQueue;
|
|
71
|
-
animationQueuePollingRate = Math.round(
|
|
72
|
-
nameOrConfig?.animationQueuePollingRate ?? 16
|
|
73
|
-
);
|
|
74
|
-
enableEventLoop = nameOrConfig?.enableEventLoop ?? true;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (initializerFn && !isWorkletFunction(initializerFn)) {
|
|
78
|
-
throw new WorkletsError(
|
|
79
|
-
'The initializer passed to `createWorkletRuntime` is not a worklet.'
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return WorkletsModule.createWorkletRuntime(
|
|
84
|
-
name,
|
|
85
|
-
createSerializable(() => {
|
|
86
|
-
'worklet';
|
|
87
|
-
setupCallGuard();
|
|
88
|
-
registerWorkletsError();
|
|
89
|
-
setupConsole(runtimeBoundCapturableConsole);
|
|
90
|
-
if (enableEventLoop) {
|
|
91
|
-
setupRunLoop(animationQueuePollingRate);
|
|
92
|
-
}
|
|
93
|
-
initializerFn?.();
|
|
94
|
-
}),
|
|
95
|
-
useDefaultQueue,
|
|
96
|
-
customQueue,
|
|
97
|
-
enableEventLoop
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// @ts-expect-error Check `runOnUI` overload.
|
|
102
|
-
export function runOnRuntime<Args extends unknown[], ReturnValue>(
|
|
103
|
-
workletRuntime: WorkletRuntime,
|
|
104
|
-
worklet: (...args: Args) => ReturnValue
|
|
105
|
-
): WorkletFunction<Args, ReturnValue>;
|
|
106
|
-
/** Schedule a worklet to execute on the background queue. */
|
|
107
|
-
export function runOnRuntime<Args extends unknown[], ReturnValue>(
|
|
108
|
-
workletRuntime: WorkletRuntime,
|
|
109
|
-
worklet: WorkletFunction<Args, ReturnValue>
|
|
110
|
-
): (...args: Args) => void {
|
|
111
|
-
'worklet';
|
|
112
|
-
if (__DEV__ && !SHOULD_BE_USE_WEB && !isWorkletFunction(worklet)) {
|
|
113
|
-
throw new WorkletsError(
|
|
114
|
-
'The function passed to `runOnRuntime` is not a worklet.'
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
if (globalThis.__RUNTIME_KIND !== RuntimeKind.ReactNative) {
|
|
118
|
-
return (...args) =>
|
|
119
|
-
globalThis._scheduleOnRuntime(
|
|
120
|
-
workletRuntime,
|
|
121
|
-
makeShareableCloneOnUIRecursive(() => {
|
|
122
|
-
'worklet';
|
|
123
|
-
worklet(...args);
|
|
124
|
-
})
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
return (...args) =>
|
|
128
|
-
WorkletsModule.scheduleOnRuntime(
|
|
129
|
-
workletRuntime,
|
|
130
|
-
createSerializable(() => {
|
|
131
|
-
'worklet';
|
|
132
|
-
worklet(...args);
|
|
133
|
-
globalThis.__flushMicrotasks();
|
|
134
|
-
})
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/** Configuration object for creating a worklet runtime. */
|
|
139
|
-
export type WorkletRuntimeConfig = {
|
|
140
|
-
/** The name of the worklet runtime. */
|
|
141
|
-
name?: string;
|
|
142
|
-
/**
|
|
143
|
-
* A worklet that will be run immediately after the runtime is created and
|
|
144
|
-
* before any other worklets.
|
|
145
|
-
*/
|
|
146
|
-
initializer?: () => void;
|
|
147
|
-
/**
|
|
148
|
-
* Time interval in milliseconds between polling of frame callbacks scheduled
|
|
149
|
-
* by requestAnimationFrame. If not specified, it defaults to 16 ms.
|
|
150
|
-
*/
|
|
151
|
-
animationQueuePollingRate?: number;
|
|
152
|
-
/**
|
|
153
|
-
* Determines whether to enable the default Event Loop or not. The Event Loop
|
|
154
|
-
* provides implementations for `setTimeout`, `setImmediate`, `setInterval`,
|
|
155
|
-
* `requestAnimationFrame`, `queueMicrotask`, `clearTimeout`, `clearInterval`,
|
|
156
|
-
* `clearImmediate`, and `cancelAnimationFrame` methods. If not specified, it
|
|
157
|
-
* defaults to `true`.
|
|
158
|
-
*/
|
|
159
|
-
enableEventLoop?: true;
|
|
160
|
-
} & (
|
|
161
|
-
| {
|
|
162
|
-
/**
|
|
163
|
-
* If true, the runtime will use the default queue implementation for
|
|
164
|
-
* scheduling worklets. Defaults to true.
|
|
165
|
-
*/
|
|
166
|
-
useDefaultQueue?: true;
|
|
167
|
-
/**
|
|
168
|
-
* An optional custom queue to be used for scheduling worklets.
|
|
169
|
-
*
|
|
170
|
-
* The queue has to implement the C++ `AsyncQueue` interface from
|
|
171
|
-
* `<worklets/Public/AsyncQueue.h>`.
|
|
172
|
-
*/
|
|
173
|
-
customQueue?: never;
|
|
174
|
-
}
|
|
175
|
-
| {
|
|
176
|
-
/**
|
|
177
|
-
* If true, the runtime will use the default queue implementation for
|
|
178
|
-
* scheduling worklets. Defaults to true.
|
|
179
|
-
*/
|
|
180
|
-
useDefaultQueue: false;
|
|
181
|
-
/**
|
|
182
|
-
* An optional custom queue to be used for scheduling worklets.
|
|
183
|
-
*
|
|
184
|
-
* The queue has to implement the C++ `AsyncQueue` interface from
|
|
185
|
-
* `<worklets/Public/AsyncQueue.h>`.
|
|
186
|
-
*/
|
|
187
|
-
customQueue?: object;
|
|
188
|
-
}
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
type WorkletRuntimeConfigInternal = WorkletRuntimeConfig & {
|
|
192
|
-
initializer?: WorkletFunction<[], void>;
|
|
193
|
-
};
|