react-native-worklets 0.7.4 → 0.8.0-bundle-mode-preview-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/.worklets/dummy.md +1 -0
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +32 -28
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +13 -5
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +7 -5
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +5 -4
- package/Common/cpp/worklets/Resources/SynchronizableUnpacker.cpp +1 -1
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +42 -19
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +2 -0
- package/Common/cpp/worklets/Tools/Defs.h +2 -2
- package/Common/cpp/worklets/Tools/ScriptBuffer.h +34 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeBindings.h +24 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +11 -6
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +82 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +12 -0
- package/RNWorklets.podspec +15 -14
- package/android/CMakeLists.txt +8 -2
- package/android/build.gradle +92 -56
- package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.cpp +67 -0
- package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.h +48 -0
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.cpp +52 -0
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.h +43 -0
- package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +115 -19
- package/android/src/main/cpp/worklets/android/WorkletsModule.h +11 -13
- package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +6 -0
- package/android/src/main/java/com/swmansion/worklets/ScriptBufferWrapper.java +88 -0
- package/android/src/networking/com/swmansion/worklets/WorkletRuntimeWrapper.kt +23 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsHeaderUtil.kt +30 -0
- package/android/src/{legacyBundling → networking}/com/swmansion/worklets/WorkletsModule.java +52 -2
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworkEventUtil.kt +268 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworking.kt +1084 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsOkHttpCallUtil.kt +37 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressListener.kt +9 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressRequestBody.kt +98 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressResponseBody.kt +57 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressiveStringDecoder.kt +82 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsRequestBodyUtil.kt +177 -0
- package/android/src/{experimentalBundling → no-networking}/com/swmansion/worklets/WorkletsModule.java +10 -15
- package/apple/worklets/apple/Networking/WorkletsNetworking.h +22 -0
- package/apple/worklets/apple/Networking/WorkletsNetworking.mm +706 -0
- package/apple/worklets/apple/WorkletsModule.mm +56 -17
- package/bundleMode/index.d.ts +3 -0
- package/bundleMode/index.js +103 -48
- package/compatibility.json +5 -2
- package/lib/module/WorkletsModule/NativeWorklets.native.js +8 -2
- package/lib/module/WorkletsModule/NativeWorklets.native.js.map +1 -1
- package/lib/module/bundleMode/metroOverrides.native.js +115 -0
- package/lib/module/bundleMode/metroOverrides.native.js.map +1 -0
- package/lib/module/bundleMode/network.native.js +41 -0
- package/lib/module/bundleMode/network.native.js.map +1 -0
- package/lib/module/debug/jsVersion.js +1 -1
- package/lib/module/debug/jsVersion.js.map +1 -1
- package/lib/module/featureFlags/staticFlags.json +2 -0
- package/lib/module/featureFlags/types.js +3 -1
- package/lib/module/featureFlags/types.js.map +1 -1
- package/lib/module/index.js +4 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/initializers/initializers.native.js +14 -43
- package/lib/module/initializers/initializers.native.js.map +1 -1
- package/lib/module/initializers/workletRuntimeEntry.native.js +3 -3
- package/lib/module/initializers/workletRuntimeEntry.native.js.map +1 -1
- package/lib/module/memory/bundleUnpacker.native.js +2 -2
- package/lib/module/memory/bundleUnpacker.native.js.map +1 -1
- package/lib/module/memory/serializable.native.js +3 -3
- package/lib/module/memory/serializable.native.js.map +1 -1
- package/lib/module/memory/synchronizableUnpacker.native.js +1 -1
- package/lib/module/memory/synchronizableUnpacker.native.js.map +1 -1
- package/lib/module/platformChecker.js +2 -2
- package/lib/module/platformChecker.js.map +1 -1
- package/lib/module/runtimeKind.js +51 -0
- package/lib/module/runtimeKind.js.map +1 -1
- package/lib/module/runtimes.js +3 -0
- package/lib/module/runtimes.js.map +1 -1
- package/lib/module/runtimes.native.js +32 -2
- package/lib/module/runtimes.native.js.map +1 -1
- package/lib/module/threads.native.js +2 -2
- package/lib/module/threads.native.js.map +1 -1
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts.map +1 -1
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +2 -1
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -1
- package/lib/typescript/bundleMode/metroOverrides.native.d.ts +28 -0
- package/lib/typescript/bundleMode/metroOverrides.native.d.ts.map +1 -0
- package/lib/typescript/bundleMode/network.native.d.ts +7 -0
- package/lib/typescript/bundleMode/network.native.d.ts.map +1 -0
- package/lib/typescript/debug/jsVersion.d.ts +1 -1
- package/lib/typescript/debug/jsVersion.d.ts.map +1 -1
- package/lib/typescript/featureFlags/types.d.ts +3 -1
- package/lib/typescript/featureFlags/types.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/initializers/initializers.native.d.ts.map +1 -1
- package/lib/typescript/initializers/workletRuntimeEntry.native.d.ts +1 -1
- package/lib/typescript/memory/bundleUnpacker.native.d.ts.map +1 -1
- package/lib/typescript/platformChecker.d.ts.map +1 -1
- package/lib/typescript/runtimeKind.d.ts +31 -0
- package/lib/typescript/runtimeKind.d.ts.map +1 -1
- package/lib/typescript/runtimes.d.ts +1 -0
- package/lib/typescript/runtimes.d.ts.map +1 -1
- package/lib/typescript/runtimes.native.d.ts +20 -2
- package/lib/typescript/runtimes.native.d.ts.map +1 -1
- package/lib/typescript/threads.native.d.ts +1 -1
- package/package.json +11 -13
- package/plugin/index.d.ts +109 -0
- package/plugin/index.js +60 -13
- package/scripts/worklets_utils.rb +21 -5
- package/src/WorkletsModule/NativeWorklets.native.ts +14 -4
- package/src/WorkletsModule/workletsModuleProxy.ts +6 -3
- package/src/bundleMode/metroOverrides.native.ts +151 -0
- package/src/bundleMode/network.native.ts +59 -0
- package/src/debug/jsVersion.ts +1 -1
- package/src/featureFlags/staticFlags.json +2 -0
- package/src/featureFlags/types.ts +3 -1
- package/src/index.ts +10 -1
- package/src/initializers/initializers.native.ts +19 -63
- package/src/initializers/workletRuntimeEntry.native.ts +3 -3
- package/src/memory/bundleUnpacker.native.ts +2 -4
- package/src/memory/serializable.native.ts +3 -3
- package/src/memory/synchronizableUnpacker.native.ts +1 -1
- package/src/platformChecker.ts +3 -2
- package/src/privateGlobals.d.ts +3 -1
- package/src/runtimeKind.ts +47 -0
- package/src/runtimes.native.ts +41 -2
- package/src/runtimes.ts +10 -0
- package/src/threads.native.ts +2 -2
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
import {
|
|
4
|
+
disallowRNImports,
|
|
5
|
+
mockTurboModuleRegistry,
|
|
6
|
+
silenceHMRWarnings,
|
|
7
|
+
} from '../bundleMode/metroOverrides';
|
|
8
|
+
import { initializeNetworking } from '../bundleMode/network';
|
|
3
9
|
import { setupCallGuard } from '../callGuard';
|
|
4
10
|
import { registerReportFatalRemoteError } from '../debug/errors';
|
|
5
11
|
import { registerWorkletsError, WorkletsError } from '../debug/WorkletsError';
|
|
12
|
+
import { getStaticFeatureFlag } from '../featureFlags/featureFlags';
|
|
6
13
|
import { bundleValueUnpacker } from '../memory/bundleUnpacker';
|
|
7
14
|
import { __installUnpacker as installCustomSerializableUnpacker } from '../memory/customSerializableUnpacker';
|
|
8
15
|
import { makeShareableCloneOnUIRecursive } from '../memory/serializable';
|
|
@@ -108,7 +115,7 @@ export function init() {
|
|
|
108
115
|
|
|
109
116
|
/** A function that should be run on any kind of runtime. */
|
|
110
117
|
function initializeRuntime() {
|
|
111
|
-
if (globalThis.
|
|
118
|
+
if (globalThis._WORKLETS_BUNDLE_MODE_ENABLED) {
|
|
112
119
|
globalThis.__valueUnpacker = bundleValueUnpacker as ValueUnpacker;
|
|
113
120
|
}
|
|
114
121
|
installSynchronizableUnpacker();
|
|
@@ -133,68 +140,17 @@ function initializeRNRuntime() {
|
|
|
133
140
|
|
|
134
141
|
/** A function that should be run only on Worklet runtimes. */
|
|
135
142
|
function initializeWorkletRuntime() {
|
|
136
|
-
if (globalThis.
|
|
143
|
+
if (globalThis._WORKLETS_BUNDLE_MODE_ENABLED) {
|
|
137
144
|
setupCallGuard();
|
|
138
145
|
|
|
139
146
|
if (__DEV__) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
*/
|
|
144
|
-
const Refresh = new Proxy(
|
|
145
|
-
{},
|
|
146
|
-
{
|
|
147
|
-
get() {
|
|
148
|
-
return () => {};
|
|
149
|
-
},
|
|
150
|
-
}
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
globalThis.__r.Refresh = Refresh;
|
|
154
|
-
|
|
155
|
-
/* Gracefully handle unwanted imports from React Native. */
|
|
156
|
-
const modules = require.getModules();
|
|
157
|
-
const ReactNativeModuleId = require.resolveWeak('react-native');
|
|
158
|
-
|
|
159
|
-
const factory = function (
|
|
160
|
-
_global: unknown,
|
|
161
|
-
_require: unknown,
|
|
162
|
-
_importDefault: unknown,
|
|
163
|
-
_importAll: unknown,
|
|
164
|
-
module: Record<string, unknown>,
|
|
165
|
-
_exports: unknown,
|
|
166
|
-
_dependencyMap: unknown
|
|
167
|
-
) {
|
|
168
|
-
module.exports = new Proxy(
|
|
169
|
-
{},
|
|
170
|
-
{
|
|
171
|
-
get: function get(_target, prop) {
|
|
172
|
-
globalThis.console.warn(
|
|
173
|
-
`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.`
|
|
174
|
-
);
|
|
175
|
-
return {
|
|
176
|
-
get() {
|
|
177
|
-
return undefined;
|
|
178
|
-
},
|
|
179
|
-
};
|
|
180
|
-
},
|
|
181
|
-
}
|
|
182
|
-
);
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
const mod = {
|
|
186
|
-
dependencyMap: [],
|
|
187
|
-
factory,
|
|
188
|
-
hasError: false,
|
|
189
|
-
importedAll: {},
|
|
190
|
-
importedDefault: {},
|
|
191
|
-
isInitialized: false,
|
|
192
|
-
publicModule: {
|
|
193
|
-
exports: {},
|
|
194
|
-
},
|
|
195
|
-
};
|
|
147
|
+
silenceHMRWarnings();
|
|
148
|
+
disallowRNImports();
|
|
149
|
+
}
|
|
196
150
|
|
|
197
|
-
|
|
151
|
+
if (getStaticFeatureFlag('FETCH_PREVIEW_ENABLED')) {
|
|
152
|
+
mockTurboModuleRegistry();
|
|
153
|
+
initializeNetworking();
|
|
198
154
|
}
|
|
199
155
|
}
|
|
200
156
|
}
|
|
@@ -210,10 +166,8 @@ function installRNBindingsOnUIRuntime() {
|
|
|
210
166
|
);
|
|
211
167
|
}
|
|
212
168
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (!globalThis._WORKLETS_BUNDLE_MODE) {
|
|
216
|
-
/** In bundle mode Runtimes setup their callGuard themselves. */
|
|
169
|
+
if (!globalThis._WORKLETS_BUNDLE_MODE_ENABLED) {
|
|
170
|
+
/** In Bundle Mode Runtimes setup their callGuard themselves. */
|
|
217
171
|
runOnUISync(setupCallGuard);
|
|
218
172
|
|
|
219
173
|
/** In Bundle Mode the error is taken from the bundle. */
|
|
@@ -223,6 +177,8 @@ function installRNBindingsOnUIRuntime() {
|
|
|
223
177
|
runOnUISync(setupSerializer);
|
|
224
178
|
}
|
|
225
179
|
|
|
180
|
+
const runtimeBoundCapturableConsole = getMemorySafeCapturableConsole();
|
|
181
|
+
|
|
226
182
|
runOnUISync(() => {
|
|
227
183
|
'worklet';
|
|
228
184
|
|
|
@@ -14,14 +14,14 @@ import { init } from './initializers';
|
|
|
14
14
|
* error is caught in C++ code.
|
|
15
15
|
*
|
|
16
16
|
* This function has no effect on the RN Runtime beside setting the
|
|
17
|
-
* `
|
|
17
|
+
* `_WORKLETS_BUNDLE_MODE_ENABLED` flag.
|
|
18
18
|
*/
|
|
19
19
|
export function bundleModeInit() {
|
|
20
20
|
// Worklets Babel Plugin replaces `false` with `true` here
|
|
21
21
|
// when Bundle Mode is enabled.
|
|
22
|
-
globalThis.
|
|
22
|
+
globalThis._WORKLETS_BUNDLE_MODE_ENABLED = false;
|
|
23
23
|
|
|
24
|
-
if (!globalThis.
|
|
24
|
+
if (!globalThis._WORKLETS_BUNDLE_MODE_ENABLED) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -48,11 +48,9 @@ function getWorklet(
|
|
|
48
48
|
if (__DEV__) {
|
|
49
49
|
try {
|
|
50
50
|
worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
|
|
51
|
-
} catch (
|
|
51
|
+
} catch (e) {
|
|
52
52
|
logger.error(
|
|
53
|
-
|
|
54
|
-
workletHash +
|
|
55
|
-
'. Try reloading the app.'
|
|
53
|
+
`Unable to resolve worklet with hash ${workletHash}. Try reloading the app. Original error: ${(e as Error).message}`
|
|
56
54
|
);
|
|
57
55
|
}
|
|
58
56
|
} else {
|
|
@@ -174,7 +174,7 @@ export function createSerializable<TValue>(
|
|
|
174
174
|
return cloneArray(value, shouldPersistRemote, depth);
|
|
175
175
|
}
|
|
176
176
|
if (
|
|
177
|
-
globalThis.
|
|
177
|
+
globalThis._WORKLETS_BUNDLE_MODE_ENABLED &&
|
|
178
178
|
isFunction &&
|
|
179
179
|
(value as WorkletImport).__bundleData
|
|
180
180
|
) {
|
|
@@ -238,7 +238,7 @@ export function createSerializable<TValue>(
|
|
|
238
238
|
return inaccessibleObject(value);
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
-
if (globalThis.
|
|
241
|
+
if (globalThis._WORKLETS_BUNDLE_MODE_ENABLED) {
|
|
242
242
|
// TODO: Do it programmatically.
|
|
243
243
|
createSerializable.__bundleData = {
|
|
244
244
|
imported: 'createSerializable',
|
|
@@ -870,7 +870,7 @@ function makeShareableCloneOnUIRecursiveLEGACY<TValue>(
|
|
|
870
870
|
|
|
871
871
|
/** @deprecated This function is no longer supported. */
|
|
872
872
|
export const makeShareableCloneOnUIRecursive = (
|
|
873
|
-
globalThis.
|
|
873
|
+
globalThis._WORKLETS_BUNDLE_MODE_ENABLED
|
|
874
874
|
? createSerializable
|
|
875
875
|
: makeShareableCloneOnUIRecursiveLEGACY
|
|
876
876
|
) as typeof makeShareableCloneOnUIRecursiveLEGACY;
|
|
@@ -6,7 +6,7 @@ import { type Synchronizable, type SynchronizableRef } from './types';
|
|
|
6
6
|
export function __installUnpacker() {
|
|
7
7
|
// TODO: Add cache for synchronizables.
|
|
8
8
|
const serializer =
|
|
9
|
-
!globalThis._WORKLET || globalThis.
|
|
9
|
+
!globalThis._WORKLET || globalThis._WORKLETS_BUNDLE_MODE_ENABLED
|
|
10
10
|
? createSerializable
|
|
11
11
|
: (value: unknown) => globalThis.__serializer(value);
|
|
12
12
|
|
package/src/platformChecker.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { Platform } from 'react-native';
|
|
4
4
|
|
|
5
5
|
export const IS_JEST: boolean = !!process.env.JEST_WORKER_ID;
|
|
6
|
-
export const IS_WEB: boolean = Platform.OS === 'web';
|
|
7
|
-
export const IS_WINDOWS: boolean =
|
|
6
|
+
export const IS_WEB: boolean = /* @__PURE__ */ (() => Platform.OS === 'web')();
|
|
7
|
+
export const IS_WINDOWS: boolean = /* @__PURE__ */ (() =>
|
|
8
|
+
Platform.OS === 'windows')();
|
|
8
9
|
export const SHOULD_BE_USE_WEB: boolean = IS_JEST || IS_WEB || IS_WINDOWS;
|
package/src/privateGlobals.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ declare global {
|
|
|
19
19
|
|
|
20
20
|
var _toString: (value: unknown) => string;
|
|
21
21
|
var __workletsModuleProxy: WorkletsModuleProxy;
|
|
22
|
-
var
|
|
22
|
+
var _WORKLETS_BUNDLE_MODE_ENABLED: boolean | undefined;
|
|
23
23
|
var _WORKLETS_VERSION_CPP: string | undefined;
|
|
24
24
|
var _WORKLETS_VERSION_JS: string | undefined;
|
|
25
25
|
var _createSerializable: <T>(
|
|
@@ -84,6 +84,8 @@ declare global {
|
|
|
84
84
|
var __hasNativeState: (value: object) => boolean;
|
|
85
85
|
/** Only in Debug builds. */
|
|
86
86
|
var __isHostObject: (value: object) => boolean;
|
|
87
|
+
/** Only in Bundle Mode on Worklet Runtimes. */
|
|
88
|
+
var TurboModules: Map<string, unknown>;
|
|
87
89
|
interface NodeRequire {
|
|
88
90
|
resolveWeak(id: string): number;
|
|
89
91
|
getModules(): Map<number, unknown>;
|
package/src/runtimeKind.ts
CHANGED
|
@@ -29,6 +29,53 @@ export function getRuntimeKind(): RuntimeKind {
|
|
|
29
29
|
return globalThis.__RUNTIME_KIND;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Checks if the current runtime is the [React Native
|
|
34
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds/#rn-runtime).
|
|
35
|
+
*
|
|
36
|
+
* @returns `true` if the current runtime is the React Native Runtime, `false`
|
|
37
|
+
* otherwise.
|
|
38
|
+
*/
|
|
39
|
+
export function isRNRuntime(): boolean {
|
|
40
|
+
'worklet';
|
|
41
|
+
return globalThis.__RUNTIME_KIND === 1;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Checks if the current runtime is a [Worklet
|
|
46
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds/#worklet-runtime).
|
|
47
|
+
*
|
|
48
|
+
* @returns `true` if the current runtime is a Worklet Runtime, `false`
|
|
49
|
+
* otherwise.
|
|
50
|
+
*/
|
|
51
|
+
export function isWorkletRuntime(): boolean {
|
|
52
|
+
'worklet';
|
|
53
|
+
return globalThis.__RUNTIME_KIND !== 1;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Checks if the current runtime is the [UI
|
|
58
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds/#ui-runtime).
|
|
59
|
+
*
|
|
60
|
+
* @returns `true` if the current runtime is the UI Runtime, `false` otherwise.
|
|
61
|
+
*/
|
|
62
|
+
export function isUIRuntime(): boolean {
|
|
63
|
+
'worklet';
|
|
64
|
+
return globalThis.__RUNTIME_KIND === 2;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Checks if the current runtime is a [Worker
|
|
69
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds/#worker-runtime).
|
|
70
|
+
*
|
|
71
|
+
* @returns `true` if the current runtime is a Worker Runtime, `false`
|
|
72
|
+
* otherwise.
|
|
73
|
+
*/
|
|
74
|
+
export function isWorkerRuntime(): boolean {
|
|
75
|
+
'worklet';
|
|
76
|
+
return globalThis.__RUNTIME_KIND === 3;
|
|
77
|
+
}
|
|
78
|
+
|
|
32
79
|
if (globalThis.__RUNTIME_KIND === undefined) {
|
|
33
80
|
// In Jest environments eager imports make this file to evaluate before
|
|
34
81
|
// `initializers.ts` file, therefore we have to set the RuntimeKind here,
|
package/src/runtimes.native.ts
CHANGED
|
@@ -123,8 +123,8 @@ export function createWorkletRuntime(
|
|
|
123
123
|
* or another [Worker
|
|
124
124
|
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worker-runtime),
|
|
125
125
|
* unless the [Bundle
|
|
126
|
-
* Mode](https://docs.swmansion.com/react-native-worklets/docs/
|
|
127
|
-
*
|
|
126
|
+
* Mode](https://docs.swmansion.com/react-native-worklets/docs/bundleMode/) is
|
|
127
|
+
* enabled.
|
|
128
128
|
*
|
|
129
129
|
* @param workletRuntime - The runtime to schedule the worklet on.
|
|
130
130
|
* @param worklet - The worklet to schedule.
|
|
@@ -198,3 +198,42 @@ export function runOnRuntime<Args extends unknown[], ReturnValue>(
|
|
|
198
198
|
type WorkletRuntimeConfigInternal = WorkletRuntimeConfig & {
|
|
199
199
|
initializer?: WorkletFunction<[], void>;
|
|
200
200
|
};
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Lets you run a function synchronously on a [Worker
|
|
204
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worker-runtime).
|
|
205
|
+
*
|
|
206
|
+
* - This function cannot be called from the [UI
|
|
207
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
|
208
|
+
* or another [Worker
|
|
209
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worker-runtime),
|
|
210
|
+
* unless the [Bundle
|
|
211
|
+
* Mode](https://docs.swmansion.com/react-native-worklets/docs/bundleMode/) is
|
|
212
|
+
* enabled.
|
|
213
|
+
*
|
|
214
|
+
* @param workletRuntime - The runtime to run the worklet on.
|
|
215
|
+
* @param worklet - The worklet to run.
|
|
216
|
+
* @param args - The arguments to pass to the worklet.
|
|
217
|
+
* @returns The return value of the worklet.
|
|
218
|
+
*/
|
|
219
|
+
export function runOnRuntimeSync<Args extends unknown[], ReturnValue>(
|
|
220
|
+
workletRuntime: WorkletRuntime,
|
|
221
|
+
worklet: (...args: Args) => ReturnValue,
|
|
222
|
+
...args: Args
|
|
223
|
+
): ReturnValue {
|
|
224
|
+
'worklet';
|
|
225
|
+
if (__DEV__ && !isWorkletFunction(worklet)) {
|
|
226
|
+
throw new WorkletsError(
|
|
227
|
+
'The function passed to `runOnRuntimeSync` is not a worklet.'
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return WorkletsModule.runOnRuntimeSync(
|
|
232
|
+
workletRuntime,
|
|
233
|
+
createSerializable(() => {
|
|
234
|
+
'worklet';
|
|
235
|
+
const result = worklet(...args);
|
|
236
|
+
return makeShareableCloneOnUIRecursive(result);
|
|
237
|
+
})
|
|
238
|
+
);
|
|
239
|
+
}
|
package/src/runtimes.ts
CHANGED
|
@@ -38,3 +38,13 @@ export function scheduleOnRuntime<Args extends unknown[], ReturnValue>(
|
|
|
38
38
|
export function scheduleOnRuntime(): never {
|
|
39
39
|
throw new WorkletsError('`scheduleOnRuntime` is not supported on web.');
|
|
40
40
|
}
|
|
41
|
+
|
|
42
|
+
export function runOnRuntimeSync<Args extends unknown[], ReturnValue>(
|
|
43
|
+
workletRuntime: WorkletRuntime,
|
|
44
|
+
worklet: (...args: Args) => ReturnValue,
|
|
45
|
+
...args: Args
|
|
46
|
+
): ReturnValue;
|
|
47
|
+
|
|
48
|
+
export function runOnRuntimeSync(): never {
|
|
49
|
+
throw new WorkletsError('`runOnRuntimeSync` is not supported on web.');
|
|
50
|
+
}
|
package/src/threads.native.ts
CHANGED
|
@@ -66,7 +66,7 @@ export const callMicrotasks = callMicrotasksOnUIThread;
|
|
|
66
66
|
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime)
|
|
67
67
|
* or a [Worker
|
|
68
68
|
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worker-runtime),
|
|
69
|
-
* unless you have the [Bundle Mode](/docs/
|
|
69
|
+
* unless you have the [Bundle Mode](/docs/bundleMode/) enabled.
|
|
70
70
|
*
|
|
71
71
|
* @param fun - A reference to a function you want to schedule on the [UI
|
|
72
72
|
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
|
@@ -187,7 +187,7 @@ export function runOnUISync<Args extends unknown[], ReturnValue>(
|
|
|
187
187
|
worklet: WorkletFunction<Args, ReturnValue>,
|
|
188
188
|
...args: Args
|
|
189
189
|
): ReturnValue {
|
|
190
|
-
return WorkletsModule.
|
|
190
|
+
return WorkletsModule.runOnUISync(
|
|
191
191
|
createSerializable(() => {
|
|
192
192
|
'worklet';
|
|
193
193
|
const result = worklet(...args);
|