@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,75 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#ifndef NDEBUG
|
|
4
|
+
|
|
5
|
+
#include <react/debug/react_native_assert.h>
|
|
6
|
+
|
|
7
|
+
#include <cxxabi.h>
|
|
8
|
+
|
|
9
|
+
#include <atomic>
|
|
10
|
+
#include <cassert>
|
|
11
|
+
#include <cstdlib>
|
|
12
|
+
#include <iostream>
|
|
13
|
+
#include <string>
|
|
14
|
+
|
|
15
|
+
#ifdef ANDROID
|
|
16
|
+
#include <android/log.h>
|
|
17
|
+
#endif // ANDROID
|
|
18
|
+
|
|
19
|
+
namespace worklets {
|
|
20
|
+
|
|
21
|
+
// This is a class that counts how many instances of a different class there
|
|
22
|
+
// are. It is meant only to be used with classes that should only have one
|
|
23
|
+
// instance.
|
|
24
|
+
|
|
25
|
+
template <class T>
|
|
26
|
+
class SingleInstanceChecker {
|
|
27
|
+
public:
|
|
28
|
+
SingleInstanceChecker();
|
|
29
|
+
~SingleInstanceChecker();
|
|
30
|
+
|
|
31
|
+
private:
|
|
32
|
+
void assertWithMessage(bool condition, const std::string &message) {
|
|
33
|
+
if (!condition) {
|
|
34
|
+
#ifdef ANDROID
|
|
35
|
+
__android_log_print(ANDROID_LOG_WARN, "Worklets", "%s", message.c_str());
|
|
36
|
+
#else
|
|
37
|
+
std::cerr << "[Worklets] " << message << std::endl;
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
#ifdef IS_REANIMATED_EXAMPLE_APP
|
|
41
|
+
react_native_assert(false && "SingleInstanceChecker failed");
|
|
42
|
+
#endif
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// A static field will exist separately for every class template.
|
|
47
|
+
// This has to be inline for automatic initialization.
|
|
48
|
+
inline static std::atomic<int> instanceCount_;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
template <class T>
|
|
52
|
+
SingleInstanceChecker<T>::SingleInstanceChecker() {
|
|
53
|
+
int status = 0;
|
|
54
|
+
char *demangled = __cxxabiv1::__cxa_demangle(typeid(T).name(), nullptr, nullptr, &status);
|
|
55
|
+
std::string className = (status == 0 && demangled != nullptr) ? demangled : typeid(T).name();
|
|
56
|
+
std::free(demangled);
|
|
57
|
+
|
|
58
|
+
// React Native can spawn up to two instances of a Native Module at the same
|
|
59
|
+
// time. This happens during a reload when a new instance of React Native is
|
|
60
|
+
// created while simultaneously the old one is torn down.
|
|
61
|
+
instanceCount_++;
|
|
62
|
+
assertWithMessage(
|
|
63
|
+
instanceCount_ <= 2,
|
|
64
|
+
"[Worklets] More than two instances of " + className +
|
|
65
|
+
" present. This may indicate a memory leak due to a retain cycle.");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
template <class T>
|
|
69
|
+
SingleInstanceChecker<T>::~SingleInstanceChecker() {
|
|
70
|
+
instanceCount_--;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
} // namespace worklets
|
|
74
|
+
|
|
75
|
+
#endif // NDEBUG
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <condition_variable>
|
|
4
|
+
#include <mutex>
|
|
5
|
+
#include <queue>
|
|
6
|
+
#include <utility>
|
|
7
|
+
|
|
8
|
+
namespace worklets {
|
|
9
|
+
|
|
10
|
+
//
|
|
11
|
+
// Copyright (c) 2013 Juan Palacios juan.palacios.puyana@gmail.com
|
|
12
|
+
// Subject to the BSD 2-Clause License
|
|
13
|
+
// - see < https://opensource.org/license/bsd-2-clause/ >
|
|
14
|
+
//
|
|
15
|
+
template <typename T>
|
|
16
|
+
class ThreadSafeQueue {
|
|
17
|
+
public:
|
|
18
|
+
T pop() {
|
|
19
|
+
std::unique_lock<std::mutex> mlock(mutex_);
|
|
20
|
+
while (queue_.empty()) {
|
|
21
|
+
cond_.wait(mlock);
|
|
22
|
+
}
|
|
23
|
+
const auto item = queue_.front();
|
|
24
|
+
queue_.pop();
|
|
25
|
+
return item;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
void push(T &&item) {
|
|
29
|
+
std::unique_lock<std::mutex> mlock(mutex_);
|
|
30
|
+
queue_.push(std::move(item));
|
|
31
|
+
mlock.unlock();
|
|
32
|
+
cond_.notify_one();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
bool empty() const {
|
|
36
|
+
std::unique_lock<std::mutex> mlock(mutex_);
|
|
37
|
+
const auto res = queue_.empty();
|
|
38
|
+
mlock.unlock();
|
|
39
|
+
cond_.notify_one();
|
|
40
|
+
return res;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private:
|
|
44
|
+
std::queue<T> queue_;
|
|
45
|
+
mutable std::mutex mutex_;
|
|
46
|
+
mutable std::condition_variable cond_;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
} // namespace worklets
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#include <worklets/Tools/UIScheduler.h>
|
|
2
|
+
|
|
3
|
+
#include <utility>
|
|
4
|
+
|
|
5
|
+
namespace worklets {
|
|
6
|
+
|
|
7
|
+
void UIScheduler::scheduleOnUI(std::function<void()> job) {
|
|
8
|
+
uiJobs_.push(std::move(job));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
void UIScheduler::triggerUI() {
|
|
12
|
+
scheduledOnUI_ = false;
|
|
13
|
+
while (!uiJobs_.empty()) {
|
|
14
|
+
const auto job = uiJobs_.pop();
|
|
15
|
+
job();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
} // namespace worklets
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <worklets/Tools/ThreadSafeQueue.h>
|
|
4
|
+
|
|
5
|
+
#include <ReactCommon/CallInvoker.h>
|
|
6
|
+
|
|
7
|
+
#include <atomic>
|
|
8
|
+
|
|
9
|
+
namespace worklets {
|
|
10
|
+
|
|
11
|
+
class UIScheduler {
|
|
12
|
+
public:
|
|
13
|
+
virtual void scheduleOnUI(std::function<void()> job);
|
|
14
|
+
virtual void triggerUI();
|
|
15
|
+
virtual ~UIScheduler() = default;
|
|
16
|
+
|
|
17
|
+
protected:
|
|
18
|
+
std::atomic<bool> scheduledOnUI_{false};
|
|
19
|
+
ThreadSafeQueue<std::function<void()>> uiJobs_;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
} // namespace worklets
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#include <worklets/Tools/VersionUtils.h>
|
|
2
|
+
|
|
3
|
+
#include <iostream>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <regex>
|
|
6
|
+
#include <string>
|
|
7
|
+
|
|
8
|
+
using namespace facebook;
|
|
9
|
+
|
|
10
|
+
namespace worklets {
|
|
11
|
+
|
|
12
|
+
bool matchVersion(const std::string &version1, const std::string &version2) {
|
|
13
|
+
std::regex pattern("^(\\d+)\\.(\\d+)\\.\\d+$");
|
|
14
|
+
std::smatch mv1;
|
|
15
|
+
std::smatch mv2;
|
|
16
|
+
if (std::regex_match(version1, mv1, pattern) && std::regex_match(version2, mv2, pattern)) {
|
|
17
|
+
return mv1[1].str() == mv2[1].str() && mv1[2].str() == mv2[2].str();
|
|
18
|
+
} else {
|
|
19
|
+
return version1 == version2;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
void checkJSVersion(
|
|
24
|
+
jsi::Runtime &runtime,
|
|
25
|
+
jsi::Value &jsVersionValue,
|
|
26
|
+
const std::shared_ptr<worklets::JSLogger> &jsLogger,
|
|
27
|
+
const std::string &cppVersion,
|
|
28
|
+
const std::string &libraryName,
|
|
29
|
+
const std::string &docsBaseUrl) {
|
|
30
|
+
const auto libraryPrefix = std::string("[" + libraryName + "] ");
|
|
31
|
+
|
|
32
|
+
if (jsVersionValue.isUndefined()) {
|
|
33
|
+
jsLogger->warnOnJS(
|
|
34
|
+
std::string(
|
|
35
|
+
libraryPrefix +
|
|
36
|
+
"C++ side failed to resolve JavaScript code "
|
|
37
|
+
"version\n") +
|
|
38
|
+
"See " + docsBaseUrl +
|
|
39
|
+
"/guides/"
|
|
40
|
+
"troubleshooting#c-side-failed-to-resolve-javascript-code-version` for "
|
|
41
|
+
"more details.");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const auto jsVersion = jsVersionValue.asString(runtime).utf8(runtime);
|
|
46
|
+
|
|
47
|
+
if (!matchVersion(cppVersion, jsVersion)) {
|
|
48
|
+
jsLogger->warnOnJS(
|
|
49
|
+
std::string(
|
|
50
|
+
libraryPrefix +
|
|
51
|
+
"Mismatch between C++ code version and "
|
|
52
|
+
"JavaScript code version (") +
|
|
53
|
+
cppVersion + " vs. " + jsVersion + " respectively).\n" + "See " + docsBaseUrl +
|
|
54
|
+
"/guides/"
|
|
55
|
+
"troubleshooting#mismatch-between-c-code-version-and-javascript-code-"
|
|
56
|
+
"version` for more details.");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}; // namespace worklets
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <worklets/Tools/JSLogger.h>
|
|
4
|
+
|
|
5
|
+
#include <jsi/jsi.h>
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <regex>
|
|
8
|
+
#include <string>
|
|
9
|
+
|
|
10
|
+
using namespace facebook;
|
|
11
|
+
|
|
12
|
+
namespace worklets {
|
|
13
|
+
|
|
14
|
+
bool matchVersion(const std::string &version1, const std::string &version2);
|
|
15
|
+
|
|
16
|
+
void checkJSVersion(
|
|
17
|
+
jsi::Runtime &runtime,
|
|
18
|
+
jsi::Value &jsVersionValue,
|
|
19
|
+
const std::shared_ptr<worklets::JSLogger> &jsLogger,
|
|
20
|
+
const std::string &cppVersion,
|
|
21
|
+
const std::string &libraryName,
|
|
22
|
+
const std::string &docsBaseUrl);
|
|
23
|
+
|
|
24
|
+
}; // namespace worklets
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// WorkletEventHandler was fully moved to Reanimated.
|
|
2
|
+
// This file is kept only for backwards compatibility with older versions of Reanimated.
|
|
3
|
+
|
|
4
|
+
#include <worklets/Tools/WorkletEventHandler.h>
|
|
5
|
+
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <string>
|
|
8
|
+
|
|
9
|
+
namespace worklets {
|
|
10
|
+
|
|
11
|
+
void WorkletEventHandler::process(
|
|
12
|
+
const std::shared_ptr<WorkletRuntime> &workletRuntime,
|
|
13
|
+
const double eventTimestamp,
|
|
14
|
+
const jsi::Value &eventValue) const {
|
|
15
|
+
workletRuntime->runSync(handlerFunction_, jsi::Value(eventTimestamp), eventValue);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
uint64_t WorkletEventHandler::getHandlerId() const {
|
|
19
|
+
return handlerId_;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const std::string &WorkletEventHandler::getEventName() const {
|
|
23
|
+
return eventName_;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
uint64_t WorkletEventHandler::getEmitterReactTag() const {
|
|
27
|
+
return emitterReactTag_;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
bool WorkletEventHandler::shouldIgnoreEmitterReactTag() const {
|
|
31
|
+
return emitterReactTag_ == -1;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
} // namespace worklets
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// WorkletEventHandler was fully moved to Reanimated.
|
|
2
|
+
// This file is kept only for backwards compatibility with older versions of Reanimated.
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#include <worklets/SharedItems/Serializable.h>
|
|
7
|
+
#include <worklets/WorkletRuntime/WorkletRuntime.h>
|
|
8
|
+
|
|
9
|
+
#include <jsi/jsi.h>
|
|
10
|
+
|
|
11
|
+
#include <memory>
|
|
12
|
+
#include <string>
|
|
13
|
+
|
|
14
|
+
using namespace facebook;
|
|
15
|
+
|
|
16
|
+
namespace worklets {
|
|
17
|
+
|
|
18
|
+
class WorkletEventHandler {
|
|
19
|
+
const uint64_t handlerId_;
|
|
20
|
+
const uint64_t emitterReactTag_;
|
|
21
|
+
const std::string eventName_;
|
|
22
|
+
const std::shared_ptr<SerializableWorklet> handlerFunction_;
|
|
23
|
+
|
|
24
|
+
public:
|
|
25
|
+
WorkletEventHandler(
|
|
26
|
+
const uint64_t handlerId,
|
|
27
|
+
const std::string &eventName,
|
|
28
|
+
const uint64_t emitterReactTag,
|
|
29
|
+
const std::shared_ptr<SerializableWorklet> &handlerFunction)
|
|
30
|
+
: handlerId_(handlerId),
|
|
31
|
+
emitterReactTag_(emitterReactTag),
|
|
32
|
+
eventName_(eventName),
|
|
33
|
+
handlerFunction_(handlerFunction) {}
|
|
34
|
+
void process(
|
|
35
|
+
const std::shared_ptr<WorkletRuntime> &workletRuntime,
|
|
36
|
+
double eventTimestamp,
|
|
37
|
+
const jsi::Value &eventValue) const;
|
|
38
|
+
uint64_t getHandlerId() const;
|
|
39
|
+
const std::string &getEventName() const;
|
|
40
|
+
uint64_t getEmitterReactTag() const;
|
|
41
|
+
bool shouldIgnoreEmitterReactTag() const;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
} // namespace worklets
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#include <worklets/Tools/WorkletsJSIUtils.h>
|
|
2
|
+
|
|
3
|
+
#include <react/debug/react_native_assert.h>
|
|
4
|
+
|
|
5
|
+
#include <memory>
|
|
6
|
+
#include <sstream>
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
using namespace facebook;
|
|
11
|
+
|
|
12
|
+
namespace worklets::jsi_utils {
|
|
13
|
+
|
|
14
|
+
jsi::Array convertStringToArray(jsi::Runtime &rt, const std::string &value, const unsigned int expectedSize) {
|
|
15
|
+
std::vector<float> transformMatrixList;
|
|
16
|
+
std::istringstream stringStream(value);
|
|
17
|
+
std::copy(
|
|
18
|
+
std::istream_iterator<float>(stringStream),
|
|
19
|
+
std::istream_iterator<float>(),
|
|
20
|
+
std::back_inserter(transformMatrixList));
|
|
21
|
+
react_native_assert(
|
|
22
|
+
transformMatrixList.size() == expectedSize && "Transform matrix list size is different than expected");
|
|
23
|
+
jsi::Array matrix(rt, expectedSize);
|
|
24
|
+
for (unsigned int i = 0; i < expectedSize; i++) {
|
|
25
|
+
matrix.setValueAtIndex(rt, i, transformMatrixList[i]);
|
|
26
|
+
}
|
|
27
|
+
return matrix;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
} // namespace worklets::jsi_utils
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <react/debug/react_native_assert.h>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <tuple>
|
|
7
|
+
#include <type_traits>
|
|
8
|
+
#include <utility>
|
|
9
|
+
|
|
10
|
+
using namespace facebook;
|
|
11
|
+
|
|
12
|
+
namespace worklets::jsi_utils {
|
|
13
|
+
|
|
14
|
+
// `get` functions take a pointer to `jsi::Value` and
|
|
15
|
+
// call an appropriate method to cast to the native type
|
|
16
|
+
template <typename T>
|
|
17
|
+
inline T get(jsi::Runtime &rt, const jsi::Value *value);
|
|
18
|
+
|
|
19
|
+
template <>
|
|
20
|
+
inline double get<double>(jsi::Runtime &, const jsi::Value *value) {
|
|
21
|
+
return value->asNumber();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
template <>
|
|
25
|
+
inline int get<int>(jsi::Runtime &, const jsi::Value *value) {
|
|
26
|
+
return value->asNumber();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
template <>
|
|
30
|
+
inline bool get<bool>(jsi::Runtime &, const jsi::Value *value) {
|
|
31
|
+
if (!value->isBool()) {
|
|
32
|
+
throw jsi::JSINativeException("[Worklets] Expected a boolean.");
|
|
33
|
+
}
|
|
34
|
+
return value->getBool();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
template <>
|
|
38
|
+
inline jsi::Object get<jsi::Object>(jsi::Runtime &rt, const jsi::Value *value) {
|
|
39
|
+
return value->asObject(rt);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
template <>
|
|
43
|
+
inline jsi::Value const &get<jsi::Value const &>(jsi::Runtime &, const jsi::Value *value) {
|
|
44
|
+
return *value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// `convertArgs` functions take a variadic template parameter of target (C++)
|
|
48
|
+
// argument types `Targs` and a `jsi::Value` array `args`, and converts `args`
|
|
49
|
+
// to a tuple of typed C++ arguments to be passed to the native implementation.
|
|
50
|
+
// This is accomplished by dispatching (at compile time) to the correct
|
|
51
|
+
// implementation based on the first type of `Targs`, using SFINAE to select the
|
|
52
|
+
// correct specialization, and concatenating with the result of recursion on the
|
|
53
|
+
// rest of `Targs`
|
|
54
|
+
|
|
55
|
+
// BEGIN implementations for `convertArgs` specializations.
|
|
56
|
+
// specialization for empty `Targs` - returns an empty tuple
|
|
57
|
+
template <typename... Args>
|
|
58
|
+
inline std::enable_if_t<(sizeof...(Args) == 0), std::tuple<>> convertArgs(jsi::Runtime &, const jsi::Value *) {
|
|
59
|
+
return std::make_tuple();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// calls `get<First>` on the first argument to retrieve the native type,
|
|
63
|
+
// then calls recursively on the rest of `args`
|
|
64
|
+
// and returns the concatenation of results
|
|
65
|
+
template <typename T, typename... Rest>
|
|
66
|
+
inline std::tuple<T, Rest...> convertArgs(jsi::Runtime &rt, const jsi::Value *args) {
|
|
67
|
+
auto arg = std::tuple<T>(get<T>(rt, args));
|
|
68
|
+
auto rest = convertArgs<Rest...>(rt, std::next(args));
|
|
69
|
+
return std::tuple_cat(std::move(arg), std::move(rest));
|
|
70
|
+
}
|
|
71
|
+
// END implementations for `convertArgs` specializations.
|
|
72
|
+
|
|
73
|
+
// returns a tuple with the result of casting `args` to appropriate
|
|
74
|
+
// native C++ types needed to call `function`
|
|
75
|
+
template <typename Ret, typename... Args>
|
|
76
|
+
std::tuple<Args...>
|
|
77
|
+
getArgsForFunction(std::function<Ret(Args...)>, jsi::Runtime &rt, const jsi::Value *args, const size_t count) {
|
|
78
|
+
react_native_assert(sizeof...(Args) == count && "Argument list has different length than expected");
|
|
79
|
+
return convertArgs<Args...>(rt, args);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// returns a tuple with the result of casting `args` to appropriate
|
|
83
|
+
// native C++ types needed to call `function`,
|
|
84
|
+
// passing `rt` as the first argument
|
|
85
|
+
template <typename Ret, typename... Args>
|
|
86
|
+
std::tuple<jsi::Runtime &, Args...> getArgsForFunction(
|
|
87
|
+
const std::function<Ret(jsi::Runtime &, Args...)> &,
|
|
88
|
+
jsi::Runtime &rt,
|
|
89
|
+
const jsi::Value *args,
|
|
90
|
+
const size_t count) {
|
|
91
|
+
react_native_assert(sizeof...(Args) == count && "Argument list has different length than expected");
|
|
92
|
+
return std::tuple_cat(std::tie(rt), convertArgs<Args...>(rt, args));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// calls `function` with `args`
|
|
96
|
+
template <typename Ret, typename... Args>
|
|
97
|
+
inline jsi::Value apply(std::function<Ret(Args...)> function, std::tuple<Args...> args) {
|
|
98
|
+
return std::apply(function, std::move(args));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// calls string-returning `function` with `args`,
|
|
102
|
+
// and returns the string
|
|
103
|
+
template <typename... Args>
|
|
104
|
+
inline jsi::Value apply(jsi::Runtime &rt, std::function<std::string(Args...)> function, std::tuple<Args...> args) {
|
|
105
|
+
return jsi::String::createFromUtf8(rt, std::apply(function, std::move(args)));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// calls void-returning `function` with `args`,
|
|
109
|
+
// and returns `undefined`
|
|
110
|
+
template <typename... Args>
|
|
111
|
+
inline jsi::Value apply(std::function<void(Args...)> function, std::tuple<Args...> args) {
|
|
112
|
+
std::apply(function, std::move(args));
|
|
113
|
+
return jsi::Value::undefined();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// returns a function with JSI calling convention
|
|
117
|
+
// from a native function `function`
|
|
118
|
+
template <typename Fun>
|
|
119
|
+
jsi::HostFunctionType createHostFunction(const Fun &function) {
|
|
120
|
+
return [function](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, const size_t count) {
|
|
121
|
+
auto argz = getArgsForFunction(function, rt, args, count);
|
|
122
|
+
return apply(function, std::move(argz));
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// returns a function with JSI calling convention
|
|
127
|
+
// from a native function `function` returning a string
|
|
128
|
+
template <typename... Args>
|
|
129
|
+
jsi::HostFunctionType createHostFunction(std::function<std::string(Args...)> function) {
|
|
130
|
+
return [function](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, const size_t count) {
|
|
131
|
+
auto argz = getArgsForFunction(function, rt, args, count);
|
|
132
|
+
return apply(rt, function, std::move(argz));
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// used to determine if `function<Ret(Args...)>`
|
|
137
|
+
// takes `Runtime &` as its first argument
|
|
138
|
+
template <typename... Args>
|
|
139
|
+
struct takes_runtime {
|
|
140
|
+
static constexpr size_t value = 0;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// specialization for `function<Ret(Runtime &, Rest...)`
|
|
144
|
+
template <typename... Rest>
|
|
145
|
+
struct takes_runtime<jsi::Runtime &, Rest...> {
|
|
146
|
+
static constexpr size_t value = 1;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// creates a JSI compatible function from `function`
|
|
150
|
+
// and installs it as a global function named `name`
|
|
151
|
+
// in the `rt` JS runtime
|
|
152
|
+
template <typename Ret, typename... Args>
|
|
153
|
+
void installJsiFunction(jsi::Runtime &rt, std::string_view name, const std::function<Ret(Args...)> &function) {
|
|
154
|
+
auto clb = createHostFunction(function);
|
|
155
|
+
auto argsCount = static_cast<unsigned int>(sizeof...(Args) - takes_runtime<Args...>::value);
|
|
156
|
+
jsi::Value jsiFunction =
|
|
157
|
+
jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, name.data()), argsCount, clb);
|
|
158
|
+
rt.global().setProperty(rt, name.data(), jsiFunction);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// this should take care of passing types convertible to `function`
|
|
162
|
+
template <typename Fun>
|
|
163
|
+
void installJsiFunction(jsi::Runtime &rt, std::string_view name, Fun function) {
|
|
164
|
+
installJsiFunction(rt, name, std::function(std::forward<Fun>(function)));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
jsi::Array convertStringToArray(jsi::Runtime &rt, const std::string &value, const unsigned int expectedSize);
|
|
168
|
+
|
|
169
|
+
template <size_t TIndex, size_t TLength>
|
|
170
|
+
requires(TIndex < TLength)
|
|
171
|
+
constexpr const jsi::Value &at(const jsi::Value (&args)[TLength]) noexcept {
|
|
172
|
+
return args[TIndex];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
template <size_t TLength, typename TFun>
|
|
176
|
+
requires(TLength > 0) &&
|
|
177
|
+
std::is_invocable_v<TFun &&, jsi::Runtime &, const jsi::Value &, const jsi::Value (&)[TLength]>
|
|
178
|
+
void addMethod(jsi::Runtime &rt, jsi::Object &obj, const char *name, TFun &&func) {
|
|
179
|
+
obj.setProperty(
|
|
180
|
+
rt,
|
|
181
|
+
name,
|
|
182
|
+
jsi::Function::createFromHostFunction(
|
|
183
|
+
rt,
|
|
184
|
+
jsi::PropNameID::forAscii(rt, name),
|
|
185
|
+
TLength,
|
|
186
|
+
[func = std::forward<TFun>(func)](
|
|
187
|
+
jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t) mutable -> jsi::Value {
|
|
188
|
+
using TReturn =
|
|
189
|
+
std::invoke_result_t<TFun &, jsi::Runtime &, const jsi::Value &, const jsi::Value(&)[TLength]>;
|
|
190
|
+
auto &typed = *reinterpret_cast<const jsi::Value(*)[TLength]>(args);
|
|
191
|
+
if constexpr (std::is_void_v<TReturn>) {
|
|
192
|
+
func(rt, thisVal, typed);
|
|
193
|
+
return jsi::Value::undefined();
|
|
194
|
+
} else {
|
|
195
|
+
return func(rt, thisVal, typed);
|
|
196
|
+
}
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
template <size_t TLength, typename TFun>
|
|
201
|
+
requires(TLength == 0) && std::is_invocable_v<TFun &&, jsi::Runtime &, const jsi::Value &>
|
|
202
|
+
void addMethod(jsi::Runtime &rt, jsi::Object &obj, const char *name, TFun &&func) {
|
|
203
|
+
obj.setProperty(
|
|
204
|
+
rt,
|
|
205
|
+
name,
|
|
206
|
+
jsi::Function::createFromHostFunction(
|
|
207
|
+
rt,
|
|
208
|
+
jsi::PropNameID::forAscii(rt, name),
|
|
209
|
+
0,
|
|
210
|
+
[func = std::forward<TFun>(func)](
|
|
211
|
+
jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *, size_t) mutable -> jsi::Value {
|
|
212
|
+
using TReturn = std::invoke_result_t<TFun &, jsi::Runtime &, const jsi::Value &>;
|
|
213
|
+
if constexpr (std::is_void_v<TReturn>) {
|
|
214
|
+
func(rt, thisVal);
|
|
215
|
+
return jsi::Value::undefined();
|
|
216
|
+
} else {
|
|
217
|
+
return func(rt, thisVal);
|
|
218
|
+
}
|
|
219
|
+
}));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
} // namespace worklets::jsi_utils
|