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
package/plugin/index.js
CHANGED
|
@@ -277,7 +277,7 @@ var require_types = __commonJS({
|
|
|
277
277
|
return (0, types_12.isObjectExpression)(node);
|
|
278
278
|
}
|
|
279
279
|
exports2.workletClassFactorySuffix = "__classFactory";
|
|
280
|
-
exports2.generatedWorkletsDir = "
|
|
280
|
+
exports2.generatedWorkletsDir = ".worklets";
|
|
281
281
|
}
|
|
282
282
|
});
|
|
283
283
|
|
|
@@ -411,10 +411,15 @@ var require_globals = __commonJS({
|
|
|
411
411
|
exports2.initializeGlobals = initializeGlobals;
|
|
412
412
|
exports2.addCustomGlobals = addCustomGlobals;
|
|
413
413
|
var notCapturedIdentifiers = [
|
|
414
|
+
// Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
|
|
415
|
+
// Note that objects' properties don't need to be listed since we always only capture the whole object,
|
|
416
|
+
// e.g. `global.__ErrorUtils` or `Intl.DateTimeFormat`.
|
|
417
|
+
// Value properties
|
|
414
418
|
"globalThis",
|
|
415
419
|
"Infinity",
|
|
416
420
|
"NaN",
|
|
417
421
|
"undefined",
|
|
422
|
+
// Function properties
|
|
418
423
|
"eval",
|
|
419
424
|
"isFinite",
|
|
420
425
|
"isNaN",
|
|
@@ -426,10 +431,12 @@ var require_globals = __commonJS({
|
|
|
426
431
|
"encodeURIComponent",
|
|
427
432
|
"escape",
|
|
428
433
|
"unescape",
|
|
434
|
+
// Fundamental objects
|
|
429
435
|
"Object",
|
|
430
436
|
"Function",
|
|
431
437
|
"Boolean",
|
|
432
438
|
"Symbol",
|
|
439
|
+
// Error objects
|
|
433
440
|
"Error",
|
|
434
441
|
"AggregateError",
|
|
435
442
|
"EvalError",
|
|
@@ -439,12 +446,15 @@ var require_globals = __commonJS({
|
|
|
439
446
|
"TypeError",
|
|
440
447
|
"URIError",
|
|
441
448
|
"InternalError",
|
|
449
|
+
// Numbers and dates
|
|
442
450
|
"Number",
|
|
443
451
|
"BigInt",
|
|
444
452
|
"Math",
|
|
445
453
|
"Date",
|
|
454
|
+
// Text processing
|
|
446
455
|
"String",
|
|
447
456
|
"RegExp",
|
|
457
|
+
// Indexed collections
|
|
448
458
|
"Array",
|
|
449
459
|
"Int8Array",
|
|
450
460
|
"Uint8Array",
|
|
@@ -457,17 +467,21 @@ var require_globals = __commonJS({
|
|
|
457
467
|
"BigUint64Array",
|
|
458
468
|
"Float32Array",
|
|
459
469
|
"Float64Array",
|
|
470
|
+
// Keyed collections
|
|
460
471
|
"Map",
|
|
461
472
|
"Set",
|
|
462
473
|
"WeakMap",
|
|
463
474
|
"WeakSet",
|
|
475
|
+
// Structured data
|
|
464
476
|
"ArrayBuffer",
|
|
465
477
|
"SharedArrayBuffer",
|
|
466
478
|
"DataView",
|
|
467
479
|
"Atomics",
|
|
468
480
|
"JSON",
|
|
481
|
+
// Managing memory
|
|
469
482
|
"WeakRef",
|
|
470
483
|
"FinalizationRegistry",
|
|
484
|
+
// Control abstraction objects
|
|
471
485
|
"Iterator",
|
|
472
486
|
"AsyncIterator",
|
|
473
487
|
"Promise",
|
|
@@ -476,9 +490,12 @@ var require_globals = __commonJS({
|
|
|
476
490
|
"Generator",
|
|
477
491
|
"AsyncGenerator",
|
|
478
492
|
"AsyncFunction",
|
|
493
|
+
// Reflection
|
|
479
494
|
"Reflect",
|
|
480
495
|
"Proxy",
|
|
496
|
+
// Internationalization
|
|
481
497
|
"Intl",
|
|
498
|
+
// Other stuff
|
|
482
499
|
"null",
|
|
483
500
|
"this",
|
|
484
501
|
"global",
|
|
@@ -488,7 +505,12 @@ var require_globals = __commonJS({
|
|
|
488
505
|
"console",
|
|
489
506
|
"performance",
|
|
490
507
|
"arguments",
|
|
508
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments
|
|
491
509
|
"require",
|
|
510
|
+
"fetch",
|
|
511
|
+
"XMLHttpRequest",
|
|
512
|
+
"WebSocket",
|
|
513
|
+
// Run loop
|
|
492
514
|
"queueMicrotask",
|
|
493
515
|
"requestAnimationFrame",
|
|
494
516
|
"cancelAnimationFrame",
|
|
@@ -498,7 +520,9 @@ var require_globals = __commonJS({
|
|
|
498
520
|
"clearImmediate",
|
|
499
521
|
"setInterval",
|
|
500
522
|
"clearInterval",
|
|
523
|
+
// Hermes
|
|
501
524
|
"HermesInternal",
|
|
525
|
+
// Worklets
|
|
502
526
|
"_WORKLET"
|
|
503
527
|
];
|
|
504
528
|
exports2.outsideBindingsToCaptureFromGlobalScope = /* @__PURE__ */ new Set([
|
|
@@ -511,8 +535,10 @@ var require_globals = __commonJS({
|
|
|
511
535
|
function initializeState(state) {
|
|
512
536
|
state.workletNumber = 1;
|
|
513
537
|
state.classesToWorkletize = [];
|
|
514
|
-
|
|
515
|
-
|
|
538
|
+
if (!state.opts.strictGlobal) {
|
|
539
|
+
initializeGlobals();
|
|
540
|
+
addCustomGlobals(state);
|
|
541
|
+
}
|
|
516
542
|
}
|
|
517
543
|
exports2.defaultGlobals = new Set(notCapturedIdentifiers.concat(notCapturedIdentifiers_DEPRECATED));
|
|
518
544
|
function initializeGlobals() {
|
|
@@ -561,7 +587,7 @@ var require_closure = __commonJS({
|
|
|
561
587
|
binding = idPath.scope.getBinding(name);
|
|
562
588
|
}
|
|
563
589
|
if (!binding) {
|
|
564
|
-
if (globals_12.globals.has(name)) {
|
|
590
|
+
if (state.opts.strictGlobal || globals_12.globals.has(name)) {
|
|
565
591
|
return;
|
|
566
592
|
}
|
|
567
593
|
capturedNames.add(name);
|
|
@@ -614,11 +640,16 @@ var require_closure = __commonJS({
|
|
|
614
640
|
return imported.path.parentPath.node.source.value.startsWith(".");
|
|
615
641
|
}
|
|
616
642
|
function isAllowedForRelativeImports(filename, workletizableModules) {
|
|
617
|
-
return !!filename && (filename.includes(
|
|
643
|
+
return !!filename && (alwaysAllowed.some((module3) => filename.includes(module3)) || !!(workletizableModules === null || workletizableModules === void 0 ? void 0 : workletizableModules.some((module3) => filename.includes(module3))));
|
|
618
644
|
}
|
|
619
645
|
function isWorkletizableModule(source, workletizableModules) {
|
|
620
|
-
return source.startsWith(
|
|
646
|
+
return alwaysAllowed.some((module3) => source.startsWith(module3)) || !!(workletizableModules === null || workletizableModules === void 0 ? void 0 : workletizableModules.some((module3) => source.startsWith(module3)));
|
|
621
647
|
}
|
|
648
|
+
var alwaysAllowed = [
|
|
649
|
+
"react-native-worklets",
|
|
650
|
+
"react-native/Libraries/Core/setUpXHR"
|
|
651
|
+
// for networking
|
|
652
|
+
];
|
|
622
653
|
}
|
|
623
654
|
});
|
|
624
655
|
|
|
@@ -658,9 +689,6 @@ var require_generate = __commonJS({
|
|
|
658
689
|
comments: false
|
|
659
690
|
})) === null || _a === void 0 ? void 0 : _a.code;
|
|
660
691
|
(0, assert_1.default)(transformedProg, "[Worklets] `transformedProg` is undefined.");
|
|
661
|
-
if (!(0, fs_1.existsSync)(filesDirPath)) {
|
|
662
|
-
(0, fs_1.mkdirSync)(filesDirPath, {});
|
|
663
|
-
}
|
|
664
692
|
const dedicatedFilePath = (0, path_1.resolve)(filesDirPath, `${workletHash}.js`);
|
|
665
693
|
(0, fs_1.writeFileSync)(dedicatedFilePath, transformedProg);
|
|
666
694
|
}
|
|
@@ -979,6 +1007,7 @@ var require_workletFactory = __commonJS({
|
|
|
979
1007
|
(0, types_12.newExpression)((0, types_12.memberExpression)((0, types_12.identifier)("global"), (0, types_12.identifier)("Error")), []),
|
|
980
1008
|
(0, types_12.numericLiteral)(lineOffset),
|
|
981
1009
|
(0, types_12.numericLiteral)(-27)
|
|
1010
|
+
// the placement of opening bracket after Exception in line that defined '_e' variable
|
|
982
1011
|
]))
|
|
983
1012
|
]));
|
|
984
1013
|
statements.push((0, types_12.expressionStatement)((0, types_12.assignmentExpression)("=", (0, types_12.memberExpression)((0, types_12.identifier)(reactName), (0, types_12.identifier)("__stackDetails"), false), (0, types_12.identifier)("_e"))));
|
|
@@ -1124,6 +1153,7 @@ var require_workletSubstitution = __commonJS({
|
|
|
1124
1153
|
}
|
|
1125
1154
|
function processWorklet(path, state) {
|
|
1126
1155
|
path.traverse({
|
|
1156
|
+
// @ts-expect-error TypeScript doesn't like this syntax here.
|
|
1127
1157
|
[types_2.WorkletizableFunction](subPath, passedState) {
|
|
1128
1158
|
processIfWithWorkletDirective(subPath, passedState);
|
|
1129
1159
|
}
|
|
@@ -1180,7 +1210,14 @@ var require_objectWorklets = __commonJS({
|
|
|
1180
1210
|
(0, workletSubstitution_12.processWorklet)(property, state);
|
|
1181
1211
|
} else if (property.isObjectProperty()) {
|
|
1182
1212
|
const value = property.get("value");
|
|
1183
|
-
tryProcessingNode(
|
|
1213
|
+
tryProcessingNode(
|
|
1214
|
+
value,
|
|
1215
|
+
state,
|
|
1216
|
+
true,
|
|
1217
|
+
// acceptWorkletizableFunction
|
|
1218
|
+
false
|
|
1219
|
+
// acceptObject
|
|
1220
|
+
);
|
|
1184
1221
|
} else {
|
|
1185
1222
|
throw new Error(`[Reanimated] '${property.type}' as to-be workletized argument is not supported for object hooks.`);
|
|
1186
1223
|
}
|
|
@@ -1213,10 +1250,12 @@ var require_autoworkletization = __commonJS({
|
|
|
1213
1250
|
"useDerivedValue",
|
|
1214
1251
|
"useAnimatedScrollHandler",
|
|
1215
1252
|
"useAnimatedReaction",
|
|
1253
|
+
// animations' callbacks
|
|
1216
1254
|
"withTiming",
|
|
1217
1255
|
"withSpring",
|
|
1218
1256
|
"withDecay",
|
|
1219
1257
|
"withRepeat",
|
|
1258
|
+
// scheduling functions
|
|
1220
1259
|
"runOnUI",
|
|
1221
1260
|
"executeOnUIRuntimeSync",
|
|
1222
1261
|
"scheduleOnUI",
|
|
@@ -1301,7 +1340,7 @@ var require_bundleMode = __commonJS({
|
|
|
1301
1340
|
}
|
|
1302
1341
|
const object = left.get("object");
|
|
1303
1342
|
const property = left.get("property");
|
|
1304
|
-
if (!object.isIdentifier() || object.node.name !== "globalThis" || !property.isIdentifier() || property.node.name !== "
|
|
1343
|
+
if (!object.isIdentifier() || object.node.name !== "globalThis" || !property.isIdentifier() || property.node.name !== "_WORKLETS_BUNDLE_MODE_ENABLED") {
|
|
1305
1344
|
return;
|
|
1306
1345
|
}
|
|
1307
1346
|
const right = expressionPath.get("right");
|
|
@@ -1474,7 +1513,15 @@ var require_class = __commonJS({
|
|
|
1474
1513
|
stack.delete(current.name);
|
|
1475
1514
|
}
|
|
1476
1515
|
function isOutsideDependency(identifierPath, bindingIdentifiers, functionPath) {
|
|
1477
|
-
return
|
|
1516
|
+
return (
|
|
1517
|
+
// We don't care about identifiers that were just declared.
|
|
1518
|
+
identifierPath.isReferencedIdentifier() && // We don't care about identifiers that are bound in the scope.
|
|
1519
|
+
!(identifierPath.node.name in bindingIdentifiers) && // This I don't exactly understand, but the function identifier itself isn't in `bindingIdentifiers`,
|
|
1520
|
+
// but it return true on `hasOwnBinding`.
|
|
1521
|
+
!functionPath.scope.hasOwnBinding(identifierPath.node.name) && // `hasReference` returns true for global identifiers, like `Object`,
|
|
1522
|
+
// we don't want to include those.
|
|
1523
|
+
functionPath.scope.hasReference(identifierPath.node.name)
|
|
1524
|
+
);
|
|
1478
1525
|
}
|
|
1479
1526
|
function isWorkletizableClass(classPath, state) {
|
|
1480
1527
|
var _a;
|
|
@@ -1682,7 +1729,7 @@ var require_inlineStylesWarning = __commonJS({
|
|
|
1682
1729
|
}
|
|
1683
1730
|
function processPropertyValueForInlineStylesWarning(path) {
|
|
1684
1731
|
if (path.isMemberExpression() && (0, types_12.isIdentifier)(path.node.property)) {
|
|
1685
|
-
if (
|
|
1732
|
+
if (path.node.property.name === "value") {
|
|
1686
1733
|
path.replaceWith(generateInlineStylesWarning(path));
|
|
1687
1734
|
}
|
|
1688
1735
|
}
|
|
@@ -8,18 +8,18 @@ end
|
|
|
8
8
|
|
|
9
9
|
def worklets_find_config()
|
|
10
10
|
result = {
|
|
11
|
-
:
|
|
11
|
+
:bundle_mode_flag => nil,
|
|
12
|
+
:dynamic_frameworks_worklets_dir => nil,
|
|
13
|
+
:feature_flags_flag => nil,
|
|
14
|
+
:fetch_preview_flag => nil,
|
|
12
15
|
:is_reanimated_example_app => nil,
|
|
13
16
|
:is_tvos_target => nil,
|
|
14
17
|
:react_native_version => nil,
|
|
15
18
|
:react_native_minor_version => nil,
|
|
16
19
|
:react_native_node_modules_dir => nil,
|
|
17
20
|
:react_native_common_dir => nil,
|
|
18
|
-
:dynamic_frameworks_worklets_dir => nil,
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
result[:bundle_mode] = ENV["WORKLETS_BUNDLE_MODE"] == "1"
|
|
22
|
-
|
|
23
23
|
react_native_node_modules_dir = File.join(File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`), '..')
|
|
24
24
|
react_native_json = worklets_try_to_parse_react_native_package_json(react_native_node_modules_dir)
|
|
25
25
|
|
|
@@ -51,6 +51,11 @@ def worklets_find_config()
|
|
|
51
51
|
react_native_worklets_dir_relative = Pathname.new(react_native_worklets_dir_absolute).relative_path_from(pods_root).to_s
|
|
52
52
|
result[:dynamic_frameworks_worklets_dir] = react_native_worklets_dir_relative
|
|
53
53
|
|
|
54
|
+
feature_flags = worklets_get_static_feature_flags()
|
|
55
|
+
result[:feature_flags_flag] = worklets_get_static_feature_flags_flag(feature_flags)
|
|
56
|
+
result[:bundle_mode_flag] = worklets_get_flag_from_feature_flags(feature_flags, 'BUNDLE_MODE_ENABLED')
|
|
57
|
+
result[:fetch_preview_flag] = worklets_get_flag_from_feature_flags(feature_flags, 'FETCH_PREVIEW_ENABLED')
|
|
58
|
+
|
|
54
59
|
return result
|
|
55
60
|
end
|
|
56
61
|
|
|
@@ -67,6 +72,14 @@ def worklets_assert_new_architecture_enabled(new_arch_enabled)
|
|
|
67
72
|
end
|
|
68
73
|
end
|
|
69
74
|
|
|
75
|
+
def worklets_get_flag_from_feature_flags(feature_flags, flag_name)
|
|
76
|
+
if feature_flags[flag_name] == 'true'
|
|
77
|
+
return "-DWORKLETS_#{flag_name}"
|
|
78
|
+
else
|
|
79
|
+
return ''
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
70
83
|
def worklets_get_static_feature_flags()
|
|
71
84
|
feature_flags = {}
|
|
72
85
|
|
|
@@ -89,6 +102,9 @@ def worklets_get_static_feature_flags()
|
|
|
89
102
|
end
|
|
90
103
|
end
|
|
91
104
|
end
|
|
105
|
+
return feature_flags
|
|
106
|
+
end
|
|
92
107
|
|
|
93
|
-
|
|
108
|
+
def worklets_get_static_feature_flags_flag(feature_flags)
|
|
109
|
+
return "-DWORKLETS_FEATURE_FLAGS=\"#{feature_flags.map { |key, value| "[#{key}:#{value}]" }.join('')}\""
|
|
94
110
|
end
|
|
@@ -26,6 +26,11 @@ class NativeWorklets implements IWorkletsModule {
|
|
|
26
26
|
globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative
|
|
27
27
|
) {
|
|
28
28
|
WorkletsTurboModule?.installTurboModule();
|
|
29
|
+
if (__DEV__ && globalThis._WORKLETS_BUNDLE_MODE_ENABLED) {
|
|
30
|
+
console.log(
|
|
31
|
+
'[Worklets] Bundle mode initialization: Downloaded the bundle for Worklet Runtimes.'
|
|
32
|
+
);
|
|
33
|
+
}
|
|
29
34
|
}
|
|
30
35
|
if (global.__workletsModuleProxy === undefined) {
|
|
31
36
|
throw new WorkletsError(
|
|
@@ -177,10 +182,8 @@ See https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting
|
|
|
177
182
|
return this.#workletsModuleProxy.scheduleOnUI(serializable);
|
|
178
183
|
}
|
|
179
184
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
): TReturn {
|
|
183
|
-
return this.#workletsModuleProxy.executeOnUIRuntimeSync(serializable);
|
|
185
|
+
runOnUISync<TValue, TReturn>(worklet: SerializableRef<TValue>): TReturn {
|
|
186
|
+
return this.#workletsModuleProxy.runOnUISync(worklet);
|
|
184
187
|
}
|
|
185
188
|
|
|
186
189
|
createWorkletRuntime(
|
|
@@ -209,6 +212,13 @@ See https://docs.swmansion.com/react-native-worklets/docs/guides/troubleshooting
|
|
|
209
212
|
);
|
|
210
213
|
}
|
|
211
214
|
|
|
215
|
+
runOnRuntimeSync<TValue, TReturn>(
|
|
216
|
+
workletRuntime: WorkletRuntime,
|
|
217
|
+
worklet: SerializableRef<TValue>
|
|
218
|
+
): TReturn {
|
|
219
|
+
return this.#workletsModuleProxy.runOnRuntimeSync(workletRuntime, worklet);
|
|
220
|
+
}
|
|
221
|
+
|
|
212
222
|
createSynchronizable<TValue>(value: TValue): SynchronizableRef<TValue> {
|
|
213
223
|
return this.#workletsModuleProxy.createSynchronizable(value);
|
|
214
224
|
}
|
|
@@ -83,9 +83,7 @@ export interface WorkletsModuleProxy {
|
|
|
83
83
|
|
|
84
84
|
scheduleOnUI<TValue>(serializable: SerializableRef<TValue>): void;
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
serializable: SerializableRef<TValue>
|
|
88
|
-
): TReturn;
|
|
86
|
+
runOnUISync<TValue, TReturn>(serializable: SerializableRef<TValue>): TReturn;
|
|
89
87
|
|
|
90
88
|
createWorkletRuntime(
|
|
91
89
|
name: string,
|
|
@@ -100,6 +98,11 @@ export interface WorkletsModuleProxy {
|
|
|
100
98
|
worklet: SerializableRef<TValue>
|
|
101
99
|
): void;
|
|
102
100
|
|
|
101
|
+
runOnRuntimeSync<TValue, TReturn>(
|
|
102
|
+
workletRuntime: WorkletRuntime,
|
|
103
|
+
worklet: SerializableRef<TValue>
|
|
104
|
+
): TReturn;
|
|
105
|
+
|
|
103
106
|
reportFatalErrorOnJS(
|
|
104
107
|
message: string,
|
|
105
108
|
stack: string,
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { WorkletsError } from '../debug/WorkletsError';
|
|
4
|
+
import { isWorkletRuntime } from '../runtimeKind';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Evaluating HMR updates on Worklet Runtimes leads to verbose warnings which
|
|
8
|
+
* don't affect runtime. This function silences those warnings by providing a
|
|
9
|
+
* dummy Refresh module to the global scope.
|
|
10
|
+
*
|
|
11
|
+
* Use only in dev builds.
|
|
12
|
+
*/
|
|
13
|
+
export function silenceHMRWarnings() {
|
|
14
|
+
assertWorkletRuntime('silenceHMRWarnings');
|
|
15
|
+
|
|
16
|
+
const Refresh = new Proxy(
|
|
17
|
+
{},
|
|
18
|
+
{
|
|
19
|
+
get() {
|
|
20
|
+
return () => {};
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
globalThis.__r.Refresh = Refresh;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Importing `react-native` on Worklet Runtimes will result in a crash due to
|
|
30
|
+
* the fact that React Native will try to set itself up as on the React Native
|
|
31
|
+
* runtime. To provide better developer experience we override the main React
|
|
32
|
+
* Native module with a proxy that puts an actionable warning.
|
|
33
|
+
*
|
|
34
|
+
* Note that this doesn't affect deep imports.
|
|
35
|
+
*
|
|
36
|
+
* Use only in dev builds.
|
|
37
|
+
*/
|
|
38
|
+
export function disallowRNImports() {
|
|
39
|
+
assertWorkletRuntime('disallowRNImports');
|
|
40
|
+
|
|
41
|
+
const modules = require.getModules();
|
|
42
|
+
const ReactNativeModuleId = require.resolveWeak('react-native');
|
|
43
|
+
|
|
44
|
+
const moduleFactory = makeModuleFactory((module) => {
|
|
45
|
+
module.exports = new Proxy(
|
|
46
|
+
{},
|
|
47
|
+
{
|
|
48
|
+
get: function get(_target, prop) {
|
|
49
|
+
globalThis.console.warn(
|
|
50
|
+
`You tried to import '${String(
|
|
51
|
+
prop
|
|
52
|
+
)}' from 'react-native' module on a Worklet Runtime. Using 'react-native' module on a Worklet Runtime is not allowed.`,
|
|
53
|
+
// eslint-disable-next-line reanimated/use-worklets-error
|
|
54
|
+
new Error().stack
|
|
55
|
+
);
|
|
56
|
+
return {
|
|
57
|
+
get() {
|
|
58
|
+
return undefined;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const mockModule = {
|
|
67
|
+
dependencyMap: [],
|
|
68
|
+
moduleFactory,
|
|
69
|
+
hasError: false,
|
|
70
|
+
importedAll: {},
|
|
71
|
+
importedDefault: {},
|
|
72
|
+
isInitialized: false,
|
|
73
|
+
publicModule: {
|
|
74
|
+
exports: {},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
modules.set(ReactNativeModuleId, mockModule);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* To use code from React Native that obtains TurboModules we need to mock the
|
|
83
|
+
* registry even if the TurboModules aren't actually used.
|
|
84
|
+
*
|
|
85
|
+
* This is needed for example for the XHR setup code that is imported from React
|
|
86
|
+
* Native.
|
|
87
|
+
*/
|
|
88
|
+
export function mockTurboModuleRegistry() {
|
|
89
|
+
const modules = require.getModules();
|
|
90
|
+
|
|
91
|
+
const TurboModuleRegistryId = require.resolveWeak(
|
|
92
|
+
'react-native/Libraries/TurboModule/TurboModuleRegistry'
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const TurboModules = new Map<string, unknown>();
|
|
96
|
+
|
|
97
|
+
TurboModules.set('Networking', {});
|
|
98
|
+
|
|
99
|
+
globalThis.TurboModules = TurboModules;
|
|
100
|
+
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
|
+
const moduleFactory = makeModuleFactory((module: any) => {
|
|
103
|
+
function get(name: string) {
|
|
104
|
+
return globalThis.TurboModules.get(name);
|
|
105
|
+
}
|
|
106
|
+
function getEnforcing(name: string) {
|
|
107
|
+
return globalThis.TurboModules.get(name);
|
|
108
|
+
}
|
|
109
|
+
module.exports.get = get;
|
|
110
|
+
module.exports.getEnforcing = getEnforcing;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const metroModule = {
|
|
114
|
+
dependencyMap: [],
|
|
115
|
+
factory: moduleFactory,
|
|
116
|
+
hasError: false,
|
|
117
|
+
importedAll: {},
|
|
118
|
+
importedDefault: {},
|
|
119
|
+
isInitialized: false,
|
|
120
|
+
publicModule: {
|
|
121
|
+
exports: {},
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
modules.set(TurboModuleRegistryId, metroModule);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function assertWorkletRuntime(functionName: string) {
|
|
129
|
+
if (!isWorkletRuntime()) {
|
|
130
|
+
throw new WorkletsError(
|
|
131
|
+
`${functionName} can be used only on Worklet Runtimes.`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Module factory mimicking the one used by Metro bundler. */
|
|
137
|
+
function makeModuleFactory(
|
|
138
|
+
moduleImpl: (moduleExports: Record<string, unknown>) => void
|
|
139
|
+
) {
|
|
140
|
+
return function (
|
|
141
|
+
_global: unknown,
|
|
142
|
+
_require: unknown,
|
|
143
|
+
_importDefault: unknown,
|
|
144
|
+
_importAll: unknown,
|
|
145
|
+
module: Record<string, unknown>,
|
|
146
|
+
_exports: unknown,
|
|
147
|
+
_dependencyMap: unknown
|
|
148
|
+
) {
|
|
149
|
+
moduleImpl(module);
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { WorkletsError } from '../debug/WorkletsError';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Mocks necessary networking TurboModules on Worklet Runtimes to prevent
|
|
7
|
+
* crashes when code running on Worklet Runtimes tries to use networking APIs.
|
|
8
|
+
* The NetworkingModule itself is injected via C++.
|
|
9
|
+
*/
|
|
10
|
+
export function initializeNetworking() {
|
|
11
|
+
const TurboModules = globalThis.TurboModules;
|
|
12
|
+
|
|
13
|
+
TurboModules.set('FileReaderModule', makeMockTurboModule('FileReaderModule'));
|
|
14
|
+
TurboModules.set(
|
|
15
|
+
'PlatformConstants',
|
|
16
|
+
makeMockTurboModule('PlatformConstants')
|
|
17
|
+
);
|
|
18
|
+
TurboModules.set('WebSocketModule', makeMockTurboModule('WebSocketModule'));
|
|
19
|
+
TurboModules.set(
|
|
20
|
+
'BlobModule',
|
|
21
|
+
makeMockTurboModule('BlobModule', ['addNetworkingHandler'])
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* This require statement below is the key part of the implementation here. It
|
|
26
|
+
* pulls all the code that properly sets up XHR on a Runtime, using underlying
|
|
27
|
+
* C++ NetworkingModule. Thanks to that we can have the same JavaScript
|
|
28
|
+
* implementation for fetch on all runtimes in the app and we don't have to
|
|
29
|
+
* write the code ourselves.
|
|
30
|
+
*/
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
32
|
+
require('react-native/Libraries/Core/setUpXHR');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const noopMethods = ['getConstants'];
|
|
36
|
+
|
|
37
|
+
function makeMockTurboModule(name: string, extraNoopMethods?: string[]) {
|
|
38
|
+
const proxy = new Proxy(
|
|
39
|
+
{},
|
|
40
|
+
{
|
|
41
|
+
get: function get(_target, prop) {
|
|
42
|
+
if (
|
|
43
|
+
[...noopMethods, ...(extraNoopMethods ?? [])].includes(prop as string)
|
|
44
|
+
) {
|
|
45
|
+
return () => {
|
|
46
|
+
return () => {};
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
throw new WorkletsError(
|
|
50
|
+
`You tried to call method '${String(
|
|
51
|
+
prop
|
|
52
|
+
)}' from '${name}' TurboModule on a Worklet Runtime. Using '${name}' TurboModule on a Worklet Runtime is not allowed.`
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return proxy;
|
|
59
|
+
}
|
package/src/debug/jsVersion.ts
CHANGED
|
@@ -21,7 +21,9 @@ export type DynamicFlagName = keyof Omit<
|
|
|
21
21
|
*/
|
|
22
22
|
export const DefaultStaticFeatureFlags = {
|
|
23
23
|
RUNTIME_TEST_FLAG: false,
|
|
24
|
-
|
|
24
|
+
BUNDLE_MODE_ENABLED: false,
|
|
25
|
+
FETCH_PREVIEW_ENABLED: false,
|
|
26
|
+
IOS_DYNAMIC_FRAMERATE_ENABLED: true,
|
|
25
27
|
} as const satisfies typeof StaticFeatureFlagsJSON;
|
|
26
28
|
|
|
27
29
|
export type StaticFeatureFlagsSchema = {
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { init } from './initializers/initializers';
|
|
4
4
|
import { bundleModeInit } from './initializers/workletRuntimeEntry';
|
|
5
5
|
|
|
6
|
+
// is-tree-shakable-suppress
|
|
6
7
|
init();
|
|
7
8
|
|
|
8
9
|
// @ts-expect-error We must trick the bundler to include
|
|
@@ -40,10 +41,18 @@ export type {
|
|
|
40
41
|
Synchronizable,
|
|
41
42
|
SynchronizableRef,
|
|
42
43
|
} from './memory/types';
|
|
43
|
-
export {
|
|
44
|
+
export {
|
|
45
|
+
getRuntimeKind,
|
|
46
|
+
isRNRuntime,
|
|
47
|
+
isUIRuntime,
|
|
48
|
+
isWorkerRuntime,
|
|
49
|
+
isWorkletRuntime,
|
|
50
|
+
RuntimeKind,
|
|
51
|
+
} from './runtimeKind';
|
|
44
52
|
export {
|
|
45
53
|
createWorkletRuntime,
|
|
46
54
|
runOnRuntime,
|
|
55
|
+
runOnRuntimeSync,
|
|
47
56
|
scheduleOnRuntime,
|
|
48
57
|
} from './runtimes';
|
|
49
58
|
export {
|