1 | 'use strict';
|
2 |
|
3 | import { isWorkletFunction } from "./commonTypes.js";
|
4 | import { ReanimatedError, registerReanimatedError } from "./errors.js";
|
5 | import { setupCallGuard, setupConsole } from "./initializers.js";
|
6 | import { registerLoggerConfig } from "./logger/index.js";
|
7 | import NativeReanimatedModule from './NativeReanimated';
|
8 | import { shouldBeUseWeb } from "./PlatformChecker.js";
|
9 | import { makeShareableCloneOnUIRecursive, makeShareableCloneRecursive } from "./shareables.js";
|
10 | const SHOULD_BE_USE_WEB = shouldBeUseWeb();
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | export function createWorkletRuntime(name, initializer) {
|
27 |
|
28 |
|
29 | const config = __reanimatedLoggerConfig;
|
30 | return NativeReanimatedModule.createWorkletRuntime(name, makeShareableCloneRecursive(() => {
|
31 | 'worklet';
|
32 |
|
33 | registerReanimatedError();
|
34 | registerLoggerConfig(config);
|
35 | setupCallGuard();
|
36 | setupConsole();
|
37 | initializer?.();
|
38 | }));
|
39 | }
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | export function runOnRuntime(workletRuntime, worklet) {
|
45 | 'worklet';
|
46 |
|
47 | if (__DEV__ && !SHOULD_BE_USE_WEB && !isWorkletFunction(worklet)) {
|
48 | throw new ReanimatedError('The function passed to `runOnRuntime` is not a worklet.' + (_WORKLET ? ' Please make sure that `processNestedWorklets` option in Reanimated Babel plugin is enabled.' : ''));
|
49 | }
|
50 | if (_WORKLET) {
|
51 | return (...args) => global._scheduleOnRuntime(workletRuntime, makeShareableCloneOnUIRecursive(() => {
|
52 | 'worklet';
|
53 |
|
54 | worklet(...args);
|
55 | }));
|
56 | }
|
57 | return (...args) => NativeReanimatedModule.scheduleOnRuntime(workletRuntime, makeShareableCloneRecursive(() => {
|
58 | 'worklet';
|
59 |
|
60 | worklet(...args);
|
61 | }));
|
62 | }
|
63 |
|
\ | No newline at end of file |