@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.
Files changed (95) hide show
  1. package/kepler-compatibility.json +2 -1
  2. package/lib/module/index.js +0 -25
  3. package/package.json +1 -1
  4. package/src/index.ts +0 -52
  5. package/bundleMode/index.js +0 -59
  6. package/lib/module/PlatformChecker/PlatformChecker.js +0 -8
  7. package/lib/module/PlatformChecker/index.js +0 -18
  8. package/lib/module/WorkletsError.js +0 -29
  9. package/lib/module/WorkletsModule/JSWorklets.js +0 -111
  10. package/lib/module/WorkletsModule/NativeWorklets.js +0 -126
  11. package/lib/module/WorkletsModule/index.js +0 -4
  12. package/lib/module/WorkletsModule/workletsModuleInstance.js +0 -7
  13. package/lib/module/WorkletsModule/workletsModuleInstance.web.js +0 -5
  14. package/lib/module/WorkletsModule/workletsModuleProxy.js +0 -4
  15. package/lib/module/bundleUnpacker.js +0 -47
  16. package/lib/module/callGuard.js +0 -30
  17. package/lib/module/deprecated.js +0 -20
  18. package/lib/module/errors.js +0 -69
  19. package/lib/module/featureFlags/index.js +0 -48
  20. package/lib/module/initializers.js +0 -221
  21. package/lib/module/isSynchronizable.js +0 -6
  22. package/lib/module/logger.js +0 -15
  23. package/lib/module/privateGlobals.d.js +0 -7
  24. package/lib/module/publicGlobals.js +0 -6
  25. package/lib/module/runLoop/common/setImmediatePolyfill.js +0 -15
  26. package/lib/module/runLoop/common/setIntervalPolyfill.js +0 -26
  27. package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js +0 -10
  28. package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +0 -52
  29. package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js +0 -32
  30. package/lib/module/runLoop/workletRuntime/index.js +0 -19
  31. package/lib/module/runLoop/workletRuntime/queueMicrotask.js +0 -11
  32. package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +0 -48
  33. package/lib/module/runLoop/workletRuntime/setTimeout.js +0 -28
  34. package/lib/module/runLoop/workletRuntime/taskQueue.js +0 -37
  35. package/lib/module/runtimeKind.js +0 -39
  36. package/lib/module/runtimes.js +0 -100
  37. package/lib/module/serializable.js +0 -568
  38. package/lib/module/serializableMappingCache.js +0 -37
  39. package/lib/module/specs/NativeWorkletsModule.js +0 -5
  40. package/lib/module/specs/NativeWorkletsModule.kepler.js +0 -7
  41. package/lib/module/specs/index.js +0 -10
  42. package/lib/module/synchronizable.js +0 -9
  43. package/lib/module/synchronizableUnpacker.js +0 -42
  44. package/lib/module/threads.js +0 -347
  45. package/lib/module/utils/checkCppVersion.js +0 -30
  46. package/lib/module/utils/jsVersion.js +0 -9
  47. package/lib/module/valueUnpacker.js +0 -60
  48. package/lib/module/workletFunction.js +0 -37
  49. package/lib/module/workletRuntimeEntry.js +0 -32
  50. package/lib/module/workletTypes.js +0 -12
  51. package/scripts/validate-react-native-version.js +0 -43
  52. package/src/PlatformChecker/PlatformChecker.ts +0 -7
  53. package/src/PlatformChecker/index.ts +0 -30
  54. package/src/WorkletsError.ts +0 -36
  55. package/src/WorkletsModule/JSWorklets.ts +0 -200
  56. package/src/WorkletsModule/NativeWorklets.ts +0 -256
  57. package/src/WorkletsModule/index.ts +0 -7
  58. package/src/WorkletsModule/workletsModuleInstance.ts +0 -9
  59. package/src/WorkletsModule/workletsModuleInstance.web.ts +0 -5
  60. package/src/WorkletsModule/workletsModuleProxy.ts +0 -126
  61. package/src/bundleUnpacker.ts +0 -75
  62. package/src/callGuard.ts +0 -33
  63. package/src/deprecated.ts +0 -32
  64. package/src/errors.ts +0 -80
  65. package/src/featureFlags/index.ts +0 -72
  66. package/src/initializers.ts +0 -262
  67. package/src/isSynchronizable.ts +0 -13
  68. package/src/logger.ts +0 -16
  69. package/src/publicGlobals.ts +0 -39
  70. package/src/runLoop/common/setImmediatePolyfill.ts +0 -20
  71. package/src/runLoop/common/setIntervalPolyfill.ts +0 -38
  72. package/src/runLoop/uiRuntime/mockedRequestAnimationFrame.ts +0 -11
  73. package/src/runLoop/uiRuntime/requestAnimationFrame.ts +0 -66
  74. package/src/runLoop/uiRuntime/setTimeoutPolyfill.ts +0 -40
  75. package/src/runLoop/workletRuntime/index.ts +0 -18
  76. package/src/runLoop/workletRuntime/queueMicrotask.ts +0 -13
  77. package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +0 -61
  78. package/src/runLoop/workletRuntime/setTimeout.ts +0 -37
  79. package/src/runLoop/workletRuntime/taskQueue.ts +0 -44
  80. package/src/runtimeKind.ts +0 -37
  81. package/src/runtimes.ts +0 -193
  82. package/src/serializable.ts +0 -801
  83. package/src/serializableMappingCache.ts +0 -42
  84. package/src/specs/NativeWorkletsModule.kepler.ts +0 -11
  85. package/src/specs/NativeWorkletsModule.ts +0 -9
  86. package/src/specs/index.ts +0 -13
  87. package/src/synchronizable.ts +0 -32
  88. package/src/synchronizableUnpacker.ts +0 -67
  89. package/src/threads.ts +0 -452
  90. package/src/utils/checkCppVersion.ts +0 -34
  91. package/src/utils/jsVersion.ts +0 -7
  92. package/src/valueUnpacker.ts +0 -90
  93. package/src/workletFunction.ts +0 -42
  94. package/src/workletRuntimeEntry.ts +0 -35
  95. package/src/workletTypes.ts +0 -81
