@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
package/src/runtimes.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { RuntimeKind } from './runtimeKind';
|
|
4
|
+
import type {
|
|
5
|
+
WorkletFunction,
|
|
6
|
+
WorkletRuntime,
|
|
7
|
+
WorkletRuntimeConfig,
|
|
8
|
+
} from './types';
|
|
9
|
+
|
|
10
|
+
// is-tree-shakable-suppress
|
|
11
|
+
export const UIRuntimeId = RuntimeKind.UI;
|
|
12
|
+
|
|
13
|
+
export function createWorkletRuntime(
|
|
14
|
+
config?: WorkletRuntimeConfig
|
|
15
|
+
): WorkletRuntime;
|
|
16
|
+
|
|
17
|
+
export function createWorkletRuntime(
|
|
18
|
+
name?: string,
|
|
19
|
+
initializer?: () => void
|
|
20
|
+
): WorkletRuntime;
|
|
21
|
+
|
|
22
|
+
export function createWorkletRuntime(): never {
|
|
23
|
+
throw new Error('[Worklets] `createWorkletRuntime` is not supported on web.');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function runOnRuntime<Args extends unknown[], ReturnValue>(
|
|
27
|
+
workletRuntime: WorkletRuntime,
|
|
28
|
+
worklet: (...args: Args) => ReturnValue
|
|
29
|
+
): WorkletFunction<Args, ReturnValue>;
|
|
30
|
+
|
|
31
|
+
export function runOnRuntime(): never {
|
|
32
|
+
throw new Error('[Worklets] `runOnRuntime` is not supported on web.');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function scheduleOnRuntime<Args extends unknown[], ReturnValue>(
|
|
36
|
+
workletRuntime: WorkletRuntime,
|
|
37
|
+
worklet: (...args: Args) => ReturnValue,
|
|
38
|
+
...args: Args
|
|
39
|
+
): void;
|
|
40
|
+
|
|
41
|
+
export function scheduleOnRuntime(): never {
|
|
42
|
+
throw new Error('[Worklets] `scheduleOnRuntime` is not supported on web.');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function scheduleOnRuntimeWithId<Args extends unknown[], ReturnValue>(
|
|
46
|
+
runtimeId: number,
|
|
47
|
+
worklet: (...args: Args) => ReturnValue,
|
|
48
|
+
...args: Args
|
|
49
|
+
): void;
|
|
50
|
+
|
|
51
|
+
export function scheduleOnRuntimeWithId(): never {
|
|
52
|
+
throw new Error(
|
|
53
|
+
'[Worklets] `scheduleOnRuntimeWithId` is not supported on web.'
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function runOnRuntimeSync<Args extends unknown[], ReturnValue>(
|
|
58
|
+
workletRuntime: WorkletRuntime,
|
|
59
|
+
worklet: (...args: Args) => ReturnValue,
|
|
60
|
+
...args: Args
|
|
61
|
+
): ReturnValue;
|
|
62
|
+
|
|
63
|
+
export function runOnRuntimeSync(): never {
|
|
64
|
+
throw new Error('[Worklets] `runOnRuntimeSync` is not supported on web.');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function runOnRuntimeSyncWithId<Args extends unknown[], ReturnValue>(
|
|
68
|
+
runtimeId: number,
|
|
69
|
+
worklet: (...args: Args) => ReturnValue,
|
|
70
|
+
...args: Args
|
|
71
|
+
): ReturnValue;
|
|
72
|
+
|
|
73
|
+
export function runOnRuntimeSyncWithId(): never {
|
|
74
|
+
throw new Error(
|
|
75
|
+
'[Worklets] `runOnRuntimeSyncWithId` is not supported on web.'
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function runOnRuntimeAsync<Args extends unknown[], ReturnValue>(
|
|
80
|
+
workletRuntime: WorkletRuntime,
|
|
81
|
+
worklet: (...args: Args) => ReturnValue,
|
|
82
|
+
...args: Args
|
|
83
|
+
): Promise<ReturnValue>;
|
|
84
|
+
|
|
85
|
+
export function runOnRuntimeAsync(): never {
|
|
86
|
+
throw new Error('[Worklets] `runOnRuntimeAsync` is not supported on web.');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function runOnRuntimeAsyncWithId<Args extends unknown[], ReturnValue>(
|
|
90
|
+
runtimeId: number,
|
|
91
|
+
worklet: (...args: Args) => ReturnValue,
|
|
92
|
+
...args: Args
|
|
93
|
+
): Promise<ReturnValue>;
|
|
94
|
+
|
|
95
|
+
export function runOnRuntimeAsyncWithId(): never {
|
|
96
|
+
throw new Error(
|
|
97
|
+
'[Worklets] `runOnRuntimeAsyncWithId` is not supported on web.'
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function getUIRuntimeHolder(): object {
|
|
102
|
+
throw new Error('[Worklets] `getUIRuntimeHolder` is not supported on web.');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function getUISchedulerHolder(): object {
|
|
106
|
+
throw new Error('[Worklets] `getUISchedulerHolder` is not supported on web.');
|
|
107
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { type TurboModule, TurboModuleRegistry } from 'react-native';
|
|
4
|
+
|
|
5
|
+
export interface Spec extends TurboModule {
|
|
6
|
+
installTurboModule: (bundleModeEnabled: boolean) => boolean;
|
|
7
|
+
toggleSlowAnimationsOnUIRuntime: () => boolean;
|
|
8
|
+
start: () => boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default TurboModuleRegistry.get<Spec>('WorkletsModule');
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { RuntimeKind } from '../runtimeKind';
|
|
4
|
+
import type { Spec } from './NativeWorkletsModule';
|
|
5
|
+
import RNWorkletsTurboModule from './NativeWorkletsModule';
|
|
6
|
+
|
|
7
|
+
export const WorkletsTurboModule: Spec | null | undefined =
|
|
8
|
+
globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative
|
|
9
|
+
? RNWorkletsTurboModule
|
|
10
|
+
: // In Bundle Mode, on Worklet Runtimes `RNWorkletsTurboModule` isn't
|
|
11
|
+
// available and shouldn't be accessed. We return null here
|
|
12
|
+
// to keep the same codebase for the Bundle Mode and Legacy Eval Mode.
|
|
13
|
+
null;
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { isBundleModeEnabled } from './debug/bundleMode';
|
|
4
|
+
import { getStaticFeatureFlag } from './featureFlags/featureFlags';
|
|
5
|
+
import { addNoBundleModeGuardImplementation } from './guardImplementation';
|
|
6
|
+
import {
|
|
7
|
+
createSerializable,
|
|
8
|
+
makeShareableCloneOnUIRecursive,
|
|
9
|
+
} from './memory/serializable';
|
|
10
|
+
import type { RemoteFunction, SerializableRef } from './memory/types';
|
|
11
|
+
import { RuntimeKind } from './runtimeKind';
|
|
12
|
+
import type { WorkletFunction, WorkletImport } from './types';
|
|
13
|
+
import { isWorkletFunction } from './workletFunction';
|
|
14
|
+
import { WorkletsModule } from './WorkletsModule/NativeWorklets';
|
|
15
|
+
|
|
16
|
+
const SHOULD_CAPTURE_SCHEDULE_STACK =
|
|
17
|
+
__DEV__ && getStaticFeatureFlag('ENABLE_CROSS_RUNTIME_STACK_TRACES');
|
|
18
|
+
|
|
19
|
+
type UIJob<Args extends unknown[] = unknown[], ReturnValue = unknown> = [
|
|
20
|
+
worklet: WorkletFunction<Args, ReturnValue>,
|
|
21
|
+
args: Args,
|
|
22
|
+
resolve: ((value: ReturnValue) => void) | undefined,
|
|
23
|
+
reject: ((reason: unknown) => void) | undefined,
|
|
24
|
+
scheduleStack: string | undefined,
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
let runOnUIQueue: UIJob[] = [];
|
|
28
|
+
|
|
29
|
+
export function setupMicrotasks() {
|
|
30
|
+
'worklet';
|
|
31
|
+
|
|
32
|
+
let microtasksQueue: Array<() => void> = [];
|
|
33
|
+
let isExecutingMicrotasksQueue = false;
|
|
34
|
+
globalThis.queueMicrotask = (callback: () => void) => {
|
|
35
|
+
microtasksQueue.push(callback);
|
|
36
|
+
};
|
|
37
|
+
// TODO: Remove it after support for Reanimated 4.3 is dropped.
|
|
38
|
+
globalThis._microtaskQueueFinalizers = [];
|
|
39
|
+
|
|
40
|
+
globalThis.__callMicrotasks = () => {
|
|
41
|
+
if (isExecutingMicrotasksQueue) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
isExecutingMicrotasksQueue = true;
|
|
46
|
+
for (let index = 0; index < microtasksQueue.length; index += 1) {
|
|
47
|
+
// we use classic 'for' loop because the size of the currentTasks array may change while executing some of the callbacks due to queueMicrotask calls
|
|
48
|
+
microtasksQueue[index]();
|
|
49
|
+
}
|
|
50
|
+
microtasksQueue = [];
|
|
51
|
+
globalThis._microtaskQueueFinalizers.forEach((finalizer) => finalizer());
|
|
52
|
+
} finally {
|
|
53
|
+
isExecutingMicrotasksQueue = false;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Lets you schedule a function to be executed on the [UI
|
|
60
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
|
61
|
+
*
|
|
62
|
+
* - The callback executes asynchronously and doesn't return a value.
|
|
63
|
+
* - Passed function and args are automatically
|
|
64
|
+
* [workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
|
|
65
|
+
* and serialized.
|
|
66
|
+
* - This function cannot be called from the [UI
|
|
67
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime)
|
|
68
|
+
* or a [Worker
|
|
69
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worker-runtime),
|
|
70
|
+
* unless you have the [Bundle Mode](/docs/bundleMode/) enabled.
|
|
71
|
+
*
|
|
72
|
+
* @param fun - A reference to a function you want to schedule on the [UI
|
|
73
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
|
74
|
+
* @param args - Arguments to pass to the function.
|
|
75
|
+
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/scheduleOnUI
|
|
76
|
+
*/
|
|
77
|
+
// @ts-expect-error This overload is correct since it's what user sees in their code
|
|
78
|
+
// before it's transformed by Worklets Babel plugin.
|
|
79
|
+
export function scheduleOnUI<Args extends unknown[], ReturnValue>(
|
|
80
|
+
worklet: (...args: Args) => ReturnValue,
|
|
81
|
+
...args: Args
|
|
82
|
+
): void;
|
|
83
|
+
|
|
84
|
+
export function scheduleOnUI<Args extends unknown[], ReturnValue>(
|
|
85
|
+
worklet: WorkletFunction<Args, ReturnValue>,
|
|
86
|
+
...args: Args
|
|
87
|
+
): void {
|
|
88
|
+
if (
|
|
89
|
+
__DEV__ &&
|
|
90
|
+
!isWorkletFunction(worklet) &&
|
|
91
|
+
!(worklet as unknown as WorkletImport).__bundleData
|
|
92
|
+
) {
|
|
93
|
+
throw new Error(
|
|
94
|
+
'[Worklets] `scheduleOnUI` can only be used with worklets.'
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
if (__DEV__) {
|
|
98
|
+
// in DEV mode we call serializable conversion here because in case the object
|
|
99
|
+
// can't be converted, we will get a meaningful stack-trace as opposed to the
|
|
100
|
+
// situation when conversion is only done via microtask queue. This does not
|
|
101
|
+
// make the app particularily less efficient as converted objects are cached
|
|
102
|
+
// and for a given worklet the conversion only happens once.
|
|
103
|
+
createSerializable(worklet);
|
|
104
|
+
createSerializable(args);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
enqueueUI(worklet, args);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Lets you asynchronously run
|
|
112
|
+
* [workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
|
|
113
|
+
* functions on the [UI
|
|
114
|
+
* thread](https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI/).
|
|
115
|
+
*
|
|
116
|
+
* This method does not schedule the work immediately but instead waits for
|
|
117
|
+
* other worklets to be scheduled within the same JS loop. It uses
|
|
118
|
+
* queueMicrotask to schedule all the worklets at once making sure they will run
|
|
119
|
+
* within the same frame boundaries on the UI thread.
|
|
120
|
+
*
|
|
121
|
+
* @param fun - A reference to a function you want to execute on the [UI
|
|
122
|
+
* thread](https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI/)
|
|
123
|
+
* from the [JavaScript
|
|
124
|
+
* thread](https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI/).
|
|
125
|
+
* @returns A function that accepts arguments for the function passed as the
|
|
126
|
+
* first argument.
|
|
127
|
+
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUI @deprecated Use `scheduleOnUI` instead.
|
|
128
|
+
*/
|
|
129
|
+
// @ts-expect-error This overload is correct since it's what user sees in their code
|
|
130
|
+
// before it's transformed by Worklets Babel plugin.
|
|
131
|
+
export function runOnUI<Args extends unknown[], ReturnValue>(
|
|
132
|
+
worklet: (...args: Args) => ReturnValue
|
|
133
|
+
): (...args: Args) => void;
|
|
134
|
+
|
|
135
|
+
export function runOnUI<Args extends unknown[], ReturnValue>(
|
|
136
|
+
worklet: WorkletFunction<Args, ReturnValue>
|
|
137
|
+
): (...args: Args) => void {
|
|
138
|
+
if (
|
|
139
|
+
__DEV__ &&
|
|
140
|
+
!isWorkletFunction(worklet) &&
|
|
141
|
+
!(worklet as unknown as WorkletImport).__bundleData
|
|
142
|
+
) {
|
|
143
|
+
throw new Error('[Worklets] `runOnUI` can only be used with worklets.');
|
|
144
|
+
}
|
|
145
|
+
return (...args: Args) => {
|
|
146
|
+
scheduleOnUI(worklet, ...args);
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Lets you run a function synchronously on the [UI
|
|
152
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime)
|
|
153
|
+
* from the [RN
|
|
154
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#rn-runtime).
|
|
155
|
+
* Passed function and args are automatically
|
|
156
|
+
* [workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
|
|
157
|
+
* and serialized.
|
|
158
|
+
*
|
|
159
|
+
* - This function cannot be called from the [UI
|
|
160
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
|
161
|
+
* - This function cannot be called from a [Worker
|
|
162
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#worker-runtime).
|
|
163
|
+
*
|
|
164
|
+
* @param fun - A reference to a function you want to execute on the [UI
|
|
165
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
|
166
|
+
* @param args - Arguments to pass to the function.
|
|
167
|
+
* @returns The return value of the function passed as the first argument.
|
|
168
|
+
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUISync
|
|
169
|
+
*/
|
|
170
|
+
// @ts-expect-error This overload is correct since it's what user sees in their code
|
|
171
|
+
// before it's transformed by Worklets Babel plugin.
|
|
172
|
+
export function runOnUISync<Args extends unknown[], ReturnValue>(
|
|
173
|
+
worklet: (...args: Args) => ReturnValue,
|
|
174
|
+
...args: Args
|
|
175
|
+
): ReturnValue;
|
|
176
|
+
|
|
177
|
+
export function runOnUISync<Args extends unknown[], ReturnValue>(
|
|
178
|
+
worklet: WorkletFunction<Args, ReturnValue>,
|
|
179
|
+
...args: Args
|
|
180
|
+
): ReturnValue {
|
|
181
|
+
return WorkletsModule.runOnUISync(
|
|
182
|
+
createSerializable(() => {
|
|
183
|
+
'worklet';
|
|
184
|
+
const result = worklet(...args);
|
|
185
|
+
return makeShareableCloneOnUIRecursive(result);
|
|
186
|
+
}),
|
|
187
|
+
SHOULD_CAPTURE_SCHEDULE_STACK ? (new Error().stack ?? '') : undefined
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// @ts-expect-error This overload is correct since it's what user sees in their code
|
|
192
|
+
// before it's transformed by Worklets Babel plugin.
|
|
193
|
+
export function executeOnUIRuntimeSync<Args extends unknown[], ReturnValue>(
|
|
194
|
+
worklet: (...args: Args) => ReturnValue
|
|
195
|
+
): (...args: Args) => ReturnValue;
|
|
196
|
+
|
|
197
|
+
export function executeOnUIRuntimeSync<Args extends unknown[], ReturnValue>(
|
|
198
|
+
worklet: WorkletFunction<Args, ReturnValue>
|
|
199
|
+
): (...args: Args) => ReturnValue {
|
|
200
|
+
return (...args) => {
|
|
201
|
+
return runOnUISync(worklet, ...args);
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function runWorkletOnJS<Args extends unknown[], ReturnValue>(
|
|
206
|
+
worklet: WorkletFunction<Args, ReturnValue>,
|
|
207
|
+
...args: Args
|
|
208
|
+
): void {
|
|
209
|
+
// remote function that calls a worklet synchronously on the JS runtime
|
|
210
|
+
worklet(...args);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Lets you schedule a function to be executed on the RN runtime from any
|
|
215
|
+
* runtime. Check
|
|
216
|
+
* {@link https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds}
|
|
217
|
+
* for more information about the different runtime kinds.
|
|
218
|
+
*
|
|
219
|
+
* Scheduling function from the RN Runtime (we are already on RN Runtime) simply
|
|
220
|
+
* uses `queueMicrotask`.
|
|
221
|
+
*
|
|
222
|
+
* When functions need to be scheduled from the UI Runtime, first function and
|
|
223
|
+
* args are serialized and then the system passes the scheduling responsibility
|
|
224
|
+
* to the JSScheduler. The JSScheduler then uses the RN CallInvoker to schedule
|
|
225
|
+
* the function asynchronously on the JavaScript thread by calling
|
|
226
|
+
* `jsCallInvoker_->invokeAsync()`.
|
|
227
|
+
*
|
|
228
|
+
* When called from a Worker Runtime, it uses the same JSScheduler mechanism.
|
|
229
|
+
*
|
|
230
|
+
* @param fun - A function you want to schedule on the RN runtime. A function
|
|
231
|
+
* can be a worklet, a remote function or a regular function.
|
|
232
|
+
* @param args - Arguments to pass to the function.
|
|
233
|
+
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/scheduleOnRN
|
|
234
|
+
*/
|
|
235
|
+
export function scheduleOnRN<Args extends unknown[], ReturnValue>(
|
|
236
|
+
fun:
|
|
237
|
+
| ((...args: Args) => ReturnValue)
|
|
238
|
+
| RemoteFunction
|
|
239
|
+
| WorkletFunction<Args, ReturnValue>,
|
|
240
|
+
...args: Args
|
|
241
|
+
): void {
|
|
242
|
+
'worklet';
|
|
243
|
+
if (globalThis.__RUNTIME_KIND === RuntimeKind.ReactNative) {
|
|
244
|
+
// if we are already on the JS thread, we just schedule the worklet on the JS queue
|
|
245
|
+
queueMicrotask(
|
|
246
|
+
args.length
|
|
247
|
+
? () => (fun as (...args: Args) => ReturnValue)(...args)
|
|
248
|
+
: (fun as () => ReturnValue)
|
|
249
|
+
);
|
|
250
|
+
} else if (isWorkletFunction<Args, ReturnValue>(fun)) {
|
|
251
|
+
// If `fun` is a worklet, we schedule a call of a remote function `runWorkletOnJS`
|
|
252
|
+
// and pass the worklet as a first argument followed by original arguments.
|
|
253
|
+
scheduleOnRN(runWorkletOnJS<Args, ReturnValue>, fun, ...args);
|
|
254
|
+
} else {
|
|
255
|
+
globalThis.__workletsModuleProxy.scheduleOnRN(
|
|
256
|
+
fun,
|
|
257
|
+
(args.length > 0
|
|
258
|
+
? globalThis.__serializer(args)
|
|
259
|
+
: undefined) as SerializableRef<Args>
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Lets you asynchronously run
|
|
266
|
+
* non-[workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
|
|
267
|
+
* functions that couldn't otherwise run on the [UI
|
|
268
|
+
* thread](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#ui-thread).
|
|
269
|
+
* This applies to most external libraries as they don't have their functions
|
|
270
|
+
* marked with "worklet"; directive.
|
|
271
|
+
*
|
|
272
|
+
* @param fun - A reference to a function you want to execute on the JavaScript
|
|
273
|
+
* thread from the UI thread.
|
|
274
|
+
* @returns A function that accepts arguments for the function passed as the
|
|
275
|
+
* first argument.
|
|
276
|
+
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnJS
|
|
277
|
+
*/
|
|
278
|
+
/** @deprecated Use `scheduleOnRN` instead. */
|
|
279
|
+
export function runOnJS<Args extends unknown[], ReturnValue>(
|
|
280
|
+
fun:
|
|
281
|
+
| ((...args: Args) => ReturnValue)
|
|
282
|
+
| RemoteFunction
|
|
283
|
+
| WorkletFunction<Args, ReturnValue>
|
|
284
|
+
): (...args: Args) => void {
|
|
285
|
+
'worklet';
|
|
286
|
+
return (...args: Args) => {
|
|
287
|
+
scheduleOnRN(fun, ...args);
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Lets you asynchronously run
|
|
293
|
+
* [workletized](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#to-workletize)
|
|
294
|
+
* functions on the [UI
|
|
295
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
|
296
|
+
*
|
|
297
|
+
* - This method does not schedule the work immediately but instead waits for
|
|
298
|
+
* other worklets to be scheduled within the same JS loop. It uses
|
|
299
|
+
* queueMicrotask to schedule all the worklets at once making sure they will
|
|
300
|
+
* run within the same frame boundaries on the UI thread.
|
|
301
|
+
*
|
|
302
|
+
* @param fun - A reference to a function you want to execute on the [UI
|
|
303
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/runtimeKinds#ui-runtime).
|
|
304
|
+
* from the [JavaScript
|
|
305
|
+
* Runtime](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#javascript-runtime).
|
|
306
|
+
* @returns A promise that resolves to the return value of the function passed
|
|
307
|
+
* as the first argument.
|
|
308
|
+
* @see https://docs.swmansion.com/react-native-worklets/docs/threading/runOnUIAsync
|
|
309
|
+
*/
|
|
310
|
+
export function runOnUIAsync<Args extends unknown[], ReturnValue>(
|
|
311
|
+
worklet: (...args: Args) => ReturnValue,
|
|
312
|
+
...args: Args
|
|
313
|
+
): Promise<ReturnValue> {
|
|
314
|
+
if (__DEV__) {
|
|
315
|
+
if (!isWorkletFunction(worklet)) {
|
|
316
|
+
throw new Error(
|
|
317
|
+
'[Worklets] `runOnUIAsync` can only be used with worklets.'
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return new Promise<ReturnValue>((resolve, reject) => {
|
|
322
|
+
if (__DEV__) {
|
|
323
|
+
// in DEV mode we call serializable conversion here because in case the object
|
|
324
|
+
// can't be converted, we will get a meaningful stack-trace as opposed to the
|
|
325
|
+
// situation when conversion is only done via microtask queue. This does not
|
|
326
|
+
// make the app particularily less efficient as converted objects are cached
|
|
327
|
+
// and for a given worklet the conversion only happens once.
|
|
328
|
+
createSerializable(worklet);
|
|
329
|
+
createSerializable(args);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
enqueueUI(
|
|
333
|
+
worklet as WorkletFunction<Args, ReturnValue>,
|
|
334
|
+
args,
|
|
335
|
+
resolve,
|
|
336
|
+
reject
|
|
337
|
+
);
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function enqueueUI<Args extends unknown[], ReturnValue>(
|
|
342
|
+
worklet: WorkletFunction<Args, ReturnValue>,
|
|
343
|
+
args: Args,
|
|
344
|
+
resolve?: (value: ReturnValue) => void,
|
|
345
|
+
reject?: (reason: unknown) => void
|
|
346
|
+
): void {
|
|
347
|
+
const scheduleStack = SHOULD_CAPTURE_SCHEDULE_STACK
|
|
348
|
+
? new Error().stack
|
|
349
|
+
: undefined;
|
|
350
|
+
const job = [worklet, args, resolve, reject, scheduleStack] as UIJob<
|
|
351
|
+
Args,
|
|
352
|
+
ReturnValue
|
|
353
|
+
>;
|
|
354
|
+
runOnUIQueue.push(job as unknown as UIJob);
|
|
355
|
+
if (runOnUIQueue.length === 1) {
|
|
356
|
+
flushUIQueue();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function flushUIQueue(): void {
|
|
361
|
+
queueMicrotask(() => {
|
|
362
|
+
const queue = runOnUIQueue;
|
|
363
|
+
runOnUIQueue = [];
|
|
364
|
+
const jobWorklets = queue.map(
|
|
365
|
+
([workletFunction, workletArgs, resolve, reject]) =>
|
|
366
|
+
createSerializable(() => {
|
|
367
|
+
'worklet';
|
|
368
|
+
try {
|
|
369
|
+
const result = workletFunction(...workletArgs);
|
|
370
|
+
if (resolve) {
|
|
371
|
+
const serializedResult = globalThis.__serializer(result);
|
|
372
|
+
globalThis.__workletsModuleProxy.handlePromise(
|
|
373
|
+
resolve,
|
|
374
|
+
serializedResult
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
} catch (error) {
|
|
378
|
+
if (reject) {
|
|
379
|
+
const serializedError = globalThis.__serializer(error);
|
|
380
|
+
globalThis.__workletsModuleProxy.handlePromise(
|
|
381
|
+
reject,
|
|
382
|
+
serializedError
|
|
383
|
+
);
|
|
384
|
+
} else {
|
|
385
|
+
throw error;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
})
|
|
389
|
+
);
|
|
390
|
+
const scheduleStacks = SHOULD_CAPTURE_SCHEDULE_STACK
|
|
391
|
+
? (queue.map(([, , , , scheduleStack]) => scheduleStack) as string[])
|
|
392
|
+
: undefined;
|
|
393
|
+
WorkletsModule.scheduleOnUI(
|
|
394
|
+
WorkletsModule.createSerializableArray(jobWorklets),
|
|
395
|
+
scheduleStacks
|
|
396
|
+
);
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (__DEV__ && !isBundleModeEnabled()) {
|
|
401
|
+
/**
|
|
402
|
+
* QoL guards to give a meaningful error message when the user tries to call
|
|
403
|
+
* these functions on Worklet Runtimes outside of the Bundle Mode.
|
|
404
|
+
*/
|
|
405
|
+
addNoBundleModeGuardImplementation(runOnUIAsync);
|
|
406
|
+
addNoBundleModeGuardImplementation(runOnUISync);
|
|
407
|
+
addNoBundleModeGuardImplementation(scheduleOnUI);
|
|
408
|
+
}
|
package/src/threads.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import { IS_JEST } from './platformChecker';
|
|
4
|
+
import { mockedRequestAnimationFrame } from './runLoop/uiRuntime/mockedRequestAnimationFrame';
|
|
5
|
+
|
|
6
|
+
export function scheduleOnUI<Args extends unknown[], ReturnValue>(
|
|
7
|
+
worklet: (...args: Args) => ReturnValue,
|
|
8
|
+
...args: Args
|
|
9
|
+
): void {
|
|
10
|
+
enqueueUI(worklet, args);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function runOnUI<Args extends unknown[], ReturnValue>(
|
|
14
|
+
worklet: (...args: Args) => ReturnValue
|
|
15
|
+
): (...args: Args) => void {
|
|
16
|
+
return (...args) => {
|
|
17
|
+
scheduleOnUI(worklet, ...args);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function runOnUISync<Args extends unknown[], ReturnValue>(
|
|
22
|
+
worklet: (...args: Args) => ReturnValue,
|
|
23
|
+
...args: Args
|
|
24
|
+
): ReturnValue;
|
|
25
|
+
|
|
26
|
+
export function runOnUISync(): never {
|
|
27
|
+
throw new Error('[Worklets] `runOnUISync` is not supported on web.');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function executeOnUIRuntimeSync<Args extends unknown[], ReturnValue>(
|
|
31
|
+
worklet: (...args: Args) => ReturnValue
|
|
32
|
+
): (...args: Args) => ReturnValue;
|
|
33
|
+
|
|
34
|
+
export function executeOnUIRuntimeSync(): never {
|
|
35
|
+
throw new Error(
|
|
36
|
+
'[Worklets] `executeOnUIRuntimeSync` is not supported on web.'
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function runOnJS<Args extends unknown[], ReturnValue>(
|
|
41
|
+
fun: (...args: Args) => ReturnValue
|
|
42
|
+
): (...args: Args) => void {
|
|
43
|
+
return (...args) => scheduleOnRN(fun, ...args);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function scheduleOnRN<Args extends unknown[], ReturnValue>(
|
|
47
|
+
fun: (...args: Args) => ReturnValue,
|
|
48
|
+
...args: Args
|
|
49
|
+
): void {
|
|
50
|
+
queueMicrotask(
|
|
51
|
+
args.length
|
|
52
|
+
? () => (fun as (...args: Args) => ReturnValue)(...args)
|
|
53
|
+
: (fun as () => ReturnValue)
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function runOnUIAsync<Args extends unknown[], ReturnValue>(
|
|
58
|
+
worklet: (...args: Args) => ReturnValue,
|
|
59
|
+
...args: Args
|
|
60
|
+
): Promise<ReturnValue> {
|
|
61
|
+
return new Promise<ReturnValue>((resolve) => {
|
|
62
|
+
enqueueUI(worklet, args, resolve);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type UIJob<Args extends unknown[] = unknown[], ReturnValue = unknown> = [
|
|
67
|
+
worklet: (...args: Args) => ReturnValue,
|
|
68
|
+
args: Args,
|
|
69
|
+
resolve?: (value: ReturnValue) => void,
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
let runOnUIQueue: UIJob[] = [];
|
|
73
|
+
|
|
74
|
+
function enqueueUI<Args extends unknown[], ReturnValue>(
|
|
75
|
+
worklet: (...args: Args) => ReturnValue,
|
|
76
|
+
args: Args,
|
|
77
|
+
resolve?: (value: ReturnValue) => void
|
|
78
|
+
): void {
|
|
79
|
+
if (IS_JEST) {
|
|
80
|
+
mockedRequestAnimationFrame(() => {
|
|
81
|
+
const result = worklet(...args);
|
|
82
|
+
resolve?.(result);
|
|
83
|
+
});
|
|
84
|
+
} else {
|
|
85
|
+
const job = [worklet, args, resolve];
|
|
86
|
+
runOnUIQueue.push(job as UIJob);
|
|
87
|
+
if (runOnUIQueue.length === 1) {
|
|
88
|
+
flushUIQueue();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function flushUIQueue(): void {
|
|
94
|
+
queueMicrotask(() => {
|
|
95
|
+
const queue = runOnUIQueue;
|
|
96
|
+
runOnUIQueue = [];
|
|
97
|
+
requestAnimationFrameImpl(() => {
|
|
98
|
+
queue.forEach(([workletFunction, workletArgs, jobResolve]) => {
|
|
99
|
+
const result = workletFunction(...workletArgs);
|
|
100
|
+
if (jobResolve) {
|
|
101
|
+
jobResolve(result);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const requestAnimationFrameImpl = !globalThis.requestAnimationFrame
|
|
109
|
+
? mockedRequestAnimationFrame
|
|
110
|
+
: globalThis.requestAnimationFrame;
|