react-native-worklets 0.8.0-rc.0 → 0.8.0
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/Common/cpp/worklets/Compat/StableApi.cpp +121 -0
- package/Common/cpp/worklets/Compat/StableApi.h +109 -0
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +14 -14
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +10 -7
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +5 -14
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +3 -5
- package/Common/cpp/worklets/SharedItems/Serializable.h +1 -43
- package/Common/cpp/worklets/Tools/Defs.h +2 -7
- package/Common/cpp/worklets/Tools/ScriptBuffer.h +1 -1
- package/Common/cpp/worklets/WorkletRuntime/BundleModeConfig.h +17 -0
- package/Common/cpp/worklets/WorkletRuntime/HermesProfiling.cpp +73 -0
- package/Common/cpp/worklets/WorkletRuntime/HermesProfiling.h +12 -0
- package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +20 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeBindings.h +2 -2
- package/Common/cpp/worklets/WorkletRuntime/RuntimeData.h +0 -4
- package/Common/cpp/worklets/WorkletRuntime/RuntimeHolder.h +0 -3
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +27 -17
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +12 -3
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +74 -2
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +0 -4
- package/RNWorklets.podspec +1 -2
- package/android/CMakeLists.txt +1 -4
- package/android/build.gradle +0 -3
- package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.cpp +1 -1
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.cpp +2 -2
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.h +2 -2
- package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +28 -18
- package/android/src/main/cpp/worklets/android/WorkletsModule.h +6 -5
- package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +2 -2
- package/android/src/networking/com/swmansion/worklets/WorkletsModule.java +4 -2
- package/android/src/no-networking/com/swmansion/worklets/WorkletsModule.java +4 -2
- package/apple/worklets/apple/Networking/WorkletsNetworking.h +5 -2
- package/apple/worklets/apple/Networking/WorkletsNetworking.mm +3 -2
- package/apple/worklets/apple/WorkletsModule.mm +40 -26
- package/compatibility.json +2 -2
- package/lib/module/WorkletsModule/NativeWorklets.native.js +3 -2
- package/lib/module/WorkletsModule/NativeWorklets.native.js.map +1 -1
- package/lib/module/debug/jsVersion.js +1 -1
- package/lib/module/debug/jsVersion.js.map +1 -1
- package/lib/module/featureFlags/staticFlags.json +0 -1
- package/lib/module/featureFlags/types.js +0 -1
- package/lib/module/featureFlags/types.js.map +1 -1
- package/lib/module/memory/serializable.native.js +14 -5
- package/lib/module/memory/serializable.native.js.map +1 -1
- package/lib/module/memory/shareable.js +15 -0
- package/lib/module/memory/shareable.js.map +1 -1
- package/lib/module/memory/shareable.native.js +15 -0
- package/lib/module/memory/shareable.native.js.map +1 -1
- package/lib/module/runtimeKind.js +2 -0
- package/lib/module/runtimeKind.js.map +1 -1
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts.map +1 -1
- 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 +0 -1
- package/lib/typescript/featureFlags/types.d.ts.map +1 -1
- package/lib/typescript/memory/serializable.native.d.ts.map +1 -1
- package/lib/typescript/memory/shareable.d.ts +16 -2
- package/lib/typescript/memory/shareable.d.ts.map +1 -1
- package/lib/typescript/memory/shareable.native.d.ts +16 -2
- package/lib/typescript/memory/shareable.native.d.ts.map +1 -1
- package/lib/typescript/memory/types.d.ts +42 -0
- package/lib/typescript/memory/types.d.ts.map +1 -1
- package/lib/typescript/specs/NativeWorkletsModule.d.ts +1 -1
- package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -1
- package/package.json +16 -15
- package/scripts/worklets_utils.rb +0 -2
- package/src/WorkletsModule/NativeWorklets.native.ts +3 -2
- package/src/debug/jsVersion.ts +1 -1
- package/src/featureFlags/staticFlags.json +0 -1
- package/src/featureFlags/types.ts +0 -1
- package/src/memory/serializable.native.ts +16 -10
- package/src/memory/shareable.native.ts +16 -2
- package/src/memory/shareable.ts +16 -2
- package/src/memory/types.ts +42 -0
- package/src/privateGlobals.d.ts +4 -0
- package/src/runtimeKind.ts +1 -0
- package/src/specs/NativeWorkletsModule.ts +1 -1
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import type { UIRuntimeId } from '../runtimes';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Shareable, ShareableConfig } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new {@link Shareable} holding the provided initial value. You must
|
|
5
|
+
* explicitly declare which Worklet Runtime will host the Shareable by passing
|
|
6
|
+
* its `runtimeId`.
|
|
7
|
+
*
|
|
8
|
+
* Currently only hosting a Shareable on the UI Runtime is supported.
|
|
9
|
+
*
|
|
10
|
+
* @param hostRuntimeId - The `runtimeId` of the Worklet Runtime that will host
|
|
11
|
+
* the Shareable. Use {@link UIRuntimeId}.
|
|
12
|
+
* @param initial - The initial value of the Shareable.
|
|
13
|
+
* @param config - Optional advanced configuration.
|
|
14
|
+
* @returns The created {@link Shareable}.
|
|
15
|
+
* @see {@link https://docs.swmansion.com/react-native-worklets/docs/memory/createShareable | createShareable docs}
|
|
16
|
+
*/
|
|
3
17
|
export declare function createShareable<TValue = unknown, THostDecorated = unknown, TGuestDecorated = unknown>(hostRuntimeId: typeof UIRuntimeId, initial: TValue, config?: ShareableConfig<TValue, THostDecorated, TGuestDecorated>): Shareable<TValue, THostDecorated, TGuestDecorated>;
|
|
4
18
|
/**
|
|
5
19
|
* @deprecated Only UI host runtime is supported now. Use {@link UIRuntimeId} as
|
|
6
20
|
* the `hostRuntimeId` argument.
|
|
7
21
|
*/
|
|
8
|
-
export declare function createShareable<TValue = unknown, THostDecorated = unknown, TGuestDecorated = unknown>(hostRuntimeId: number, initial:
|
|
22
|
+
export declare function createShareable<TValue = unknown, THostDecorated = unknown, TGuestDecorated = unknown>(hostRuntimeId: number, initial: TValue, config?: ShareableConfig<TValue, THostDecorated, TGuestDecorated>): Shareable<TValue, THostDecorated, TGuestDecorated>;
|
|
9
23
|
//# sourceMappingURL=shareable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shareable.d.ts","sourceRoot":"","sources":["../../../src/memory/shareable.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"shareable.d.ts","sourceRoot":"","sources":["../../../src/memory/shareable.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC7B,MAAM,GAAG,OAAO,EAChB,cAAc,GAAG,OAAO,EACxB,eAAe,GAAG,OAAO,EAEzB,aAAa,EAAE,OAAO,WAAW,EACjC,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,eAAe,CAAC,MAAM,EAAE,cAAc,EAAE,eAAe,CAAC,GAChE,SAAS,CAAC,MAAM,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC;AAEtD;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,MAAM,GAAG,OAAO,EAChB,cAAc,GAAG,OAAO,EACxB,eAAe,GAAG,OAAO,EAEzB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,eAAe,CAAC,MAAM,EAAE,cAAc,EAAE,eAAe,CAAC,GAChE,SAAS,CAAC,MAAM,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC"}
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import { UIRuntimeId } from '../runtimes';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Shareable, ShareableConfig } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new {@link Shareable} holding the provided initial value. You must
|
|
5
|
+
* explicitly declare which Worklet Runtime will host the Shareable by passing
|
|
6
|
+
* its `runtimeId`.
|
|
7
|
+
*
|
|
8
|
+
* Currently only hosting a Shareable on the UI Runtime is supported.
|
|
9
|
+
*
|
|
10
|
+
* @param hostRuntimeId - The `runtimeId` of the Worklet Runtime that will host
|
|
11
|
+
* the Shareable. Use {@link UIRuntimeId}.
|
|
12
|
+
* @param initial - The initial value of the Shareable.
|
|
13
|
+
* @param config - Optional advanced configuration.
|
|
14
|
+
* @returns The created {@link Shareable}.
|
|
15
|
+
* @see {@link https://docs.swmansion.com/react-native-worklets/docs/memory/createShareable | createShareable docs}
|
|
16
|
+
*/
|
|
3
17
|
export declare function createShareable<TValue = unknown, THostDecorated = unknown, TGuestDecorated = unknown>(hostRuntimeId: typeof UIRuntimeId, initial: TValue, config?: ShareableConfig<TValue, THostDecorated, TGuestDecorated>): Shareable<TValue, THostDecorated, TGuestDecorated>;
|
|
4
18
|
/**
|
|
5
19
|
* @deprecated Only UI host runtime is supported now. Use {@link UIRuntimeId} as
|
|
6
20
|
* the `hostRuntimeId` argument.
|
|
7
21
|
*/
|
|
8
|
-
export declare function createShareable<TValue = unknown, THostDecorated = unknown, TGuestDecorated = unknown>(hostRuntimeId: number, initial:
|
|
22
|
+
export declare function createShareable<TValue = unknown, THostDecorated = unknown, TGuestDecorated = unknown>(hostRuntimeId: number, initial: TValue, config?: ShareableConfig<TValue, THostDecorated, TGuestDecorated>): Shareable<TValue, THostDecorated, TGuestDecorated>;
|
|
9
23
|
//# sourceMappingURL=shareable.native.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shareable.native.d.ts","sourceRoot":"","sources":["../../../src/memory/shareable.native.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI1C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"shareable.native.d.ts","sourceRoot":"","sources":["../../../src/memory/shareable.native.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI1C,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC7B,MAAM,GAAG,OAAO,EAChB,cAAc,GAAG,OAAO,EACxB,eAAe,GAAG,OAAO,EAEzB,aAAa,EAAE,OAAO,WAAW,EACjC,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,eAAe,CAAC,MAAM,EAAE,cAAc,EAAE,eAAe,CAAC,GAChE,SAAS,CAAC,MAAM,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC;AAEtD;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,MAAM,GAAG,OAAO,EAChB,cAAc,GAAG,OAAO,EACxB,eAAe,GAAG,OAAO,EAEzB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,eAAe,CAAC,MAAM,EAAE,cAAc,EAAE,eAAe,CAAC,GAChE,SAAS,CAAC,MAAM,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC"}
|
|
@@ -67,6 +67,11 @@ export type ShareableHostMeta = {
|
|
|
67
67
|
isHost: true;
|
|
68
68
|
__shareableRef: true;
|
|
69
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* A worklet that takes the created {@link ShareableHost} and decorates it with
|
|
72
|
+
* additional properties or methods. It must return the same reference it
|
|
73
|
+
* received.
|
|
74
|
+
*/
|
|
70
75
|
export type ShareableHostDecorator<TValue = unknown, TDecorated = unknown> = (shareable: ShareableHost<TValue> & TDecorated) => ShareableHost<TValue> & TDecorated;
|
|
71
76
|
export type ShareableGuestMeta = {
|
|
72
77
|
isHost: false;
|
|
@@ -78,13 +83,50 @@ export type ShareableGuestProps<TValue = unknown> = {
|
|
|
78
83
|
setAsync(value: TValue | ((prev: TValue) => TValue)): void;
|
|
79
84
|
setSync(value: TValue | ((prev: TValue) => TValue)): void;
|
|
80
85
|
};
|
|
86
|
+
/**
|
|
87
|
+
* A worklet that decorates each {@link ShareableGuest} created for the Shareable
|
|
88
|
+
* with additional properties or methods. It must return the same reference it
|
|
89
|
+
* received.
|
|
90
|
+
*/
|
|
81
91
|
export type ShareableGuestDecorator<TValue = unknown, TDecorated = unknown> = (shareable: ShareableGuest<TValue> & TDecorated) => ShareableGuest<TValue> & TDecorated;
|
|
92
|
+
/**
|
|
93
|
+
* The host-side representation of a {@link Shareable}, living on the
|
|
94
|
+
* {@link https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worklet-runtime | Worklet Runtime}
|
|
95
|
+
* that hosts the Shareable.
|
|
96
|
+
*/
|
|
82
97
|
export type ShareableHost<TValue = unknown, THostDecorated = unknown> = ShareableHostMeta & ShareableHostProps<TValue> & (THostDecorated extends object ? THostDecorated : object);
|
|
98
|
+
/**
|
|
99
|
+
* A guest-side representation of a {@link Shareable}, used on any runtime other
|
|
100
|
+
* than the host runtime.
|
|
101
|
+
*/
|
|
83
102
|
export type ShareableGuest<TValue = unknown, TGuestDecorated = unknown> = ShareableGuestMeta & ShareableGuestProps<TValue> & (TGuestDecorated extends object ? TGuestDecorated : object);
|
|
103
|
+
/**
|
|
104
|
+
* A type of shared memory tied to a given runtime, called the Host Runtime.
|
|
105
|
+
* Depending on the context it's either a {@link ShareableHost} (on the hosting
|
|
106
|
+
* Worklet Runtime) or a {@link ShareableGuest} (on every other runtime).
|
|
107
|
+
*
|
|
108
|
+
* @see {@link https://docs.swmansion.com/react-native-worklets/docs/memory/shareable | Shareable docs}
|
|
109
|
+
*/
|
|
84
110
|
export type Shareable<TValue = unknown, THostDecorated = unknown, TGuestDecorated = unknown> = (ShareableHost<TValue, THostDecorated> & Partial<ShareableGuestProps<TValue> & (TGuestDecorated extends object ? Partial<TGuestDecorated> : object)>) | (ShareableGuest<TValue, TGuestDecorated> & Partial<ShareableHostProps<TValue> & (THostDecorated extends object ? Partial<THostDecorated> : object)>);
|
|
111
|
+
/** Optional advanced configuration for a {@link Shareable}. */
|
|
85
112
|
export type ShareableConfig<TValue, THostDecorated, TGuestDecorated> = {
|
|
113
|
+
/**
|
|
114
|
+
* A worklet that decorates the {@link ShareableHost} with additional
|
|
115
|
+
* properties or methods.
|
|
116
|
+
*/
|
|
86
117
|
hostDecorator?: ShareableHostDecorator<TValue, THostDecorated>;
|
|
118
|
+
/**
|
|
119
|
+
* A worklet that decorates each {@link ShareableGuest} with additional
|
|
120
|
+
* properties or methods.
|
|
121
|
+
*/
|
|
87
122
|
guestDecorator?: ShareableGuestDecorator<TValue, TGuestDecorated>;
|
|
123
|
+
/**
|
|
124
|
+
* When `true`, the {@link ShareableHost} is created synchronously during the
|
|
125
|
+
* call to `createShareable` instead of lazily on first access. Use this when
|
|
126
|
+
* the host initialization triggers side effects that must happen eagerly.
|
|
127
|
+
*
|
|
128
|
+
* @defaultValue `false`
|
|
129
|
+
*/
|
|
88
130
|
initSynchronously?: boolean;
|
|
89
131
|
};
|
|
90
132
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/memory/types.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,CAAC,MAAM,GAAG,OAAO,IAAI;IAC9C,iBAAiB,EAAE,IAAI,CAAC;IACxB,8BAA8B,EAAE,MAAM,CAAC;CAC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,CAAC;CAC7B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeWorkletsModule.d.ts","sourceRoot":"","sources":["../../../src/specs/NativeWorkletsModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,WAAW,EAAuB,MAAM,cAAc,CAAC;AAErE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"NativeWorkletsModule.d.ts","sourceRoot":"","sources":["../../../src/specs/NativeWorkletsModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,WAAW,EAAuB,MAAM,cAAc,CAAC;AAErE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,kBAAkB,EAAE,CAAC,iBAAiB,EAAE,OAAO,KAAK,OAAO,CAAC;CAC7D;;AAED,wBAA+D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-worklets",
|
|
3
|
-
"version": "0.8.0
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "The React Native multithreading library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
"type:check:app": "yarn workspace common-app type:check",
|
|
38
38
|
"type:check:plugin": "yarn workspace babel-plugin-worklets type:check",
|
|
39
39
|
"type:check:tests": "../../scripts/test-ts.sh __typetests__",
|
|
40
|
-
"tree-shake:check:web": "yarn is-tree-shakable --resolution web"
|
|
40
|
+
"tree-shake:check:web": "yarn is-tree-shakable --resolution web",
|
|
41
|
+
"validate-peers": "node ../../scripts/validate-compatibility-peer-dependencies.js"
|
|
41
42
|
},
|
|
42
43
|
"repository": {
|
|
43
44
|
"type": "git",
|
|
@@ -54,21 +55,20 @@
|
|
|
54
55
|
"@babel/core": "*",
|
|
55
56
|
"@react-native/metro-config": "*",
|
|
56
57
|
"react": "*",
|
|
57
|
-
"react-native": "
|
|
58
|
+
"react-native": "0.81 - 0.85"
|
|
58
59
|
},
|
|
59
60
|
"dependencies": {
|
|
60
|
-
"@babel/plugin-transform-arrow-functions": "7.27.1",
|
|
61
|
-
"@babel/plugin-transform-class-properties": "7.27.1",
|
|
62
|
-
"@babel/plugin-transform-classes": "7.28.4",
|
|
63
|
-
"@babel/plugin-transform-nullish-coalescing-operator": "7.27.1",
|
|
64
|
-
"@babel/plugin-transform-optional-chaining": "7.27.1",
|
|
65
|
-
"@babel/plugin-transform-shorthand-properties": "7.27.1",
|
|
66
|
-
"@babel/plugin-transform-template-literals": "7.27.1",
|
|
67
|
-
"@babel/plugin-transform-unicode-regex": "7.27.1",
|
|
68
|
-
"@babel/preset-typescript": "7.27.1",
|
|
69
|
-
"convert-source-map": "2.0.0",
|
|
70
|
-
"
|
|
71
|
-
"semver": "7.7.3"
|
|
61
|
+
"@babel/plugin-transform-arrow-functions": "^7.27.1",
|
|
62
|
+
"@babel/plugin-transform-class-properties": "^7.27.1",
|
|
63
|
+
"@babel/plugin-transform-classes": "^7.28.4",
|
|
64
|
+
"@babel/plugin-transform-nullish-coalescing-operator": "^7.27.1",
|
|
65
|
+
"@babel/plugin-transform-optional-chaining": "^7.27.1",
|
|
66
|
+
"@babel/plugin-transform-shorthand-properties": "^7.27.1",
|
|
67
|
+
"@babel/plugin-transform-template-literals": "^7.27.1",
|
|
68
|
+
"@babel/plugin-transform-unicode-regex": "^7.27.1",
|
|
69
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
70
|
+
"convert-source-map": "^2.0.0",
|
|
71
|
+
"semver": "^7.7.3"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@babel/cli": "7.28.3",
|
|
@@ -82,6 +82,7 @@
|
|
|
82
82
|
"clang-format-node": "1.3.5",
|
|
83
83
|
"code-tag": "1.2.0",
|
|
84
84
|
"eslint": "9.37.0",
|
|
85
|
+
"is-tree-shakable": "^0.5.0",
|
|
85
86
|
"jest": "30.2.0",
|
|
86
87
|
"knip": "5.61.3",
|
|
87
88
|
"madge": "8.0.0",
|
|
@@ -8,7 +8,6 @@ end
|
|
|
8
8
|
|
|
9
9
|
def worklets_find_config()
|
|
10
10
|
result = {
|
|
11
|
-
:bundle_mode_flag => nil,
|
|
12
11
|
:feature_flags_flag => nil,
|
|
13
12
|
:fetch_preview_flag => nil,
|
|
14
13
|
:is_reanimated_example_app => nil,
|
|
@@ -48,7 +47,6 @@ def worklets_find_config()
|
|
|
48
47
|
|
|
49
48
|
feature_flags = worklets_get_static_feature_flags()
|
|
50
49
|
result[:feature_flags_flag] = worklets_get_static_feature_flags_flag(feature_flags)
|
|
51
|
-
result[:bundle_mode_flag] = worklets_get_flag_from_feature_flags(feature_flags, 'BUNDLE_MODE_ENABLED')
|
|
52
50
|
result[:fetch_preview_flag] = worklets_get_flag_from_feature_flags(feature_flags, 'FETCH_PREVIEW_ENABLED')
|
|
53
51
|
|
|
54
52
|
return result
|
|
@@ -20,13 +20,14 @@ class NativeWorklets implements IWorkletsModule {
|
|
|
20
20
|
#serializableFalse: SerializableRef<boolean>;
|
|
21
21
|
|
|
22
22
|
constructor() {
|
|
23
|
+
const bundleModeEnabled = globalThis._WORKLETS_BUNDLE_MODE_ENABLED ?? false;
|
|
23
24
|
globalThis._WORKLETS_VERSION_JS = jsVersion;
|
|
24
25
|
if (
|
|
25
26
|
global.__workletsModuleProxy === undefined &&
|
|
26
27
|
globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative
|
|
27
28
|
) {
|
|
28
|
-
WorkletsTurboModule?.installTurboModule();
|
|
29
|
-
if (__DEV__ &&
|
|
29
|
+
WorkletsTurboModule?.installTurboModule(bundleModeEnabled);
|
|
30
|
+
if (__DEV__ && bundleModeEnabled) {
|
|
30
31
|
console.log(
|
|
31
32
|
'[Worklets] Bundle mode initialization: Downloaded the bundle for Worklet Runtimes.'
|
|
32
33
|
);
|
package/src/debug/jsVersion.ts
CHANGED
|
@@ -21,7 +21,6 @@ export type DynamicFlagName = keyof Omit<
|
|
|
21
21
|
*/
|
|
22
22
|
export const DefaultStaticFeatureFlags = {
|
|
23
23
|
RUNTIME_TEST_FLAG: false,
|
|
24
|
-
BUNDLE_MODE_ENABLED: false,
|
|
25
24
|
FETCH_PREVIEW_ENABLED: false,
|
|
26
25
|
IOS_DYNAMIC_FRAMERATE_ENABLED: true,
|
|
27
26
|
} as const satisfies typeof StaticFeatureFlagsJSON;
|
|
@@ -173,15 +173,21 @@ export function createSerializable<TValue>(
|
|
|
173
173
|
if (Array.isArray(value)) {
|
|
174
174
|
return cloneArray(value, shouldPersistRemote, depth);
|
|
175
175
|
}
|
|
176
|
-
if (
|
|
177
|
-
globalThis._WORKLETS_BUNDLE_MODE_ENABLED
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
176
|
+
if (isFunction) {
|
|
177
|
+
if (globalThis._WORKLETS_BUNDLE_MODE_ENABLED) {
|
|
178
|
+
if ((value as RemoteFunction).__remoteFunction) {
|
|
179
|
+
// Remote functions are already serialized.
|
|
180
|
+
return (value as RemoteFunction)
|
|
181
|
+
.__remoteFunction as SerializableRef<TValue>;
|
|
182
|
+
}
|
|
183
|
+
if ((value as WorkletImport).__bundleData) {
|
|
184
|
+
return cloneImport(value as WorkletImport) as SerializableRef<TValue>;
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
if (!isWorkletFunction(value)) {
|
|
188
|
+
return cloneRemoteFunction(value);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
185
191
|
}
|
|
186
192
|
// RN has introduced a new representation of TurboModules as a JS object whose prototype is the host object
|
|
187
193
|
// More details: https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp#L182
|
|
@@ -732,7 +738,7 @@ function getWorkletCode(value: WorkletFunction) {
|
|
|
732
738
|
return code;
|
|
733
739
|
}
|
|
734
740
|
|
|
735
|
-
type RemoteFunction<TValue> = {
|
|
741
|
+
type RemoteFunction<TValue = unknown> = {
|
|
736
742
|
__remoteFunction: FlatSerializableRef<TValue>;
|
|
737
743
|
};
|
|
738
744
|
|
|
@@ -6,8 +6,22 @@ import { UIRuntimeId } from '../runtimes';
|
|
|
6
6
|
import { isWorkletFunction } from '../workletFunction';
|
|
7
7
|
import { WorkletsModule } from '../WorkletsModule/NativeWorklets';
|
|
8
8
|
import { createSerializable } from './serializable';
|
|
9
|
-
import type {
|
|
9
|
+
import type { Shareable, ShareableConfig } from './types';
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new {@link Shareable} holding the provided initial value. You must
|
|
13
|
+
* explicitly declare which Worklet Runtime will host the Shareable by passing
|
|
14
|
+
* its `runtimeId`.
|
|
15
|
+
*
|
|
16
|
+
* Currently only hosting a Shareable on the UI Runtime is supported.
|
|
17
|
+
*
|
|
18
|
+
* @param hostRuntimeId - The `runtimeId` of the Worklet Runtime that will host
|
|
19
|
+
* the Shareable. Use {@link UIRuntimeId}.
|
|
20
|
+
* @param initial - The initial value of the Shareable.
|
|
21
|
+
* @param config - Optional advanced configuration.
|
|
22
|
+
* @returns The created {@link Shareable}.
|
|
23
|
+
* @see {@link https://docs.swmansion.com/react-native-worklets/docs/memory/createShareable | createShareable docs}
|
|
24
|
+
*/
|
|
11
25
|
export function createShareable<
|
|
12
26
|
TValue = unknown,
|
|
13
27
|
THostDecorated = unknown,
|
|
@@ -28,7 +42,7 @@ export function createShareable<
|
|
|
28
42
|
TGuestDecorated = unknown,
|
|
29
43
|
>(
|
|
30
44
|
hostRuntimeId: number,
|
|
31
|
-
initial:
|
|
45
|
+
initial: TValue,
|
|
32
46
|
config?: ShareableConfig<TValue, THostDecorated, TGuestDecorated>
|
|
33
47
|
): Shareable<TValue, THostDecorated, TGuestDecorated>;
|
|
34
48
|
|
package/src/memory/shareable.ts
CHANGED
|
@@ -2,8 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
import { WorkletsError } from '../debug/WorkletsError';
|
|
4
4
|
import type { UIRuntimeId } from '../runtimes';
|
|
5
|
-
import type {
|
|
5
|
+
import type { Shareable, ShareableConfig } from './types';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new {@link Shareable} holding the provided initial value. You must
|
|
9
|
+
* explicitly declare which Worklet Runtime will host the Shareable by passing
|
|
10
|
+
* its `runtimeId`.
|
|
11
|
+
*
|
|
12
|
+
* Currently only hosting a Shareable on the UI Runtime is supported.
|
|
13
|
+
*
|
|
14
|
+
* @param hostRuntimeId - The `runtimeId` of the Worklet Runtime that will host
|
|
15
|
+
* the Shareable. Use {@link UIRuntimeId}.
|
|
16
|
+
* @param initial - The initial value of the Shareable.
|
|
17
|
+
* @param config - Optional advanced configuration.
|
|
18
|
+
* @returns The created {@link Shareable}.
|
|
19
|
+
* @see {@link https://docs.swmansion.com/react-native-worklets/docs/memory/createShareable | createShareable docs}
|
|
20
|
+
*/
|
|
7
21
|
export function createShareable<
|
|
8
22
|
TValue = unknown,
|
|
9
23
|
THostDecorated = unknown,
|
|
@@ -24,7 +38,7 @@ export function createShareable<
|
|
|
24
38
|
TGuestDecorated = unknown,
|
|
25
39
|
>(
|
|
26
40
|
hostRuntimeId: number,
|
|
27
|
-
initial:
|
|
41
|
+
initial: TValue,
|
|
28
42
|
config?: ShareableConfig<TValue, THostDecorated, TGuestDecorated>
|
|
29
43
|
): Shareable<TValue, THostDecorated, TGuestDecorated>;
|
|
30
44
|
|
package/src/memory/types.ts
CHANGED
|
@@ -87,6 +87,11 @@ export type ShareableHostMeta = {
|
|
|
87
87
|
__shareableRef: true;
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
+
/**
|
|
91
|
+
* A worklet that takes the created {@link ShareableHost} and decorates it with
|
|
92
|
+
* additional properties or methods. It must return the same reference it
|
|
93
|
+
* received.
|
|
94
|
+
*/
|
|
90
95
|
export type ShareableHostDecorator<TValue = unknown, TDecorated = unknown> = (
|
|
91
96
|
shareable: ShareableHost<TValue> & TDecorated
|
|
92
97
|
) => ShareableHost<TValue> & TDecorated;
|
|
@@ -103,10 +108,20 @@ export type ShareableGuestProps<TValue = unknown> = {
|
|
|
103
108
|
setSync(value: TValue | ((prev: TValue) => TValue)): void;
|
|
104
109
|
};
|
|
105
110
|
|
|
111
|
+
/**
|
|
112
|
+
* A worklet that decorates each {@link ShareableGuest} created for the Shareable
|
|
113
|
+
* with additional properties or methods. It must return the same reference it
|
|
114
|
+
* received.
|
|
115
|
+
*/
|
|
106
116
|
export type ShareableGuestDecorator<TValue = unknown, TDecorated = unknown> = (
|
|
107
117
|
shareable: ShareableGuest<TValue> & TDecorated
|
|
108
118
|
) => ShareableGuest<TValue> & TDecorated;
|
|
109
119
|
|
|
120
|
+
/**
|
|
121
|
+
* The host-side representation of a {@link Shareable}, living on the
|
|
122
|
+
* {@link https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worklet-runtime | Worklet Runtime}
|
|
123
|
+
* that hosts the Shareable.
|
|
124
|
+
*/
|
|
110
125
|
export type ShareableHost<
|
|
111
126
|
TValue = unknown,
|
|
112
127
|
THostDecorated = unknown,
|
|
@@ -114,6 +129,10 @@ export type ShareableHost<
|
|
|
114
129
|
ShareableHostProps<TValue> &
|
|
115
130
|
(THostDecorated extends object ? THostDecorated : object);
|
|
116
131
|
|
|
132
|
+
/**
|
|
133
|
+
* A guest-side representation of a {@link Shareable}, used on any runtime other
|
|
134
|
+
* than the host runtime.
|
|
135
|
+
*/
|
|
117
136
|
export type ShareableGuest<
|
|
118
137
|
TValue = unknown,
|
|
119
138
|
TGuestDecorated = unknown,
|
|
@@ -121,6 +140,13 @@ export type ShareableGuest<
|
|
|
121
140
|
ShareableGuestProps<TValue> &
|
|
122
141
|
(TGuestDecorated extends object ? TGuestDecorated : object);
|
|
123
142
|
|
|
143
|
+
/**
|
|
144
|
+
* A type of shared memory tied to a given runtime, called the Host Runtime.
|
|
145
|
+
* Depending on the context it's either a {@link ShareableHost} (on the hosting
|
|
146
|
+
* Worklet Runtime) or a {@link ShareableGuest} (on every other runtime).
|
|
147
|
+
*
|
|
148
|
+
* @see {@link https://docs.swmansion.com/react-native-worklets/docs/memory/shareable | Shareable docs}
|
|
149
|
+
*/
|
|
124
150
|
export type Shareable<
|
|
125
151
|
TValue = unknown,
|
|
126
152
|
THostDecorated = unknown,
|
|
@@ -137,8 +163,24 @@ export type Shareable<
|
|
|
137
163
|
(THostDecorated extends object ? Partial<THostDecorated> : object)
|
|
138
164
|
>);
|
|
139
165
|
|
|
166
|
+
/** Optional advanced configuration for a {@link Shareable}. */
|
|
140
167
|
export type ShareableConfig<TValue, THostDecorated, TGuestDecorated> = {
|
|
168
|
+
/**
|
|
169
|
+
* A worklet that decorates the {@link ShareableHost} with additional
|
|
170
|
+
* properties or methods.
|
|
171
|
+
*/
|
|
141
172
|
hostDecorator?: ShareableHostDecorator<TValue, THostDecorated>;
|
|
173
|
+
/**
|
|
174
|
+
* A worklet that decorates each {@link ShareableGuest} with additional
|
|
175
|
+
* properties or methods.
|
|
176
|
+
*/
|
|
142
177
|
guestDecorator?: ShareableGuestDecorator<TValue, TGuestDecorated>;
|
|
178
|
+
/**
|
|
179
|
+
* When `true`, the {@link ShareableHost} is created synchronously during the
|
|
180
|
+
* call to `createShareable` instead of lazily on first access. Use this when
|
|
181
|
+
* the host initialization triggers side effects that must happen eagerly.
|
|
182
|
+
*
|
|
183
|
+
* @defaultValue `false`
|
|
184
|
+
*/
|
|
143
185
|
initSynchronously?: boolean;
|
|
144
186
|
};
|
package/src/privateGlobals.d.ts
CHANGED
|
@@ -73,6 +73,10 @@ declare global {
|
|
|
73
73
|
var __flushAnimationFrame: (timestamp: number) => void;
|
|
74
74
|
var __frameTimestamp: number | undefined;
|
|
75
75
|
var _log: (value: unknown) => void;
|
|
76
|
+
var _startProfiling: (meanHzFreq?: number) => void;
|
|
77
|
+
var _stopProfiling: () => string;
|
|
78
|
+
var _beginSection: (name: string) => void;
|
|
79
|
+
var _endSection: () => void;
|
|
76
80
|
var _getAnimationTimestamp: () => number;
|
|
77
81
|
var _scheduleOnRuntime: (
|
|
78
82
|
runtime: WorkletRuntime,
|
package/src/runtimeKind.ts
CHANGED
|
@@ -76,6 +76,7 @@ export function isWorkerRuntime(): boolean {
|
|
|
76
76
|
return globalThis.__RUNTIME_KIND === 3;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
// is-tree-shakable-suppress
|
|
79
80
|
if (globalThis.__RUNTIME_KIND === undefined) {
|
|
80
81
|
// In Jest environments eager imports make this file to evaluate before
|
|
81
82
|
// `initializers.ts` file, therefore we have to set the RuntimeKind here,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { type TurboModule, TurboModuleRegistry } from 'react-native';
|
|
4
4
|
|
|
5
5
|
export interface Spec extends TurboModule {
|
|
6
|
-
installTurboModule: () => boolean;
|
|
6
|
+
installTurboModule: (bundleModeEnabled: boolean) => boolean;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export default TurboModuleRegistry.get<Spec>('WorkletsModule');
|