@@ -1,200 +0,0 @@
1
- 'use strict';
2
-
3
- import { IS_JEST } from '../PlatformChecker';
4
- import { mockedRequestAnimationFrame } from '../runLoop/uiRuntime/mockedRequestAnimationFrame';
5
- import { WorkletsError } from '../WorkletsError';
6
- import type { SerializableRef } from '../workletTypes';
7
- import type { IWorkletsModule } from './workletsModuleProxy';
8
-
9
- export function createJSWorkletsModule(): IWorkletsModule {
10
- return new JSWorklets();
11
- }
12
-
13
- // In Node.js environments (like when static rendering with Expo Router)
14
- // requestAnimationFrame is unavailable, so we use our mock.
15
- // It also has to be mocked for Jest purposes (see `initializeUIRuntime`).
16
- const requestAnimationFrameImpl =
17
- IS_JEST || !globalThis.requestAnimationFrame
18
- ? mockedRequestAnimationFrame
19
- : globalThis.requestAnimationFrame;
20
-
21
- class JSWorklets implements IWorkletsModule {
22
- createSerializable(): never {
23
- throw new WorkletsError(
24
- 'createSerializable should never be called in JSWorklets.'
25
- );
26
- }
27
-
28
- createSerializableString(): never {
29
- throw new WorkletsError(
30
- 'createSerializableString should never be called in JSWorklets.'
31
- );
32
- }
33
-
34
- createSerializableNumber(): never {
35
- throw new WorkletsError(
36
- 'createSerializableNumber should never be called in JSWorklets.'
37
- );
38
- }
39
-
40
- createSerializableBoolean(): never {
41
- throw new WorkletsError(
42
- 'createSerializableBoolean should never be called in JSWorklets.'
43
- );
44
- }
45
-
46
- createSerializableBigInt(): never {
47
- throw new WorkletsError(
48
- 'createSerializableBigInt should never be called in JSWorklets.'
49
- );
50
- }
51
-
52
- createSerializableUndefined(): never {
53
- throw new WorkletsError(
54
- 'createSerializableUndefined should never be called in JSWorklets.'
55
- );
56
- }
57
-
58
- createSerializableNull(): never {
59
- throw new WorkletsError(
60
- 'createSerializableNull should never be called in JSWorklets.'
61
- );
62
- }
63
-
64
- createSerializableTurboModuleLike(): never {
65
- throw new WorkletsError(
66
- 'createSerializableTurboModuleLike should never be called in JSWorklets.'
67
- );
68
- }
69
-
70
- createSerializableObject(): never {
71
- throw new WorkletsError(
72
- 'createSerializableObject should never be called in JSWorklets.'
73
- );
74
- }
75
-
76
- createSerializableMap(): never {
77
- throw new WorkletsError(
78
- 'createSerializableMap should never be called in JSWorklets.'
79
- );
80
- }
81
-
82
- createSerializableSet(): never {
83
- throw new WorkletsError(
84
- 'createSerializableSet should never be called in JSWorklets.'
85
- );
86
- }
87
-
88
- createSerializableImport(): never {
89
- throw new WorkletsError(
90
- 'createSerializableImport should never be called in JSWorklets.'
91
- );
92
- }
93
-
94
- createSerializableHostObject(): never {
95
- throw new WorkletsError(
96
- 'createSerializableHostObject should never be called in JSWorklets.'
97
- );
98
- }
99
-
100
- createSerializableArray(): never {
101
- throw new WorkletsError(
102
- 'createSerializableArray should never be called in JSWorklets.'
103
- );
104
- }
105
-
106
- createSerializableInitializer(): never {
107
- throw new WorkletsError(
108
- 'createSerializableInitializer should never be called in JSWorklets.'
109
- );
110
- }
111
-
112
- createSerializableFunction(): never {
113
- throw new WorkletsError(
114
- 'createSerializableFunction should never be called in JSWorklets.'
115
- );
116
- }
117
-
118
- createSerializableWorklet(): never {
119
- throw new WorkletsError(
120
- 'createSerializableWorklet should never be called in JSWorklets.'
121
- );
122
- }
123
-
124
- scheduleOnUI<TValue>(worklet: SerializableRef<TValue>) {
125
- // TODO: `requestAnimationFrame` should be used exclusively in Reanimated
126
-
127
- // @ts-ignore web implementation has still not been updated after the rewrite,
128
- // this will be addressed once the web implementation updates are ready
129
- requestAnimationFrameImpl(worklet);
130
- }
131
-
132
- executeOnUIRuntimeSync(): never {
133
- throw new WorkletsError(
134
- '`executeOnUIRuntimeSync` is not available in JSWorklets.'
135
- );
136
- }
137
-
138
- createWorkletRuntime(): never {
139
- throw new WorkletsError(
140
- 'createWorkletRuntime is not available in JSWorklets.'
141
- );
142
- }
143
-
144
- scheduleOnRuntime(): never {
145
- throw new WorkletsError(
146
- 'scheduleOnRuntime is not available in JSWorklets.'
147
- );
148
- }
149
-
150
- createSynchronizable(): never {
151
- throw new WorkletsError(
152
- 'createSynchronizable should never be called in JSWorklets.'
153
- );
154
- }
155
-
156
- synchronizableGetDirty(): never {
157
- throw new WorkletsError(
158
- 'synchronizableGetDirty should never be called in JSWorklets.'
159
- );
160
- }
161
-
162
- synchronizableGetBlocking(): never {
163
- throw new WorkletsError(
164
- 'synchronizableGetBlocking should never be called in JSWorklets.'
165
- );
166
- }
167
-
168
- synchronizableSetBlocking(): never {
169
- throw new WorkletsError(
170
- 'synchronizableSetBlocking should never be called in JSWorklets.'
171
- );
172
- }
173
-
174
- synchronizableLock(): never {
175
- throw new WorkletsError(
176
- 'synchronizableLock should never be called in JSWorklets.'
177
- );
178
- }
179
-
180
- synchronizableUnlock(): never {
181
- throw new WorkletsError(
182
- 'synchronizableUnlock should never be called in JSWorklets.'
183
- );
184
- }
185
-
186
- reportFatalErrorOnJS(): never {
187
- throw new WorkletsError(
188
- 'reportFatalErrorOnJS should never be called in JSWorklets.'
189
- );
190
- }
191
-
192
- getStaticFeatureFlag(): boolean {
193
- // mock implementation
194
- return false;
195
- }
196
-
197
- setDynamicFeatureFlag() {
198
- // noop
199
- }
200
- }
@@ -1,256 +0,0 @@
1
- 'use strict';
2
-
3
- import { RuntimeKind } from '../runtimeKind';
4
- import { WorkletsTurboModule } from '../specs';
5
- import type { SynchronizableRef } from '../synchronizable';
6
- import { checkCppVersion } from '../utils/checkCppVersion';
7
- import { jsVersion } from '../utils/jsVersion';
8
- import { WorkletsError } from '../WorkletsError';
9
- import type { SerializableRef, WorkletRuntime } from '../workletTypes';
10
- import type {
11
- IWorkletsModule,
12
- WorkletsModuleProxy,
13
- } from './workletsModuleProxy';
14
-
15
- export function createNativeWorkletsModule(): IWorkletsModule {
16
- return new NativeWorklets();
17
- }
18
-
19
- class NativeWorklets implements IWorkletsModule {
20
- #workletsModuleProxy: WorkletsModuleProxy;
21
- #serializableUndefined: SerializableRef<undefined>;
22
- #serializableNull: SerializableRef<null>;
23
- #serializableTrue: SerializableRef<boolean>;
24
- #serializableFalse: SerializableRef<boolean>;
25
-
26
- constructor() {
27
- globalThis._WORKLETS_VERSION_JS = jsVersion;
28
- if (
29
- global.__workletsModuleProxy === undefined &&
30
- globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative
31
- ) {
32
- WorkletsTurboModule?.installTurboModule();
33
- }
34
- if (global.__workletsModuleProxy === undefined) {
35
- throw new WorkletsError(
36
- `Native part of Worklets doesn't seem to be initialized.
37
- See https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting#native-part-of-worklets-doesnt-seem-to-be-initialized for more details.`
38
- );
39
- }
40
- if (__DEV__) {
41
- checkCppVersion();
42
- }
43
- this.#workletsModuleProxy = global.__workletsModuleProxy;
44
- this.#serializableNull = this.#workletsModuleProxy.createSerializableNull();
45
- this.#serializableUndefined =
46
- this.#workletsModuleProxy.createSerializableUndefined();
47
- this.#serializableTrue =
48
- this.#workletsModuleProxy.createSerializableBoolean(true);
49
- this.#serializableFalse =
50
- this.#workletsModuleProxy.createSerializableBoolean(false);
51
- }
52
-
53
- createSerializable<TValue>(
54
- value: TValue,
55
- shouldPersistRemote: boolean,
56
- nativeStateSource?: object
57
- ) {
58
- return this.#workletsModuleProxy.createSerializable(
59
- value,
60
- shouldPersistRemote,
61
- nativeStateSource
62
- );
63
- }
64
-
65
- createSerializableImport<TValue>(
66
- from: string,
67
- to: string
68
- ): SerializableRef<TValue> {
69
- return this.#workletsModuleProxy.createSerializableImport(from, to);
70
- }
71
-
72
- createSerializableString(str: string) {
73
- return this.#workletsModuleProxy.createSerializableString(str);
74
- }
75
-
76
- createSerializableNumber(num: number) {
77
- return this.#workletsModuleProxy.createSerializableNumber(num);
78
- }
79
-
80
- createSerializableBoolean(bool: boolean) {
81
- return bool ? this.#serializableTrue : this.#serializableFalse;
82
- }
83
-
84
- createSerializableBigInt(bigInt: bigint) {
85
- return this.#workletsModuleProxy.createSerializableBigInt(bigInt);
86
- }
87
-
88
- createSerializableUndefined() {
89
- return this.#serializableUndefined;
90
- }
91
-
92
- createSerializableNull() {
93
- return this.#serializableNull;
94
- }
95
-
96
- createSerializableTurboModuleLike<
97
- TProps extends object,
98
- TProto extends object,
99
- >(props: TProps, proto: TProto): SerializableRef<TProps> {
100
- return this.#workletsModuleProxy.createSerializableTurboModuleLike(
101
- props,
102
- proto
103
- );
104
- }
105
-
106
- createSerializableObject<T extends object>(
107
- obj: T,
108
- shouldRetainRemote: boolean,
109
- nativeStateSource?: object
110
- ): SerializableRef<T> {
111
- return this.#workletsModuleProxy.createSerializableObject(
112
- obj,
113
- shouldRetainRemote,
114
- nativeStateSource
115
- );
116
- }
117
-
118
- createSerializableHostObject<T extends object>(obj: T) {
119
- return this.#workletsModuleProxy.createSerializableHostObject(obj);
120
- }
121
-
122
- createSerializableArray(array: unknown[], shouldRetainRemote: boolean) {
123
- return this.#workletsModuleProxy.createSerializableArray(
124
- array,
125
- shouldRetainRemote
126
- );
127
- }
128
-
129
- createSerializableMap<TKey, TValue>(
130
- keys: TKey[],
131
- values: TValue[]
132
- ): SerializableRef<Map<TKey, TValue>> {
133
- return this.#workletsModuleProxy.createSerializableMap(keys, values);
134
- }
135
-
136
- createSerializableSet<TValues>(
137
- values: TValues[]
138
- ): SerializableRef<Set<TValues>> {
139
- return this.#workletsModuleProxy.createSerializableSet(values);
140
- }
141
-
142
- createSerializableInitializer(obj: object) {
143
- return this.#workletsModuleProxy.createSerializableInitializer(obj);
144
- }
145
-
146
- createSerializableFunction<TArgs extends unknown[], TReturn>(
147
- func: (...args: TArgs) => TReturn
148
- ) {
149
- return this.#workletsModuleProxy.createSerializableFunction(func);
150
- }
151
-
152
- createSerializableWorklet(worklet: object, shouldPersistRemote: boolean) {
153
- return this.#workletsModuleProxy.createSerializableWorklet(
154
- worklet,
155
- shouldPersistRemote
156
- );
157
- }
158
-
159
- scheduleOnUI<TValue>(serializable: SerializableRef<TValue>) {
160
- return this.#workletsModuleProxy.scheduleOnUI(serializable);
161
- }
162
-
163
- executeOnUIRuntimeSync<TValue, TReturn>(
164
- serializable: SerializableRef<TValue>
165
- ): TReturn {
166
- return this.#workletsModuleProxy.executeOnUIRuntimeSync(serializable);
167
- }
168
-
169
- createWorkletRuntime(
170
- name: string,
171
- initializer: SerializableRef<() => void>,
172
- useDefaultQueue: boolean,
173
- customQueue: object | undefined,
174
- enableEventLoop: boolean
175
- ) {
176
- return this.#workletsModuleProxy.createWorkletRuntime(
177
- name,
178
- initializer,
179
- useDefaultQueue,
180
- customQueue,
181
- enableEventLoop
182
- );
183
- }
184
-
185
- scheduleOnRuntime<T>(
186
- workletRuntime: WorkletRuntime,
187
- serializableWorklet: SerializableRef<T>
188
- ) {
189
- return this.#workletsModuleProxy.scheduleOnRuntime(
190
- workletRuntime,
191
- serializableWorklet
192
- );
193
- }
194
-
195
- createSynchronizable<TValue>(value: TValue): SynchronizableRef<TValue> {
196
- return this.#workletsModuleProxy.createSynchronizable(value);
197
- }
198
-
199
- synchronizableGetDirty<TValue>(
200
- synchronizableRef: SynchronizableRef<TValue>
201
- ): TValue {
202
- return this.#workletsModuleProxy.synchronizableGetDirty(synchronizableRef);
203
- }
204
-
205
- synchronizableGetBlocking<TValue>(
206
- synchronizableRef: SynchronizableRef<TValue>
207
- ): TValue {
208
- return this.#workletsModuleProxy.synchronizableGetBlocking(
209
- synchronizableRef
210
- );
211
- }
212
-
213
- synchronizableSetBlocking<TValue>(
214
- synchronizableRef: SynchronizableRef<TValue>,
215
- value: SerializableRef<TValue>
216
- ) {
217
- return this.#workletsModuleProxy.synchronizableSetBlocking(
218
- synchronizableRef,
219
- value
220
- );
221
- }
222
-
223
- synchronizableLock<TValue>(
224
- synchronizableRef: SynchronizableRef<TValue>
225
- ): void {
226
- return this.#workletsModuleProxy.synchronizableLock(synchronizableRef);
227
- }
228
-
229
- synchronizableUnlock<TValue>(
230
- synchronizableRef: SynchronizableRef<TValue>
231
- ): void {
232
- return this.#workletsModuleProxy.synchronizableUnlock(synchronizableRef);
233
- }
234
-
235
- reportFatalErrorOnJS(
236
- message: string,
237
- stack: string,
238
- name: string,
239
- jsEngine: string
240
- ) {
241
- return this.#workletsModuleProxy.reportFatalErrorOnJS(
242
- message,
243
- stack,
244
- name,
245
- jsEngine
246
- );
247
- }
248
-
249
- getStaticFeatureFlag(name: string): boolean {
250
- return this.#workletsModuleProxy.getStaticFeatureFlag(name);
251
- }
252
-
253
- setDynamicFeatureFlag(name: string, value: boolean) {
254
- this.#workletsModuleProxy.setDynamicFeatureFlag(name, value);
255
- }
256
- }
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- export { WorkletsModule } from './workletsModuleInstance';
4
- export type {
5
- IWorkletsModule,
6
- WorkletsModuleProxy,
7
- } from './workletsModuleProxy';
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- import { SHOULD_BE_USE_WEB } from '../PlatformChecker';
4
- import { createJSWorkletsModule } from './JSWorklets';
5
- import { createNativeWorkletsModule } from './NativeWorklets';
6
-
7
- export const WorkletsModule = SHOULD_BE_USE_WEB
8
- ? createJSWorkletsModule()
9
- : createNativeWorkletsModule();
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- import { createJSWorkletsModule } from './JSWorklets';
4
-
5
- export const WorkletsModule = createJSWorkletsModule();
@@ -1,126 +0,0 @@
1
- 'use strict';
2
-
3
- import type { SynchronizableRef } from '../synchronizable';
4
- import type { SerializableRef, WorkletRuntime } from '../workletTypes';
5
-
6
- /** Type of `__workletsModuleProxy` injected with JSI. */
7
- export interface WorkletsModuleProxy {
8
- createSerializable<TValue>(
9
- value: TValue,
10
- shouldPersistRemote: boolean,
11
- nativeStateSource?: object
12
- ): SerializableRef<TValue>;
13
-
14
- createSerializableImport<TValue>(
15
- source: string,
16
- imported: string
17
- ): SerializableRef<TValue>;
18
-
19
- createSerializableString(str: string): SerializableRef<string>;
20
-
21
- createSerializableNumber(num: number): SerializableRef<number>;
22
-
23
- createSerializableBoolean(bool: boolean): SerializableRef<boolean>;
24
-
25
- createSerializableBigInt(bigInt: bigint): SerializableRef<bigint>;
26
-
27
- createSerializableUndefined(): SerializableRef<undefined>;
28
-
29
- createSerializableNull(): SerializableRef<null>;
30
-
31
- createSerializableTurboModuleLike<
32
- TProps extends object,
33
- TProto extends object,
34
- >(
35
- props: TProps,
36
- proto: TProto
37
- ): SerializableRef<TProps>;
38
-
39
- createSerializableObject<T extends object>(
40
- obj: T,
41
- shouldRetainRemote: boolean,
42
- nativeStateSource?: object
43
- ): SerializableRef<T>;
44
-
45
- createSerializableHostObject<T extends object>(obj: T): SerializableRef<T>;
46
-
47
- createSerializableArray(
48
- array: unknown[],
49
- shouldRetainRemote: boolean
50
- ): SerializableRef<unknown[]>;
51
-
52
- createSerializableMap<TKey, TValue>(
53
- keys: TKey[],
54
- values: TValue[]
55
- ): SerializableRef<Map<TKey, TValue>>;
56
-
57
- createSerializableSet<TValues>(
58
- values: TValues[]
59
- ): SerializableRef<Set<TValues>>;
60
-
61
- createSerializableInitializer(obj: object): SerializableRef<object>;
62
-
63
- createSerializableFunction<TArgs extends unknown[], TReturn>(
64
- func: (...args: TArgs) => TReturn
65
- ): SerializableRef<TReturn>;
66
-
67
- createSerializableWorklet(
68
- worklet: object,
69
- shouldPersistRemote: boolean
70
- ): SerializableRef<object>;
71
-
72
- scheduleOnUI<TValue>(serializable: SerializableRef<TValue>): void;
73
-
74
- executeOnUIRuntimeSync<TValue, TReturn>(
75
- serializable: SerializableRef<TValue>
76
- ): TReturn;
77
-
78
- createWorkletRuntime(
79
- name: string,
80
- initializer: SerializableRef<() => void>,
81
- useDefaultQueue: boolean,
82
- customQueue: object | undefined,
83
- enableEventLoop: boolean
84
- ): WorkletRuntime;
85
-
86
- scheduleOnRuntime<TValue>(
87
- workletRuntime: WorkletRuntime,
88
- worklet: SerializableRef<TValue>
89
- ): void;
90
-
91
- reportFatalErrorOnJS(
92
- message: string,
93
- stack: string,
94
- name: string,
95
- jsEngine: string
96
- ): void;
97
-
98
- createSynchronizable<TValue>(value: TValue): SynchronizableRef<TValue>;
99
-
100
- synchronizableGetDirty<TValue>(
101
- synchronizableRef: SynchronizableRef<TValue>
102
- ): TValue;
103
-
104
- synchronizableGetBlocking<TValue>(
105
- synchronizableRef: SynchronizableRef<TValue>
106
- ): TValue;
107
-
108
- synchronizableSetBlocking<TValue>(
109
- synchronizableRef: SynchronizableRef<TValue>,
110
- value: SerializableRef<TValue>
111
- ): void;
112
-
113
- synchronizableLock<TValue>(
114
- synchronizableRef: SynchronizableRef<TValue>
115
- ): void;
116
-
117
- synchronizableUnlock<TValue>(
118
- synchronizableRef: SynchronizableRef<TValue>
119
- ): void;
120
-
121
- getStaticFeatureFlag(name: string): boolean;
122
-
123
- setDynamicFeatureFlag(name: string, value: boolean): void;
124
- }
125
-
126
- export type IWorkletsModule = WorkletsModuleProxy;
@@ -1,75 +0,0 @@
1
- 'use strict';
2
- import { logger } from './logger';
3
- import { WorkletsError } from './WorkletsError';
4
- import type { WorkletFactory, WorkletFunction } from './workletTypes';
5
-
6
- const handleCache = new WeakMap<WorkletFunction, unknown>();
7
-
8
- export function bundleValueUnpacker(
9
- objectToUnpack: ObjectToUnpack,
10
- category?: string,
11
- remoteFunctionName?: string
12
- ): unknown {
13
- const workletHash = objectToUnpack.__workletHash;
14
- if (workletHash !== undefined) {
15
- return getWorklet(workletHash, objectToUnpack.__closure);
16
- } else if (objectToUnpack.__init !== undefined) {
17
- let value = handleCache.get(objectToUnpack);
18
- if (value === undefined) {
19
- value = objectToUnpack.__init();
20
- handleCache.set(objectToUnpack, value);
21
- }
22
- return value;
23
- } else if (category === 'RemoteFunction') {
24
- const remoteFunctionHolder = () => {
25
- const label = remoteFunctionName
26
- ? `function \`${remoteFunctionName}\``
27
- : 'anonymous function';
28
- throw new WorkletsError(`Tried to synchronously call a non-worklet ${label} on the UI thread.
29
- 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.`);
30
- };
31
- remoteFunctionHolder.__remoteFunction = objectToUnpack;
32
- return remoteFunctionHolder;
33
- } else {
34
- throw new WorkletsError(
35
- `Data type in category "${category}" not recognized by value unpacker: "${globalThis._toString(
36
- objectToUnpack
37
- )}".`
38
- );
39
- }
40
- }
41
-
42
- function getWorklet(
43
- workletHash: number,
44
- closureVariables: Record<string, unknown>
45
- ): WorkletFunction | undefined {
46
- let worklet;
47
- if (__DEV__) {
48
- try {
49
- worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
50
- } catch (_e) {
51
- logger.error(
52
- 'Unable to resolve worklet with hash ' +
53
- workletHash +
54
- '. Try reloading the app.'
55
- );
56
- }
57
- } else {
58
- worklet = getWorkletFromMetroRequire(workletHash, closureVariables);
59
- }
60
- return worklet;
61
- }
62
-
63
- const metroRequire = globalThis.__r;
64
-
65
- function getWorkletFromMetroRequire(
66
- workletHash: number,
67
- closureVariables: Record<string, unknown>
68
- ): WorkletFunction {
69
- const factory = metroRequire(workletHash).default as WorkletFactory;
70
- return factory(closureVariables);
71
- }
72
-
73
- interface ObjectToUnpack extends WorkletFunction {
74
- _recur: unknown;
75
- }