@depup/react-native-worklets 0.11.3-depup.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/.worklets/dummy.md +1 -0
- package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.cpp +64 -0
- package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.h +38 -0
- package/Common/cpp/worklets/Compat/Holders.h +25 -0
- package/Common/cpp/worklets/Compat/StableApi.cpp +145 -0
- package/Common/cpp/worklets/Compat/StableApi.h +128 -0
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +729 -0
- package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +126 -0
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +81 -0
- package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +76 -0
- package/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +95 -0
- package/Common/cpp/worklets/Registries/EventHandlerRegistry.h +44 -0
- package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +10 -0
- package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +43 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueue.h +14 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +69 -0
- package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +48 -0
- package/Common/cpp/worklets/RunLoop/EventLoop.cpp +103 -0
- package/Common/cpp/worklets/RunLoop/EventLoop.h +52 -0
- package/Common/cpp/worklets/SharedItems/MemoryManager.cpp +60 -0
- package/Common/cpp/worklets/SharedItems/MemoryManager.h +29 -0
- package/Common/cpp/worklets/SharedItems/Serializable.cpp +373 -0
- package/Common/cpp/worklets/SharedItems/Serializable.h +413 -0
- package/Common/cpp/worklets/SharedItems/SerializableFactory.cpp +172 -0
- package/Common/cpp/worklets/SharedItems/SerializableFactory.h +85 -0
- package/Common/cpp/worklets/SharedItems/SerializableRemoteFunction.cpp +71 -0
- package/Common/cpp/worklets/SharedItems/SerializableRemoteFunction.h +75 -0
- package/Common/cpp/worklets/SharedItems/Shareable.cpp +84 -0
- package/Common/cpp/worklets/SharedItems/Shareable.h +43 -0
- package/Common/cpp/worklets/SharedItems/Synchronizable.cpp +59 -0
- package/Common/cpp/worklets/SharedItems/Synchronizable.h +57 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableAccess.cpp +78 -0
- package/Common/cpp/worklets/SharedItems/SynchronizableAccess.h +45 -0
- package/Common/cpp/worklets/SharedItems/UnpackerLoader.h +78 -0
- package/Common/cpp/worklets/Tools/FeatureFlags.cpp +18 -0
- package/Common/cpp/worklets/Tools/FeatureFlags.h +44 -0
- package/Common/cpp/worklets/Tools/JSISerializer.cpp +312 -0
- package/Common/cpp/worklets/Tools/JSISerializer.h +42 -0
- package/Common/cpp/worklets/Tools/JSLogger.cpp +92 -0
- package/Common/cpp/worklets/Tools/JSLogger.h +48 -0
- package/Common/cpp/worklets/Tools/JSScheduler.cpp +21 -0
- package/Common/cpp/worklets/Tools/JSScheduler.h +35 -0
- package/Common/cpp/worklets/Tools/PlatformLogger.h +16 -0
- package/Common/cpp/worklets/Tools/RNRuntimeStatus.h +27 -0
- package/Common/cpp/worklets/Tools/ScriptBuffer.h +56 -0
- package/Common/cpp/worklets/Tools/SingleInstanceChecker.h +75 -0
- package/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -0
- package/Common/cpp/worklets/Tools/UIScheduler.cpp +19 -0
- package/Common/cpp/worklets/Tools/UIScheduler.h +22 -0
- package/Common/cpp/worklets/Tools/VersionUtils.cpp +61 -0
- package/Common/cpp/worklets/Tools/VersionUtils.h +24 -0
- package/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +34 -0
- package/Common/cpp/worklets/Tools/WorkletEventHandler.h +44 -0
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.cpp +30 -0
- package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +222 -0
- package/Common/cpp/worklets/Tools/WorkletsSystraceSection.h +116 -0
- package/Common/cpp/worklets/Tools/WorkletsVersion.cpp +46 -0
- package/Common/cpp/worklets/Tools/WorkletsVersion.h +18 -0
- package/Common/cpp/worklets/WorkletRuntime/BundleModeConfig.h +17 -0
- package/Common/cpp/worklets/WorkletRuntime/HermesProfiling.cpp +45 -0
- package/Common/cpp/worklets/WorkletRuntime/HermesProfiling.h +12 -0
- package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +68 -0
- package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +24 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeBindings.h +59 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeData.h +38 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeHolder.h +19 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +122 -0
- package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +75 -0
- package/Common/cpp/worklets/WorkletRuntime/ScriptLoader.h +116 -0
- package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.cpp +14 -0
- package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.h +15 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.cpp +58 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.h +100 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +327 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +256 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +320 -0
- package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +36 -0
- package/LICENSE +20 -0
- package/README.md +43 -0
- package/RNWorklets.podspec +94 -0
- package/android/CMakeLists.txt +108 -0
- package/android/build.gradle.kts +369 -0
- package/android/fix-prefab.gradle.kts +56 -0
- package/android/generate-stub-pch.gradle.kts +84 -0
- package/android/gradle.properties +25 -0
- package/android/proguard-rules.pro +3 -0
- package/android/settings.gradle.kts +21 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/WorkletsPCH.h +26 -0
- package/android/src/main/cpp/worklets/android/AndroidUIScheduler.cpp +66 -0
- package/android/src/main/cpp/worklets/android/AndroidUIScheduler.h +38 -0
- package/android/src/main/cpp/worklets/android/AnimationFrameCallback.h +30 -0
- package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.cpp +66 -0
- package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.h +48 -0
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.cpp +51 -0
- package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.h +43 -0
- package/android/src/main/cpp/worklets/android/PlatformLogger.cpp +31 -0
- package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +203 -0
- package/android/src/main/cpp/worklets/android/WorkletsModule.h +75 -0
- package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +19 -0
- package/android/src/main/java/com/swmansion/worklets/AndroidUIScheduler.kt +56 -0
- package/android/src/main/java/com/swmansion/worklets/ScriptBufferWrapper.kt +103 -0
- package/android/src/main/java/com/swmansion/worklets/WorkletsPackage.kt +42 -0
- package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameCallback.kt +14 -0
- package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameQueue.kt +112 -0
- package/android/src/networking/com/swmansion/worklets/WorkletRuntimeWrapper.kt +27 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsHeaderUtil.kt +30 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsModule.kt +187 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworkEventUtil.kt +272 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsNetworking.kt +1124 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsOkHttpCallUtil.kt +40 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressListener.kt +13 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressRequestBody.kt +98 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressResponseBody.kt +60 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsProgressiveStringDecoder.kt +87 -0
- package/android/src/networking/com/swmansion/worklets/WorkletsRequestBodyUtil.kt +181 -0
- package/android/src/no-networking/com/swmansion/worklets/WorkletsModule.kt +143 -0
- package/apple/worklets/apple/AnimationFrameQueue.h +15 -0
- package/apple/worklets/apple/AnimationFrameQueue.mm +145 -0
- package/apple/worklets/apple/AssertJavaScriptQueue.h +14 -0
- package/apple/worklets/apple/AssertTurboModuleManagerQueue.h +12 -0
- package/apple/worklets/apple/IOSUIScheduler.h +14 -0
- package/apple/worklets/apple/IOSUIScheduler.mm +29 -0
- package/apple/worklets/apple/Networking/WorkletsNetworking.h +25 -0
- package/apple/worklets/apple/Networking/WorkletsNetworking.mm +707 -0
- package/apple/worklets/apple/PlatformLogger.mm +31 -0
- package/apple/worklets/apple/SlowAnimations.h +8 -0
- package/apple/worklets/apple/SlowAnimations.mm +45 -0
- package/apple/worklets/apple/WorkletsDisplayLink.h +21 -0
- package/apple/worklets/apple/WorkletsModule.h +28 -0
- package/apple/worklets/apple/WorkletsModule.mm +177 -0
- package/bundleMode/index.d.ts +6 -0
- package/bundleMode/index.js +182 -0
- package/bundleMode/shims/reactNativeShim.js +21 -0
- package/bundleMode/shims/turboModuleRegistryShim.js +47 -0
- package/changes.json +58 -0
- package/compatibility.json +29 -0
- package/jest/pluginTestUtils.ts +16 -0
- package/jest/resolver.js +18 -0
- package/lib/module/WorkletsModule/NativeWorklets.js +4 -0
- package/lib/module/WorkletsModule/NativeWorklets.js.map +1 -0
- package/lib/module/WorkletsModule/NativeWorklets.native.js +199 -0
- package/lib/module/WorkletsModule/NativeWorklets.native.js.map +1 -0
- package/lib/module/WorkletsModule/workletsModuleProxy.js +4 -0
- package/lib/module/WorkletsModule/workletsModuleProxy.js.map +1 -0
- package/lib/module/bundleMode/metroOverrides.native.js +26 -0
- package/lib/module/bundleMode/metroOverrides.native.js.map +1 -0
- package/lib/module/bundleMode/network.native.js +44 -0
- package/lib/module/bundleMode/network.native.js.map +1 -0
- package/lib/module/debug/bundleMode.js +6 -0
- package/lib/module/debug/bundleMode.js.map +1 -0
- package/lib/module/debug/bundleMode.native.js +11 -0
- package/lib/module/debug/bundleMode.native.js.map +1 -0
- package/lib/module/debug/checkCppVersion.js +29 -0
- package/lib/module/debug/checkCppVersion.js.map +1 -0
- package/lib/module/debug/errors.native.js +67 -0
- package/lib/module/debug/errors.native.js.map +1 -0
- package/lib/module/debug/jsVersion.js +9 -0
- package/lib/module/debug/jsVersion.js.map +1 -0
- package/lib/module/debug/logger.js +15 -0
- package/lib/module/debug/logger.js.map +1 -0
- package/lib/module/debug/slowAnimations.js +7 -0
- package/lib/module/debug/slowAnimations.js.map +1 -0
- package/lib/module/debug/slowAnimations.native.js +17 -0
- package/lib/module/debug/slowAnimations.native.js.map +1 -0
- package/lib/module/deprecated.js +27 -0
- package/lib/module/deprecated.js.map +1 -0
- package/lib/module/featureFlags/featureFlags.js +12 -0
- package/lib/module/featureFlags/featureFlags.js.map +1 -0
- package/lib/module/featureFlags/featureFlags.native.js +51 -0
- package/lib/module/featureFlags/featureFlags.native.js.map +1 -0
- package/lib/module/featureFlags/staticFlags.json +6 -0
- package/lib/module/featureFlags/types.js +16 -0
- package/lib/module/featureFlags/types.js.map +1 -0
- package/lib/module/guardImplementation.native.js +17 -0
- package/lib/module/guardImplementation.native.js.map +1 -0
- package/lib/module/index.js +26 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/initializers/initializers.js +24 -0
- package/lib/module/initializers/initializers.js.map +1 -0
- package/lib/module/initializers/initializers.native.js +195 -0
- package/lib/module/initializers/initializers.native.js.map +1 -0
- package/lib/module/memory/bundleUnpacker.native.js +38 -0
- package/lib/module/memory/bundleUnpacker.native.js.map +1 -0
- package/lib/module/memory/customSerializableUnpacker.native.js +20 -0
- package/lib/module/memory/customSerializableUnpacker.native.js.map +1 -0
- package/lib/module/memory/isShareable.js +8 -0
- package/lib/module/memory/isShareable.js.map +1 -0
- package/lib/module/memory/isSynchronizable.js +8 -0
- package/lib/module/memory/isSynchronizable.js.map +1 -0
- package/lib/module/memory/remoteFunctionUnpacker.native.js +18 -0
- package/lib/module/memory/remoteFunctionUnpacker.native.js.map +1 -0
- package/lib/module/memory/serializable.js +18 -0
- package/lib/module/memory/serializable.js.map +1 -0
- package/lib/module/memory/serializable.native.js +619 -0
- package/lib/module/memory/serializable.native.js.map +1 -0
- package/lib/module/memory/serializableMappingCache.js +11 -0
- package/lib/module/memory/serializableMappingCache.js.map +1 -0
- package/lib/module/memory/serializableMappingCache.native.js +29 -0
- package/lib/module/memory/serializableMappingCache.native.js.map +1 -0
- package/lib/module/memory/shareable.js +18 -0
- package/lib/module/memory/shareable.js.map +1 -0
- package/lib/module/memory/shareable.native.js +42 -0
- package/lib/module/memory/shareable.native.js.map +1 -0
- package/lib/module/memory/shareableGuestUnpacker.native.js +105 -0
- package/lib/module/memory/shareableGuestUnpacker.native.js.map +1 -0
- package/lib/module/memory/shareableHostUnpacker.native.js +20 -0
- package/lib/module/memory/shareableHostUnpacker.native.js.map +1 -0
- package/lib/module/memory/synchronizable.js +6 -0
- package/lib/module/memory/synchronizable.js.map +1 -0
- package/lib/module/memory/synchronizable.native.js +9 -0
- package/lib/module/memory/synchronizable.native.js.map +1 -0
- package/lib/module/memory/synchronizableUnpacker.native.js +47 -0
- package/lib/module/memory/synchronizableUnpacker.native.js.map +1 -0
- package/lib/module/memory/types.js +12 -0
- package/lib/module/memory/types.js.map +1 -0
- package/lib/module/memory/valueUnpacker.native.js +52 -0
- package/lib/module/memory/valueUnpacker.native.js.map +1 -0
- package/lib/module/mock.js +85 -0
- package/lib/module/mock.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/platformChecker.js +4 -0
- package/lib/module/platformChecker.js.map +1 -0
- package/lib/module/platformChecker.native.js +4 -0
- package/lib/module/platformChecker.native.js.map +1 -0
- package/lib/module/privateGlobals.d.js +7 -0
- package/lib/module/privateGlobals.d.js.map +1 -0
- package/lib/module/runLoop/common/setImmediatePolyfill.js +15 -0
- package/lib/module/runLoop/common/setImmediatePolyfill.js.map +1 -0
- package/lib/module/runLoop/common/setIntervalPolyfill.js +26 -0
- package/lib/module/runLoop/common/setIntervalPolyfill.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js +10 -0
- package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +71 -0
- package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js.map +1 -0
- package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js +32 -0
- package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/index.js +19 -0
- package/lib/module/runLoop/workletRuntime/index.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js +11 -0
- package/lib/module/runLoop/workletRuntime/queueMicrotask.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +48 -0
- package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/setTimeout.js +28 -0
- package/lib/module/runLoop/workletRuntime/setTimeout.js.map +1 -0
- package/lib/module/runLoop/workletRuntime/taskQueue.js +37 -0
- package/lib/module/runLoop/workletRuntime/taskQueue.js.map +1 -0
- package/lib/module/runtimeKind.js +92 -0
- package/lib/module/runtimeKind.js.map +1 -0
- package/lib/module/runtimes.js +36 -0
- package/lib/module/runtimes.js.map +1 -0
- package/lib/module/runtimes.native.js +379 -0
- package/lib/module/runtimes.native.js.map +1 -0
- package/lib/module/specs/NativeWorkletsModule.js +5 -0
- package/lib/module/specs/NativeWorkletsModule.js.map +1 -0
- package/lib/module/specs/index.js +10 -0
- package/lib/module/specs/index.js.map +1 -0
- package/lib/module/threads.js +60 -0
- package/lib/module/threads.js.map +1 -0
- package/lib/module/threads.native.js +295 -0
- package/lib/module/threads.native.js.map +1 -0
- package/lib/module/types.js +5 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/workletFunction.js +36 -0
- package/lib/module/workletFunction.js.map +1 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.d.ts +3 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.d.ts.map +1 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts +3 -0
- package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts.map +1 -0
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +59 -0
- package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -0
- package/lib/typescript/bundleMode/metroOverrides.native.d.ts +9 -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/bundleMode.d.ts +2 -0
- package/lib/typescript/debug/bundleMode.d.ts.map +1 -0
- package/lib/typescript/debug/bundleMode.native.d.ts +2 -0
- package/lib/typescript/debug/bundleMode.native.d.ts.map +1 -0
- package/lib/typescript/debug/checkCppVersion.d.ts +3 -0
- package/lib/typescript/debug/checkCppVersion.d.ts.map +1 -0
- package/lib/typescript/debug/errors.native.d.ts +13 -0
- package/lib/typescript/debug/errors.native.d.ts.map +1 -0
- package/lib/typescript/debug/jsVersion.d.ts +7 -0
- package/lib/typescript/debug/jsVersion.d.ts.map +1 -0
- package/lib/typescript/debug/logger.d.ts +5 -0
- package/lib/typescript/debug/logger.d.ts.map +1 -0
- package/lib/typescript/debug/slowAnimations.d.ts +2 -0
- package/lib/typescript/debug/slowAnimations.d.ts.map +1 -0
- package/lib/typescript/debug/slowAnimations.native.d.ts +11 -0
- package/lib/typescript/debug/slowAnimations.native.d.ts.map +1 -0
- package/lib/typescript/deprecated.d.ts +19 -0
- package/lib/typescript/deprecated.d.ts.map +1 -0
- package/lib/typescript/featureFlags/featureFlags.d.ts +5 -0
- package/lib/typescript/featureFlags/featureFlags.d.ts.map +1 -0
- package/lib/typescript/featureFlags/featureFlags.native.d.ts +6 -0
- package/lib/typescript/featureFlags/featureFlags.native.d.ts.map +1 -0
- package/lib/typescript/featureFlags/types.d.ts +23 -0
- package/lib/typescript/featureFlags/types.d.ts.map +1 -0
- package/lib/typescript/guardImplementation.native.d.ts +3 -0
- package/lib/typescript/guardImplementation.native.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +19 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/initializers/initializers.d.ts +2 -0
- package/lib/typescript/initializers/initializers.d.ts.map +1 -0
- package/lib/typescript/initializers/initializers.native.d.ts +19 -0
- package/lib/typescript/initializers/initializers.native.d.ts.map +1 -0
- package/lib/typescript/memory/bundleUnpacker.native.d.ts +7 -0
- package/lib/typescript/memory/bundleUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/customSerializableUnpacker.native.d.ts +3 -0
- package/lib/typescript/memory/customSerializableUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/isShareable.d.ts +3 -0
- package/lib/typescript/memory/isShareable.d.ts.map +1 -0
- package/lib/typescript/memory/isSynchronizable.d.ts +3 -0
- package/lib/typescript/memory/isSynchronizable.d.ts.map +1 -0
- package/lib/typescript/memory/remoteFunctionUnpacker.native.d.ts +3 -0
- package/lib/typescript/memory/remoteFunctionUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/serializable.d.ts +7 -0
- package/lib/typescript/memory/serializable.d.ts.map +1 -0
- package/lib/typescript/memory/serializable.native.d.ts +37 -0
- package/lib/typescript/memory/serializable.native.d.ts.map +1 -0
- package/lib/typescript/memory/serializableMappingCache.d.ts +6 -0
- package/lib/typescript/memory/serializableMappingCache.d.ts.map +1 -0
- package/lib/typescript/memory/serializableMappingCache.native.d.ts +13 -0
- package/lib/typescript/memory/serializableMappingCache.native.d.ts.map +1 -0
- package/lib/typescript/memory/shareable.d.ts +15 -0
- package/lib/typescript/memory/shareable.d.ts.map +1 -0
- package/lib/typescript/memory/shareable.native.d.ts +15 -0
- package/lib/typescript/memory/shareable.native.d.ts.map +1 -0
- package/lib/typescript/memory/shareableGuestUnpacker.native.d.ts +4 -0
- package/lib/typescript/memory/shareableGuestUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/shareableHostUnpacker.native.d.ts +4 -0
- package/lib/typescript/memory/shareableHostUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/synchronizable.d.ts +3 -0
- package/lib/typescript/memory/synchronizable.d.ts.map +1 -0
- package/lib/typescript/memory/synchronizable.native.d.ts +3 -0
- package/lib/typescript/memory/synchronizable.native.d.ts.map +1 -0
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts +4 -0
- package/lib/typescript/memory/synchronizableUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/memory/types.d.ts +136 -0
- package/lib/typescript/memory/types.d.ts.map +1 -0
- package/lib/typescript/memory/valueUnpacker.native.d.ts +7 -0
- package/lib/typescript/memory/valueUnpacker.native.d.ts.map +1 -0
- package/lib/typescript/mock.d.ts +2 -0
- package/lib/typescript/mock.d.ts.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/platformChecker.d.ts +2 -0
- package/lib/typescript/platformChecker.d.ts.map +1 -0
- package/lib/typescript/platformChecker.native.d.ts +2 -0
- package/lib/typescript/platformChecker.native.d.ts.map +1 -0
- package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts +6 -0
- package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts +2 -0
- package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts.map +1 -0
- package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/index.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/index.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts +2 -0
- package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts.map +1 -0
- package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts +10 -0
- package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts.map +1 -0
- package/lib/typescript/runtimeKind.d.ts +56 -0
- package/lib/typescript/runtimeKind.d.ts.map +1 -0
- package/lib/typescript/runtimes.d.ts +15 -0
- package/lib/typescript/runtimes.d.ts.map +1 -0
- package/lib/typescript/runtimes.native.d.ts +155 -0
- package/lib/typescript/runtimes.native.d.ts.map +1 -0
- package/lib/typescript/specs/NativeWorkletsModule.d.ts +9 -0
- package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -0
- package/lib/typescript/specs/index.d.ts +3 -0
- package/lib/typescript/specs/index.d.ts.map +1 -0
- package/lib/typescript/threads.d.ts +8 -0
- package/lib/typescript/threads.d.ts.map +1 -0
- package/lib/typescript/threads.native.d.ts +125 -0
- package/lib/typescript/threads.native.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +136 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/lib/typescript/workletFunction.d.ts +26 -0
- package/lib/typescript/workletFunction.d.ts.map +1 -0
- package/package.json +220 -0
- package/plugin/index.d.ts +168 -0
- package/plugin/index.js +2188 -0
- package/scripts/validate-react-native-version.js +43 -0
- package/scripts/worklets_utils.rb +94 -0
- package/src/WorkletsModule/NativeWorklets.native.ts +461 -0
- package/src/WorkletsModule/NativeWorklets.ts +5 -0
- package/src/WorkletsModule/workletsModuleProxy.ts +247 -0
- package/src/bundleMode/metroOverrides.native.ts +33 -0
- package/src/bundleMode/network.native.ts +63 -0
- package/src/debug/bundleMode.native.ts +18 -0
- package/src/debug/bundleMode.ts +5 -0
- package/src/debug/checkCppVersion.ts +34 -0
- package/src/debug/errors.native.ts +74 -0
- package/src/debug/jsVersion.ts +8 -0
- package/src/debug/logger.ts +16 -0
- package/src/debug/slowAnimations.native.ts +15 -0
- package/src/debug/slowAnimations.ts +6 -0
- package/src/deprecated.ts +38 -0
- package/src/featureFlags/featureFlags.native.ts +70 -0
- package/src/featureFlags/featureFlags.ts +20 -0
- package/src/featureFlags/staticFlags.json +6 -0
- package/src/featureFlags/types.ts +32 -0
- package/src/guardImplementation.native.ts +26 -0
- package/src/index.ts +95 -0
- package/src/initializers/initializers.native.ts +218 -0
- package/src/initializers/initializers.ts +24 -0
- package/src/memory/bundleUnpacker.native.ts +59 -0
- package/src/memory/customSerializableUnpacker.native.ts +30 -0
- package/src/memory/isShareable.ts +16 -0
- package/src/memory/isSynchronizable.ts +14 -0
- package/src/memory/remoteFunctionUnpacker.native.ts +27 -0
- package/src/memory/serializable.native.ts +889 -0
- package/src/memory/serializable.ts +36 -0
- package/src/memory/serializableMappingCache.native.ts +37 -0
- package/src/memory/serializableMappingCache.ts +12 -0
- package/src/memory/shareable.native.ts +68 -0
- package/src/memory/shareable.ts +27 -0
- package/src/memory/shareableGuestUnpacker.native.ts +168 -0
- package/src/memory/shareableHostUnpacker.native.ts +31 -0
- package/src/memory/synchronizable.native.ts +17 -0
- package/src/memory/synchronizable.ts +9 -0
- package/src/memory/synchronizableUnpacker.native.ts +65 -0
- package/src/memory/types.ts +191 -0
- package/src/memory/valueUnpacker.native.ts +79 -0
- package/src/mock.ts +111 -0
- package/src/platformChecker.native.ts +3 -0
- package/src/platformChecker.ts +4 -0
- package/src/privateGlobals.d.ts +127 -0
- package/src/runLoop/common/setImmediatePolyfill.ts +20 -0
- package/src/runLoop/common/setIntervalPolyfill.ts +38 -0
- package/src/runLoop/uiRuntime/mockedRequestAnimationFrame.ts +11 -0
- package/src/runLoop/uiRuntime/requestAnimationFrame.ts +87 -0
- package/src/runLoop/uiRuntime/setTimeoutPolyfill.ts +40 -0
- package/src/runLoop/workletRuntime/index.ts +18 -0
- package/src/runLoop/workletRuntime/queueMicrotask.ts +13 -0
- package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +61 -0
- package/src/runLoop/workletRuntime/setTimeout.ts +37 -0
- package/src/runLoop/workletRuntime/taskQueue.ts +44 -0
- package/src/runtimeKind.ts +85 -0
- package/src/runtimes.native.ts +572 -0
- package/src/runtimes.ts +107 -0
- package/src/specs/NativeWorkletsModule.ts +11 -0
- package/src/specs/index.ts +13 -0
- package/src/threads.native.ts +408 -0
- package/src/threads.ts +110 -0
- package/src/types.ts +164 -0
- package/src/workletFunction.ts +41 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
FlatSerializableRef,
|
|
5
|
+
RegistrationData,
|
|
6
|
+
SerializableRef,
|
|
7
|
+
} from './types';
|
|
8
|
+
|
|
9
|
+
export function isSerializableRef<TValue = unknown>(
|
|
10
|
+
value: unknown
|
|
11
|
+
): value is SerializableRef<TValue> {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function createSerializable<TValue>(
|
|
16
|
+
value: TValue
|
|
17
|
+
): SerializableRef<TValue> {
|
|
18
|
+
return value as SerializableRef<TValue>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function makeShareableCloneOnUIRecursive<TValue>(
|
|
22
|
+
value: TValue
|
|
23
|
+
): FlatSerializableRef<TValue> {
|
|
24
|
+
return value as FlatSerializableRef<TValue>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function makeShareable<TValue>(value: TValue): TValue {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function registerCustomSerializable<
|
|
32
|
+
TValue extends object,
|
|
33
|
+
TPacked extends object,
|
|
34
|
+
>(_registrationData: RegistrationData<TValue, TPacked>) {
|
|
35
|
+
// noop
|
|
36
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import type { SerializableRef } from './types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This symbol is used to represent a mapping from the value to itself.
|
|
7
|
+
*
|
|
8
|
+
* It's used to prevent converting a serializable that's already converted - for
|
|
9
|
+
* example a Shared Value that's in worklet's closure.
|
|
10
|
+
*/
|
|
11
|
+
export const serializableMappingFlag = Symbol('serializable flag');
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
During a fast refresh, React holds the same instance of a Mutable
|
|
15
|
+
(that's guaranteed by `useRef`) but `serializableCache` gets regenerated and thus
|
|
16
|
+
becoming empty. This happens when editing the file that contains the definition of this cache.
|
|
17
|
+
|
|
18
|
+
Because of it, `createSerializable` can't find given mapping
|
|
19
|
+
in `serializableCache` for the Mutable and tries to clone it as if it was a regular JS object.
|
|
20
|
+
During cloning we use `Object.entries` to iterate over the keys which throws an error on accessing `_value`.
|
|
21
|
+
For convenience we moved this cache to a separate file so it doesn't scare us with red squiggles.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const cache = new WeakMap<
|
|
25
|
+
object,
|
|
26
|
+
SerializableRef | WeakRef<SerializableRef> | symbol
|
|
27
|
+
>();
|
|
28
|
+
|
|
29
|
+
export const serializableMappingCache = {
|
|
30
|
+
set(
|
|
31
|
+
serializable: object,
|
|
32
|
+
serializableRef?: SerializableRef | WeakRef<SerializableRef>
|
|
33
|
+
): void {
|
|
34
|
+
cache.set(serializable, serializableRef || serializableMappingFlag);
|
|
35
|
+
},
|
|
36
|
+
get: cache.get.bind(cache),
|
|
37
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import type { SerializableRef } from './types';
|
|
4
|
+
|
|
5
|
+
export const serializableMappingCache = {
|
|
6
|
+
set(_serializable: object, _serializableRef?: SerializableRef): void {
|
|
7
|
+
// NOOP
|
|
8
|
+
},
|
|
9
|
+
get(_key: object): object | symbol | SerializableRef {
|
|
10
|
+
return null!;
|
|
11
|
+
},
|
|
12
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { isBundleModeEnabled } from '../debug/bundleMode';
|
|
4
|
+
import { addNoBundleModeGuardImplementation } from '../guardImplementation';
|
|
5
|
+
import { isWorkletFunction } from '../workletFunction';
|
|
6
|
+
import { WorkletsModule } from '../WorkletsModule/NativeWorklets';
|
|
7
|
+
import { createSerializable } from './serializable';
|
|
8
|
+
import type { Shareable, ShareableConfig } from './types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new {@link Shareable} holding the provided initial value. You must
|
|
12
|
+
* explicitly declare which Worklet Runtime will host the Shareable by passing
|
|
13
|
+
* its `runtimeId`. To host on the UI Runtime, pass {@link UIRuntimeId}.
|
|
14
|
+
*
|
|
15
|
+
* @param hostRuntimeId - The `runtimeId` of the Worklet Runtime that will host
|
|
16
|
+
* the Shareable.
|
|
17
|
+
* @param initial - The initial value of the Shareable.
|
|
18
|
+
* @param config - Optional advanced configuration.
|
|
19
|
+
* @returns The created {@link Shareable}.
|
|
20
|
+
* @see {@link https://docs.swmansion.com/react-native-worklets/docs/memory/createShareable | createShareable docs}
|
|
21
|
+
*/
|
|
22
|
+
export function createShareable<
|
|
23
|
+
TValue = unknown,
|
|
24
|
+
THostDecorated = unknown,
|
|
25
|
+
TGuestDecorated = unknown,
|
|
26
|
+
>(
|
|
27
|
+
hostRuntimeId: number,
|
|
28
|
+
initial: TValue,
|
|
29
|
+
config?: ShareableConfig<TValue, THostDecorated, TGuestDecorated>
|
|
30
|
+
): Shareable<TValue, THostDecorated, TGuestDecorated>;
|
|
31
|
+
|
|
32
|
+
export function createShareable<
|
|
33
|
+
TValue = unknown,
|
|
34
|
+
THostDecorated = unknown,
|
|
35
|
+
TGuestDecorated = unknown,
|
|
36
|
+
>(
|
|
37
|
+
hostRuntimeId: number,
|
|
38
|
+
initial: TValue,
|
|
39
|
+
config?: ShareableConfig<TValue, THostDecorated, TGuestDecorated>
|
|
40
|
+
): Shareable<TValue, THostDecorated, TGuestDecorated> {
|
|
41
|
+
const { hostDecorator, guestDecorator, initSynchronously } = config || {};
|
|
42
|
+
if (__DEV__) {
|
|
43
|
+
if (hostDecorator && !isWorkletFunction(hostDecorator)) {
|
|
44
|
+
throw new Error('[Worklets] hostDecorator must be a worklet function');
|
|
45
|
+
}
|
|
46
|
+
if (guestDecorator && !isWorkletFunction(guestDecorator)) {
|
|
47
|
+
throw new Error('[Worklets] guestDecorator must be a worklet function');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const shareableRef = WorkletsModule.createShareable(
|
|
52
|
+
hostRuntimeId,
|
|
53
|
+
createSerializable(initial),
|
|
54
|
+
!!initSynchronously,
|
|
55
|
+
createSerializable(hostDecorator),
|
|
56
|
+
createSerializable(guestDecorator)
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return globalThis.__shareableGuestUnpacker(
|
|
60
|
+
hostRuntimeId,
|
|
61
|
+
shareableRef,
|
|
62
|
+
guestDecorator
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (__DEV__ && !isBundleModeEnabled()) {
|
|
67
|
+
addNoBundleModeGuardImplementation(createShareable);
|
|
68
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import type { Shareable, ShareableConfig } from './types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new {@link Shareable} holding the provided initial value. You must
|
|
7
|
+
* explicitly declare which Worklet Runtime will host the Shareable by passing
|
|
8
|
+
* its `runtimeId`. To host on the UI Runtime, pass {@link UIRuntimeId}.
|
|
9
|
+
*
|
|
10
|
+
* @param hostRuntimeId - The `runtimeId` of the Worklet Runtime that will host
|
|
11
|
+
* the Shareable.
|
|
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
|
+
*/
|
|
17
|
+
export function createShareable<
|
|
18
|
+
TValue = unknown,
|
|
19
|
+
THostDecorated = unknown,
|
|
20
|
+
TGuestDecorated = unknown,
|
|
21
|
+
>(
|
|
22
|
+
_hostRuntimeId: number,
|
|
23
|
+
_initial: TValue,
|
|
24
|
+
_config?: ShareableConfig<TValue, THostDecorated, TGuestDecorated>
|
|
25
|
+
): Shareable<TValue, THostDecorated, TGuestDecorated> {
|
|
26
|
+
throw new Error('[Worklets] `createShareable` is not supported on web.');
|
|
27
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/* eslint-disable n/no-missing-require */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
runOnRuntimeAsyncWithId as BundleRunOnRuntimeAsyncWithId,
|
|
8
|
+
runOnRuntimeSyncWithId as BundleRunOnRuntimeSyncWithId,
|
|
9
|
+
scheduleOnRuntimeWithId as BundleScheduleOnRuntimeWithId,
|
|
10
|
+
} from '../runtimes';
|
|
11
|
+
import type { WorkletFunction } from '../types';
|
|
12
|
+
import type {
|
|
13
|
+
SerializableRef,
|
|
14
|
+
Shareable,
|
|
15
|
+
ShareableGuest,
|
|
16
|
+
ShareableGuestDecorator,
|
|
17
|
+
ShareableHost,
|
|
18
|
+
} from './types';
|
|
19
|
+
|
|
20
|
+
export function installShareableGuestUnpacker() {
|
|
21
|
+
'worklet';
|
|
22
|
+
'no-worklet-closure';
|
|
23
|
+
let runOnRuntimeSyncFromId: typeof BundleRunOnRuntimeSyncWithId;
|
|
24
|
+
let runOnRuntimeAsyncFromId: typeof BundleRunOnRuntimeAsyncWithId;
|
|
25
|
+
let memoize: (
|
|
26
|
+
unpacked: Shareable<unknown>,
|
|
27
|
+
serialized: SerializableRef<unknown>
|
|
28
|
+
) => void;
|
|
29
|
+
|
|
30
|
+
let scheduleOnRuntimeFromId: typeof BundleScheduleOnRuntimeWithId;
|
|
31
|
+
let serializer: (value: unknown) => SerializableRef<unknown>;
|
|
32
|
+
|
|
33
|
+
if (
|
|
34
|
+
globalThis.__RUNTIME_KIND === 1 ||
|
|
35
|
+
globalThis._WORKLETS_BUNDLE_MODE_ENABLED
|
|
36
|
+
) {
|
|
37
|
+
serializer = require('./serializable').createSerializable;
|
|
38
|
+
const { serializableMappingCache } = require('./serializableMappingCache');
|
|
39
|
+
memoize = serializableMappingCache.set.bind(serializableMappingCache);
|
|
40
|
+
|
|
41
|
+
runOnRuntimeSyncFromId = require('../runtimes').runOnRuntimeSyncWithId;
|
|
42
|
+
runOnRuntimeAsyncFromId = require('../runtimes').runOnRuntimeAsyncWithId;
|
|
43
|
+
scheduleOnRuntimeFromId = require('../runtimes').scheduleOnRuntimeWithId;
|
|
44
|
+
} else {
|
|
45
|
+
// Serializer can't be inlined here because it might be yet undefined
|
|
46
|
+
// when the unpacker is installed.
|
|
47
|
+
serializer = (value: unknown) => globalThis.__serializer(value);
|
|
48
|
+
memoize = () => {
|
|
49
|
+
// No-op on Worklet Runtimes outside of Bundle Mode.
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const proxy = globalThis.__workletsModuleProxy;
|
|
53
|
+
runOnRuntimeSyncFromId = ((
|
|
54
|
+
hostId: number,
|
|
55
|
+
worklet: WorkletFunction,
|
|
56
|
+
...args: unknown[]
|
|
57
|
+
) => {
|
|
58
|
+
const serializedWorklet = serializer(() => {
|
|
59
|
+
'worklet';
|
|
60
|
+
'limit-init-data-hoisting';
|
|
61
|
+
return globalThis.__serializer(worklet(...args));
|
|
62
|
+
});
|
|
63
|
+
return proxy.runOnRuntimeSyncWithId(hostId, serializedWorklet);
|
|
64
|
+
}) as typeof BundleRunOnRuntimeSyncWithId;
|
|
65
|
+
|
|
66
|
+
scheduleOnRuntimeFromId = ((
|
|
67
|
+
hostId: number,
|
|
68
|
+
worklet: WorkletFunction,
|
|
69
|
+
...args: unknown[]
|
|
70
|
+
) => {
|
|
71
|
+
proxy.scheduleOnRuntimeWithId(
|
|
72
|
+
hostId,
|
|
73
|
+
serializer(() => {
|
|
74
|
+
'worklet';
|
|
75
|
+
'limit-init-data-hoisting';
|
|
76
|
+
return globalThis.__serializer(worklet(...args));
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
}) as typeof BundleScheduleOnRuntimeWithId;
|
|
80
|
+
|
|
81
|
+
runOnRuntimeAsyncFromId = (() => {
|
|
82
|
+
throw new Error(
|
|
83
|
+
'[Worklets] `Shareable.getAsync` can only be called on the RN Runtime.'
|
|
84
|
+
);
|
|
85
|
+
}) as typeof BundleRunOnRuntimeAsyncWithId;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function shareableGuestUnpacker<TValue>(
|
|
89
|
+
hostId: number,
|
|
90
|
+
shareableRef: SerializableRef<TValue>,
|
|
91
|
+
guestDecorator?: ShareableGuestDecorator<TValue>
|
|
92
|
+
): Shareable<TValue> {
|
|
93
|
+
type Host = ShareableHost<TValue>;
|
|
94
|
+
type Guest = ShareableGuest<TValue>;
|
|
95
|
+
|
|
96
|
+
let shareableGuest = shareableRef as unknown as Shareable<TValue>;
|
|
97
|
+
|
|
98
|
+
shareableGuest.isHost = false;
|
|
99
|
+
shareableGuest.__shareableRef = true;
|
|
100
|
+
|
|
101
|
+
const get = () => {
|
|
102
|
+
'worklet';
|
|
103
|
+
'limit-init-data-hoisting';
|
|
104
|
+
return (shareableGuest as Host).value;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const setWithValue = (value: TValue) => {
|
|
108
|
+
'worklet';
|
|
109
|
+
'limit-init-data-hoisting';
|
|
110
|
+
(shareableGuest as Host).value = value;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const setWithSetter = (setter: (prev: TValue) => TValue) => {
|
|
114
|
+
'worklet';
|
|
115
|
+
'limit-init-data-hoisting';
|
|
116
|
+
const currentValue = (shareableGuest as Host).value;
|
|
117
|
+
const newValue = setter(currentValue);
|
|
118
|
+
(shareableGuest as Host).value = newValue;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
shareableGuest.getAsync = () => {
|
|
122
|
+
return runOnRuntimeAsyncFromId(hostId, get);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
shareableGuest.getSync = () => {
|
|
126
|
+
return runOnRuntimeSyncFromId(hostId, get);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
shareableGuest.setAsync = (value: TValue | ((prev: TValue) => TValue)) => {
|
|
130
|
+
if (typeof value === 'function') {
|
|
131
|
+
scheduleOnRuntimeFromId(
|
|
132
|
+
hostId,
|
|
133
|
+
setWithSetter,
|
|
134
|
+
value as (prev: TValue) => TValue
|
|
135
|
+
);
|
|
136
|
+
} else {
|
|
137
|
+
scheduleOnRuntimeFromId(hostId, setWithValue, value);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
shareableGuest.setSync = (value: TValue | ((prev: TValue) => TValue)) => {
|
|
142
|
+
if (typeof value === 'function') {
|
|
143
|
+
runOnRuntimeSyncFromId(
|
|
144
|
+
hostId,
|
|
145
|
+
setWithSetter,
|
|
146
|
+
value as (prev: TValue) => TValue
|
|
147
|
+
);
|
|
148
|
+
} else {
|
|
149
|
+
runOnRuntimeSyncFromId(hostId, setWithValue, value);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
if (guestDecorator) {
|
|
154
|
+
shareableGuest = guestDecorator(shareableGuest as Guest);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
memoize(shareableGuest, shareableRef);
|
|
158
|
+
return shareableGuest;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
globalThis.__shareableGuestUnpacker = shareableGuestUnpacker;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export type ShareableGuestUnpacker<TValue = unknown> = (
|
|
165
|
+
hostId: number,
|
|
166
|
+
shareableRef: SerializableRef<TValue>,
|
|
167
|
+
decorateGuest?: ShareableGuestDecorator<TValue>
|
|
168
|
+
) => Shareable<TValue>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import type { Shareable, ShareableHost, ShareableHostDecorator } from './types';
|
|
4
|
+
|
|
5
|
+
export function installShareableHostUnpacker() {
|
|
6
|
+
'worklet';
|
|
7
|
+
function shareableHostUnpacker<TValue = unknown>(
|
|
8
|
+
initial: TValue,
|
|
9
|
+
hostDecorator?: ShareableHostDecorator<TValue>
|
|
10
|
+
): Shareable<TValue> {
|
|
11
|
+
let hostShareable = {
|
|
12
|
+
isHost: true,
|
|
13
|
+
__shareableRef: true,
|
|
14
|
+
value: initial,
|
|
15
|
+
} as ShareableHost<TValue>;
|
|
16
|
+
|
|
17
|
+
if (hostDecorator) {
|
|
18
|
+
hostShareable = hostDecorator(hostShareable);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const shareable = hostShareable;
|
|
22
|
+
return shareable;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
globalThis.__shareableHostUnpacker = shareableHostUnpacker;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type ShareableHostUnpacker<TValue = unknown> = (
|
|
29
|
+
initial: TValue,
|
|
30
|
+
decorateHost?: ShareableHostDecorator<TValue>
|
|
31
|
+
) => Shareable<TValue>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { WorkletsModule } from '../WorkletsModule/NativeWorklets';
|
|
4
|
+
import { createSerializable } from './serializable';
|
|
5
|
+
import type { Synchronizable } from './types';
|
|
6
|
+
|
|
7
|
+
export function createSynchronizable<TValue = unknown>(
|
|
8
|
+
initialValue: TValue
|
|
9
|
+
): Synchronizable<TValue> {
|
|
10
|
+
const synchronizableRef = WorkletsModule.createSynchronizable(
|
|
11
|
+
createSerializable(initialValue)
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
return globalThis.__synchronizableUnpacker(
|
|
15
|
+
synchronizableRef
|
|
16
|
+
) as unknown as Synchronizable<TValue>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/* eslint-disable n/no-missing-require */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
import { type Synchronizable, type SynchronizableRef } from './types';
|
|
7
|
+
|
|
8
|
+
export function installSynchronizableUnpacker() {
|
|
9
|
+
'worklet';
|
|
10
|
+
'no-worklet-closure';
|
|
11
|
+
// TODO: Add cache for synchronizables.
|
|
12
|
+
const serializer =
|
|
13
|
+
globalThis.__RUNTIME_KIND === 1 || globalThis._WORKLETS_BUNDLE_MODE_ENABLED
|
|
14
|
+
? require('./serializable').createSerializable
|
|
15
|
+
: (value: unknown) => globalThis.__serializer(value);
|
|
16
|
+
|
|
17
|
+
function synchronizableUnpacker<TValue>(
|
|
18
|
+
synchronizableRef: SynchronizableRef<TValue>
|
|
19
|
+
): Synchronizable<TValue> {
|
|
20
|
+
const synchronizable =
|
|
21
|
+
synchronizableRef as unknown as Synchronizable<TValue>;
|
|
22
|
+
const proxy = globalThis.__workletsModuleProxy;
|
|
23
|
+
|
|
24
|
+
synchronizable.__synchronizableRef = true;
|
|
25
|
+
synchronizable.getDirty = () => {
|
|
26
|
+
return proxy.synchronizableGetDirty(synchronizable);
|
|
27
|
+
};
|
|
28
|
+
synchronizable.getBlocking = () => {
|
|
29
|
+
return proxy.synchronizableGetBlocking(synchronizable);
|
|
30
|
+
};
|
|
31
|
+
synchronizable.setBlocking = (
|
|
32
|
+
valueOrFunction: TValue | ((prev: TValue) => TValue)
|
|
33
|
+
) => {
|
|
34
|
+
let newValue: TValue;
|
|
35
|
+
if (typeof valueOrFunction === 'function') {
|
|
36
|
+
const func = valueOrFunction as (prev: TValue) => TValue;
|
|
37
|
+
synchronizable.lock();
|
|
38
|
+
const prev = synchronizable.getBlocking();
|
|
39
|
+
newValue = func(prev);
|
|
40
|
+
|
|
41
|
+
proxy.synchronizableSetBlocking(synchronizable, serializer(newValue));
|
|
42
|
+
|
|
43
|
+
synchronizable.unlock();
|
|
44
|
+
} else {
|
|
45
|
+
const value = valueOrFunction;
|
|
46
|
+
newValue = value;
|
|
47
|
+
proxy.synchronizableSetBlocking(synchronizable, serializer(newValue));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
synchronizable.lock = () => {
|
|
51
|
+
proxy.synchronizableLock(synchronizable);
|
|
52
|
+
};
|
|
53
|
+
synchronizable.unlock = () => {
|
|
54
|
+
proxy.synchronizableUnlock(synchronizable);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return synchronizable;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
globalThis.__synchronizableUnpacker = synchronizableUnpacker;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type SynchronizableUnpacker = <TValue>(
|
|
64
|
+
synchronizableRef: SynchronizableRef<TValue>
|
|
65
|
+
) => Synchronizable<TValue>;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The below type is used for HostObjects returned by the JSI API that don't
|
|
5
|
+
* have any accessible fields or methods but can carry data that is accessed
|
|
6
|
+
* from the c++ side. We add a field to the type to make it possible for
|
|
7
|
+
* typescript to recognize which JSI methods accept those types as arguments and
|
|
8
|
+
* to be able to correctly type check other methods that may use them. However,
|
|
9
|
+
* this field is not actually defined nor should be used for anything else as
|
|
10
|
+
* assigning any data to those objects will throw an error.
|
|
11
|
+
*/
|
|
12
|
+
export type SerializableRef<TValue = unknown> = {
|
|
13
|
+
__serializableRef: true;
|
|
14
|
+
__nativeStateSerializableJSRef: TValue;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// In case of objects with depth or arrays of objects or arrays of arrays etc.
|
|
18
|
+
// we add this utility type that makes it a `SharaebleRef` of the outermost type.
|
|
19
|
+
export type FlatSerializableRef<TValue> =
|
|
20
|
+
TValue extends SerializableRef<infer TRecursive>
|
|
21
|
+
? SerializableRef<TRecursive>
|
|
22
|
+
: SerializableRef<TValue>;
|
|
23
|
+
|
|
24
|
+
export type SynchronizableRef<TValue = unknown> = {
|
|
25
|
+
__synchronizableRef: true;
|
|
26
|
+
__nativeStateSynchronizableJSRef: TValue;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type Synchronizable<TValue = unknown> = SerializableRef<TValue> &
|
|
30
|
+
SynchronizableRef<TValue> & {
|
|
31
|
+
__synchronizableRef: true;
|
|
32
|
+
getDirty(): TValue;
|
|
33
|
+
getBlocking(): TValue;
|
|
34
|
+
setBlocking(value: TValue | ((prev: TValue) => TValue)): void;
|
|
35
|
+
lock(): void;
|
|
36
|
+
unlock(): void;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Registration data for
|
|
41
|
+
* [registerCustomSerializable](https://docs.swmansion.com/react-native-worklets/docs/memory/registerCustomSerializable)
|
|
42
|
+
* function.
|
|
43
|
+
*/
|
|
44
|
+
export type RegistrationData<TValue extends object, TPacked = unknown> = {
|
|
45
|
+
/**
|
|
46
|
+
* A unique name for the Custom Serializable. It's used to prevent duplicate
|
|
47
|
+
* registrations of the same Custom Serializable. You will get warned if you
|
|
48
|
+
* attempt to register a Custom Serializable with a name that has already been
|
|
49
|
+
* used.
|
|
50
|
+
*/
|
|
51
|
+
name: string;
|
|
52
|
+
/**
|
|
53
|
+
* A worklet that checks whether a given JavaScript value is of the type
|
|
54
|
+
* handled by this Custom Serializable.
|
|
55
|
+
*/
|
|
56
|
+
determine: (value: object) => value is TValue;
|
|
57
|
+
/**
|
|
58
|
+
* A worklet that packs the JavaScript value of type `TValue` into a value
|
|
59
|
+
* that can be serialized by default as Serializable. The function must return
|
|
60
|
+
* a [supported type for
|
|
61
|
+
* Serialization](https://docs.swmansion.com/react-native-worklets/docs/memory/serializable#supported-types).
|
|
62
|
+
*/
|
|
63
|
+
pack: (value: TValue) => TPacked;
|
|
64
|
+
/**
|
|
65
|
+
* A worklet that unpacks the packed value, after it's been deserialized from
|
|
66
|
+
* it's packed form, back into the JavaScript value of type `TValue`.
|
|
67
|
+
*/
|
|
68
|
+
unpack: (value: TPacked) => TValue;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export type SerializationData<TValue extends object, TPacked = unknown> = Omit<
|
|
72
|
+
RegistrationData<TValue, TPacked>,
|
|
73
|
+
'name'
|
|
74
|
+
> & {
|
|
75
|
+
/** Only defined on the RN Runtime. */
|
|
76
|
+
name?: string;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type CustomSerializationRegistry = SerializationData<object, unknown>[];
|
|
80
|
+
|
|
81
|
+
export type ShareableHostProps<TValue = unknown> = {
|
|
82
|
+
value: TValue;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export type ShareableHostMeta = {
|
|
86
|
+
isHost: true;
|
|
87
|
+
__shareableRef: true;
|
|
88
|
+
};
|
|
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
|
+
*/
|
|
95
|
+
export type ShareableHostDecorator<TValue = unknown, TDecorated = unknown> = (
|
|
96
|
+
shareable: ShareableHost<TValue> & TDecorated
|
|
97
|
+
) => ShareableHost<TValue> & TDecorated;
|
|
98
|
+
|
|
99
|
+
export type ShareableGuestMeta = {
|
|
100
|
+
isHost: false;
|
|
101
|
+
__shareableRef: true;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export type ShareableGuestProps<TValue = unknown> = {
|
|
105
|
+
getAsync(): Promise<TValue>;
|
|
106
|
+
getSync(): TValue;
|
|
107
|
+
setAsync(value: TValue | ((prev: TValue) => TValue)): void;
|
|
108
|
+
setSync(value: TValue | ((prev: TValue) => TValue)): void;
|
|
109
|
+
};
|
|
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
|
+
*/
|
|
116
|
+
export type ShareableGuestDecorator<TValue = unknown, TDecorated = unknown> = (
|
|
117
|
+
shareable: ShareableGuest<TValue> & TDecorated
|
|
118
|
+
) => ShareableGuest<TValue> & TDecorated;
|
|
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
|
+
*/
|
|
125
|
+
export type ShareableHost<
|
|
126
|
+
TValue = unknown,
|
|
127
|
+
THostDecorated = unknown,
|
|
128
|
+
> = ShareableHostMeta &
|
|
129
|
+
ShareableHostProps<TValue> &
|
|
130
|
+
(THostDecorated extends object ? THostDecorated : object);
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* A guest-side representation of a {@link Shareable}, used on any runtime other
|
|
134
|
+
* than the host runtime.
|
|
135
|
+
*/
|
|
136
|
+
export type ShareableGuest<
|
|
137
|
+
TValue = unknown,
|
|
138
|
+
TGuestDecorated = unknown,
|
|
139
|
+
> = ShareableGuestMeta &
|
|
140
|
+
ShareableGuestProps<TValue> &
|
|
141
|
+
(TGuestDecorated extends object ? TGuestDecorated : object);
|
|
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
|
+
*/
|
|
150
|
+
export type Shareable<
|
|
151
|
+
TValue = unknown,
|
|
152
|
+
THostDecorated = unknown,
|
|
153
|
+
TGuestDecorated = unknown,
|
|
154
|
+
> =
|
|
155
|
+
| (ShareableHost<TValue, THostDecorated> &
|
|
156
|
+
Partial<
|
|
157
|
+
ShareableGuestProps<TValue> &
|
|
158
|
+
(TGuestDecorated extends object ? Partial<TGuestDecorated> : object)
|
|
159
|
+
>)
|
|
160
|
+
| (ShareableGuest<TValue, TGuestDecorated> &
|
|
161
|
+
Partial<
|
|
162
|
+
ShareableHostProps<TValue> &
|
|
163
|
+
(THostDecorated extends object ? Partial<THostDecorated> : object)
|
|
164
|
+
>);
|
|
165
|
+
|
|
166
|
+
/** Optional advanced configuration for a {@link Shareable}. */
|
|
167
|
+
export type ShareableConfig<TValue, THostDecorated, TGuestDecorated> = {
|
|
168
|
+
/**
|
|
169
|
+
* A worklet that decorates the {@link ShareableHost} with additional
|
|
170
|
+
* properties or methods.
|
|
171
|
+
*/
|
|
172
|
+
hostDecorator?: ShareableHostDecorator<TValue, THostDecorated>;
|
|
173
|
+
/**
|
|
174
|
+
* A worklet that decorates each {@link ShareableGuest} with additional
|
|
175
|
+
* properties or methods.
|
|
176
|
+
*/
|
|
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
|
+
*/
|
|
185
|
+
initSynchronously?: boolean;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
export interface RemoteFunction extends SerializableRef {
|
|
189
|
+
/** Defined when extracted on a Guest Runtime. */
|
|
190
|
+
__remoteFunction: true | undefined;
|
|
191
|
+
}
|