@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,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on OkHttpCallUtil.kt from React Native
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
@file:Suppress("DEPRECATION_ERROR") // Conflicting okhttp versions
|
|
6
|
+
|
|
7
|
+
package com.swmansion.worklets
|
|
8
|
+
|
|
9
|
+
import okhttp3.OkHttpClient
|
|
10
|
+
/*
|
|
11
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
12
|
+
*
|
|
13
|
+
* This source code is licensed under the MIT license found in the
|
|
14
|
+
* LICENSE file in the root directory of this source tree.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Helper class that provides the necessary methods for canceling queued and running OkHttp calls
|
|
19
|
+
*/
|
|
20
|
+
internal object WorkletsOkHttpCallUtil {
|
|
21
|
+
@JvmStatic
|
|
22
|
+
fun cancelTag(
|
|
23
|
+
client: OkHttpClient,
|
|
24
|
+
tag: Any,
|
|
25
|
+
) {
|
|
26
|
+
val dispatcher = client.dispatcher()
|
|
27
|
+
for (call in dispatcher.queuedCalls()) {
|
|
28
|
+
if (tag == call.request().tag()) {
|
|
29
|
+
call.cancel()
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
for (call in dispatcher.runningCalls()) {
|
|
34
|
+
if (tag == call.request().tag()) {
|
|
35
|
+
call.cancel()
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on ProgressRequestBody.kt from React Native
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
@file:Suppress("DEPRECATION_ERROR") // Conflicting okio versions
|
|
6
|
+
|
|
7
|
+
package com.swmansion.worklets
|
|
8
|
+
|
|
9
|
+
import okhttp3.MediaType
|
|
10
|
+
import okhttp3.RequestBody
|
|
11
|
+
import okio.BufferedSink
|
|
12
|
+
import okio.Okio
|
|
13
|
+
import okio.Sink
|
|
14
|
+
import java.io.FilterOutputStream
|
|
15
|
+
import java.io.IOException
|
|
16
|
+
|
|
17
|
+
internal class WorkletsProgressRequestBody(
|
|
18
|
+
private val requestBody: RequestBody,
|
|
19
|
+
private val progressListener: WorkletsProgressListener,
|
|
20
|
+
) : RequestBody() {
|
|
21
|
+
private var contentLength = 0L
|
|
22
|
+
|
|
23
|
+
companion object {
|
|
24
|
+
private const val MAX_BODY_PREVIEW_SIZE = 1024 * 1024 // 1MB
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
override fun contentType(): MediaType? = requestBody.contentType()
|
|
28
|
+
|
|
29
|
+
@Throws(IOException::class)
|
|
30
|
+
override fun contentLength(): Long {
|
|
31
|
+
if (contentLength == 0L) {
|
|
32
|
+
contentLength = requestBody.contentLength()
|
|
33
|
+
}
|
|
34
|
+
return contentLength
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Throws(IOException::class)
|
|
38
|
+
override fun writeTo(sink: BufferedSink) {
|
|
39
|
+
// In 99% of cases, this method is called strictly once.
|
|
40
|
+
// The only case when it is called more than once is internal okhttp upload re-try.
|
|
41
|
+
// We need to re-create CountingOutputStream in this case as progress should be re-evaluated.
|
|
42
|
+
val sinkWrapper = Okio.buffer(outputStreamSink(sink))
|
|
43
|
+
|
|
44
|
+
// contentLength changes for input streams, since we're using inputStream.available(),
|
|
45
|
+
// so get the length before writing to the sink
|
|
46
|
+
contentLength()
|
|
47
|
+
|
|
48
|
+
requestBody.writeTo(sinkWrapper)
|
|
49
|
+
sinkWrapper.flush()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private fun outputStreamSink(sink: BufferedSink): Sink =
|
|
53
|
+
Okio.sink(
|
|
54
|
+
object : FilterOutputStream(sink.outputStream()) {
|
|
55
|
+
private var count: Long = 0
|
|
56
|
+
|
|
57
|
+
@Throws(IOException::class)
|
|
58
|
+
override fun write(
|
|
59
|
+
data: ByteArray,
|
|
60
|
+
offset: Int,
|
|
61
|
+
byteCount: Int,
|
|
62
|
+
) {
|
|
63
|
+
super.write(data, offset, byteCount)
|
|
64
|
+
count += byteCount.toLong()
|
|
65
|
+
sendProgressUpdate()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@Throws(IOException::class)
|
|
69
|
+
override fun write(data: Int) {
|
|
70
|
+
super.write(data)
|
|
71
|
+
count++
|
|
72
|
+
sendProgressUpdate()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@Throws(IOException::class)
|
|
76
|
+
fun sendProgressUpdate() {
|
|
77
|
+
val bytesWritten = count
|
|
78
|
+
val contentLength = contentLength()
|
|
79
|
+
progressListener.onProgress(bytesWritten, contentLength, bytesWritten == contentLength)
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
fun getBodyPreview(): String =
|
|
85
|
+
try {
|
|
86
|
+
val buffer = okio.Buffer()
|
|
87
|
+
requestBody.writeTo(buffer)
|
|
88
|
+
val size = buffer.size()
|
|
89
|
+
if (size <= MAX_BODY_PREVIEW_SIZE) {
|
|
90
|
+
buffer.readUtf8()
|
|
91
|
+
} else {
|
|
92
|
+
buffer.readUtf8(MAX_BODY_PREVIEW_SIZE.toLong()) +
|
|
93
|
+
"\n... [truncated, showing $MAX_BODY_PREVIEW_SIZE of $size bytes]"
|
|
94
|
+
}
|
|
95
|
+
} catch (e: Exception) {
|
|
96
|
+
""
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on ProgressResponseBody.kt from React Native
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
@file:Suppress("DEPRECATION_ERROR") // Conflicting okhttp versions
|
|
6
|
+
|
|
7
|
+
package com.swmansion.worklets
|
|
8
|
+
|
|
9
|
+
import okhttp3.MediaType
|
|
10
|
+
import okhttp3.ResponseBody
|
|
11
|
+
import okio.Buffer
|
|
12
|
+
import okio.BufferedSource
|
|
13
|
+
import okio.ForwardingSource
|
|
14
|
+
import okio.Okio
|
|
15
|
+
import okio.Source
|
|
16
|
+
import java.io.IOException
|
|
17
|
+
|
|
18
|
+
public class WorkletsProgressResponseBody
|
|
19
|
+
public constructor(
|
|
20
|
+
private val responseBody: ResponseBody,
|
|
21
|
+
private val progressListener: WorkletsProgressListener,
|
|
22
|
+
) : ResponseBody() {
|
|
23
|
+
private lateinit var bufferedSource: BufferedSource
|
|
24
|
+
private var totalBytesRead = 0L
|
|
25
|
+
|
|
26
|
+
public override fun contentType(): MediaType? = responseBody.contentType()
|
|
27
|
+
|
|
28
|
+
override fun contentLength(): Long = responseBody.contentLength()
|
|
29
|
+
|
|
30
|
+
public fun totalBytesRead(): Long = totalBytesRead
|
|
31
|
+
|
|
32
|
+
public override fun source(): BufferedSource {
|
|
33
|
+
if (!::bufferedSource.isInitialized) {
|
|
34
|
+
bufferedSource = Okio.buffer(source(responseBody.source()))
|
|
35
|
+
}
|
|
36
|
+
return bufferedSource
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private fun source(source: Source): Source {
|
|
40
|
+
return object : ForwardingSource(source) {
|
|
41
|
+
@Throws(IOException::class)
|
|
42
|
+
override fun read(
|
|
43
|
+
sink: Buffer,
|
|
44
|
+
byteCount: Long,
|
|
45
|
+
): Long {
|
|
46
|
+
// read() returns the number of bytes read, or -1 if this source is exhausted.
|
|
47
|
+
return super.read(sink, byteCount).also { bytesRead ->
|
|
48
|
+
if (bytesRead != -1L) {
|
|
49
|
+
totalBytesRead += bytesRead
|
|
50
|
+
}
|
|
51
|
+
progressListener.onProgress(
|
|
52
|
+
totalBytesRead,
|
|
53
|
+
responseBody.contentLength(),
|
|
54
|
+
bytesRead == -1L,
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on ProgressiveStringDecoder.kt from React Native
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
package com.swmansion.worklets
|
|
6
|
+
|
|
7
|
+
import com.facebook.common.logging.FLog
|
|
8
|
+
import com.facebook.react.common.ReactConstants
|
|
9
|
+
import java.nio.ByteBuffer
|
|
10
|
+
import java.nio.CharBuffer
|
|
11
|
+
import java.nio.charset.Charset
|
|
12
|
+
import java.nio.charset.CharsetDecoder
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Class to decode encoded strings from byte array chunks. As in different encodings single
|
|
16
|
+
* character could take up to 4 characters byte array passed to decode could have parts of the
|
|
17
|
+
* characters which can't be correctly decoded.
|
|
18
|
+
*
|
|
19
|
+
* This class is designed in assumption that original byte stream is correctly formatted string in
|
|
20
|
+
* given encoding. Otherwise some parts of the data won't be decoded.
|
|
21
|
+
*/
|
|
22
|
+
internal class WorkletsProgressiveStringDecoder(
|
|
23
|
+
charset: Charset,
|
|
24
|
+
) {
|
|
25
|
+
private val decoder: CharsetDecoder = charset.newDecoder()
|
|
26
|
+
private var remainder: ByteArray? = null
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Parses data to String If there is a partial multi-byte symbol on the edge of the String it get
|
|
30
|
+
* saved to the reminder and added to the string on the decodeNext call.
|
|
31
|
+
*
|
|
32
|
+
* @param data The byte array containing the encoded string data.
|
|
33
|
+
* @param initialLength The number of valid bytes in the provided data array that should be
|
|
34
|
+
* decoded.
|
|
35
|
+
* @return The decoded string. If decoding fails, an empty string is returned.
|
|
36
|
+
*/
|
|
37
|
+
fun decodeNext(
|
|
38
|
+
data: ByteArray,
|
|
39
|
+
initialLength: Int,
|
|
40
|
+
): String {
|
|
41
|
+
var length = initialLength
|
|
42
|
+
var decodeData: ByteArray = data
|
|
43
|
+
|
|
44
|
+
remainder?.let { r ->
|
|
45
|
+
decodeData = ByteArray(r.size + length)
|
|
46
|
+
System.arraycopy(r, 0, decodeData, 0, r.size)
|
|
47
|
+
System.arraycopy(data, 0, decodeData, r.size, length)
|
|
48
|
+
length += r.size
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
var decodeBuffer = ByteBuffer.wrap(decodeData, 0, length)
|
|
52
|
+
var result: CharBuffer? = null
|
|
53
|
+
var decoded = false
|
|
54
|
+
var remainderLength = 0
|
|
55
|
+
|
|
56
|
+
while (!decoded && (remainderLength < 4)) {
|
|
57
|
+
try {
|
|
58
|
+
result = decoder.decode(decodeBuffer)
|
|
59
|
+
decoded = true
|
|
60
|
+
} catch (e: CharacterCodingException) {
|
|
61
|
+
remainderLength++
|
|
62
|
+
decodeBuffer = ByteBuffer.wrap(decodeData, 0, length - remainderLength)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
val hasRemainder = decoded && remainderLength > 0
|
|
67
|
+
remainder =
|
|
68
|
+
if (hasRemainder) {
|
|
69
|
+
ByteArray(remainderLength).apply {
|
|
70
|
+
System.arraycopy(decodeData, length - remainderLength, this, 0, remainderLength)
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
null
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!decoded) {
|
|
77
|
+
FLog.w(ReactConstants.TAG, "failed to decode string from byte array")
|
|
78
|
+
return EMPTY_STRING
|
|
79
|
+
} else {
|
|
80
|
+
return result?.let { String(it.array(), 0, it.length) } ?: EMPTY_STRING
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
companion object {
|
|
85
|
+
private const val EMPTY_STRING = ""
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on RequestBodyUtil.kt from React Native
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
@file:Suppress("DEPRECATION_ERROR") // Conflicting okio versions
|
|
6
|
+
|
|
7
|
+
package com.swmansion.worklets
|
|
8
|
+
|
|
9
|
+
import android.content.Context
|
|
10
|
+
import android.net.Uri
|
|
11
|
+
import android.util.Base64
|
|
12
|
+
import com.facebook.common.logging.FLog
|
|
13
|
+
import com.facebook.react.common.ReactConstants
|
|
14
|
+
import okhttp3.MediaType
|
|
15
|
+
import okhttp3.RequestBody
|
|
16
|
+
import okio.BufferedSink
|
|
17
|
+
import okio.ByteString
|
|
18
|
+
import okio.Okio
|
|
19
|
+
import okio.Source
|
|
20
|
+
import java.io.ByteArrayInputStream
|
|
21
|
+
import java.io.ByteArrayOutputStream
|
|
22
|
+
import java.io.File
|
|
23
|
+
import java.io.FileInputStream
|
|
24
|
+
import java.io.FileOutputStream
|
|
25
|
+
import java.io.IOException
|
|
26
|
+
import java.io.InputStream
|
|
27
|
+
import java.io.OutputStream
|
|
28
|
+
import java.net.URL
|
|
29
|
+
import java.nio.channels.Channels
|
|
30
|
+
import java.util.zip.GZIPOutputStream
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Helper class that provides the necessary methods for creating the [RequestBody] from a file
|
|
34
|
+
* specification, such as a contentUri.
|
|
35
|
+
*/
|
|
36
|
+
internal object WorkletsRequestBodyUtil {
|
|
37
|
+
private const val CONTENT_ENCODING_GZIP = "gzip"
|
|
38
|
+
private const val NAME = "RequestBodyUtil"
|
|
39
|
+
private const val TEMP_FILE_SUFFIX = "temp"
|
|
40
|
+
|
|
41
|
+
/** Returns whether encode type indicates the body needs to be gzip-ed. */
|
|
42
|
+
@JvmStatic
|
|
43
|
+
fun isGzipEncoding(encodingType: String?): Boolean = CONTENT_ENCODING_GZIP.equals(encodingType, ignoreCase = true)
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Returns the input stream for a file given by its contentUri. Returns null if the file has not
|
|
47
|
+
* been found or if an error as occurred.
|
|
48
|
+
*/
|
|
49
|
+
@JvmStatic
|
|
50
|
+
fun getFileInputStream(
|
|
51
|
+
context: Context,
|
|
52
|
+
fileContentUriStr: String,
|
|
53
|
+
): InputStream? {
|
|
54
|
+
try {
|
|
55
|
+
val fileContentUri = Uri.parse(fileContentUriStr)
|
|
56
|
+
|
|
57
|
+
if (fileContentUri.scheme?.startsWith("http") == true) {
|
|
58
|
+
return getDownloadFileInputStream(context, fileContentUri)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (fileContentUriStr.startsWith("data:")) {
|
|
62
|
+
val decodedDataUrString =
|
|
63
|
+
Base64.decode(
|
|
64
|
+
fileContentUriStr
|
|
65
|
+
.split(",".toRegex())
|
|
66
|
+
.dropLastWhile { it.isEmpty() }
|
|
67
|
+
.toTypedArray()[1],
|
|
68
|
+
Base64.DEFAULT,
|
|
69
|
+
)
|
|
70
|
+
return ByteArrayInputStream(decodedDataUrString)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return context.contentResolver.openInputStream(fileContentUri)
|
|
74
|
+
} catch (e: Exception) {
|
|
75
|
+
FLog.e(ReactConstants.TAG, "Could not retrieve file for contentUri $fileContentUriStr", e)
|
|
76
|
+
return null
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Download and cache a file locally. This should be used when document picker returns a URI that
|
|
82
|
+
* points to a file on the network. Returns input stream for the downloaded file.
|
|
83
|
+
*/
|
|
84
|
+
@Throws(IOException::class)
|
|
85
|
+
private fun getDownloadFileInputStream(
|
|
86
|
+
context: Context,
|
|
87
|
+
uri: Uri,
|
|
88
|
+
): InputStream {
|
|
89
|
+
val outputDir = context.applicationContext.cacheDir
|
|
90
|
+
val file = File.createTempFile(NAME, TEMP_FILE_SUFFIX, outputDir)
|
|
91
|
+
file.deleteOnExit()
|
|
92
|
+
|
|
93
|
+
val url = URL(uri.toString())
|
|
94
|
+
FileOutputStream(file).use { stream ->
|
|
95
|
+
url.openStream().use { `is` ->
|
|
96
|
+
Channels.newChannel(`is`).use { channel ->
|
|
97
|
+
stream.channel.transferFrom(channel, 0, Long.MAX_VALUE)
|
|
98
|
+
return FileInputStream(file)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Creates a [RequestBody] from a mediaType and gzip-ed body string. */
|
|
105
|
+
@JvmStatic
|
|
106
|
+
fun createGzip(
|
|
107
|
+
mediaType: MediaType?,
|
|
108
|
+
body: String,
|
|
109
|
+
): RequestBody? {
|
|
110
|
+
val gzipByteArrayOutputStream = ByteArrayOutputStream()
|
|
111
|
+
try {
|
|
112
|
+
val gzipOutputStream: OutputStream = GZIPOutputStream(gzipByteArrayOutputStream)
|
|
113
|
+
gzipOutputStream.write(body.toByteArray())
|
|
114
|
+
gzipOutputStream.close()
|
|
115
|
+
} catch (e: IOException) {
|
|
116
|
+
return null
|
|
117
|
+
}
|
|
118
|
+
@Suppress("DEPRECATION")
|
|
119
|
+
return RequestBody.create(mediaType, gzipByteArrayOutputStream.toByteArray())
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Reference:
|
|
124
|
+
* https://github.com/square/okhttp/blob/8c8c3dbcfa91e28de2e13975ec414e07f153fde4/okhttp/src/commonMain/kotlin/okhttp3/internal/-UtilCommon.kt#L281-L288
|
|
125
|
+
* Checked exceptions will be ignored
|
|
126
|
+
*/
|
|
127
|
+
private fun closeQuietly(source: Source) {
|
|
128
|
+
try {
|
|
129
|
+
source.close()
|
|
130
|
+
} catch (e: RuntimeException) {
|
|
131
|
+
throw e
|
|
132
|
+
} catch (e: Exception) {
|
|
133
|
+
// no-op
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Creates a [RequestBody] from a mediaType and inputStream given. */
|
|
138
|
+
@JvmStatic
|
|
139
|
+
fun create(
|
|
140
|
+
mediaType: MediaType?,
|
|
141
|
+
inputStream: InputStream,
|
|
142
|
+
): RequestBody =
|
|
143
|
+
object : RequestBody() {
|
|
144
|
+
override fun contentType(): MediaType? = mediaType
|
|
145
|
+
|
|
146
|
+
override fun contentLength(): Long =
|
|
147
|
+
try {
|
|
148
|
+
inputStream.available().toLong()
|
|
149
|
+
} catch (e: IOException) {
|
|
150
|
+
0
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@Throws(IOException::class)
|
|
154
|
+
override fun writeTo(sink: BufferedSink) {
|
|
155
|
+
var source: Source? = null
|
|
156
|
+
try {
|
|
157
|
+
source = Okio.source(inputStream)
|
|
158
|
+
sink.writeAll(source)
|
|
159
|
+
} finally {
|
|
160
|
+
source?.let { closeQuietly(it) }
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Creates a [ProgressRequestBody] that can be used for showing uploading progress. */
|
|
166
|
+
@JvmStatic
|
|
167
|
+
fun createProgressRequest(
|
|
168
|
+
requestBody: RequestBody,
|
|
169
|
+
listener: WorkletsProgressListener,
|
|
170
|
+
): WorkletsProgressRequestBody = WorkletsProgressRequestBody(requestBody, listener)
|
|
171
|
+
|
|
172
|
+
/** Creates an empty [RequestBody] if required by the http method spec, otherwise use null. */
|
|
173
|
+
@JvmStatic
|
|
174
|
+
fun getEmptyBody(method: String): RequestBody? =
|
|
175
|
+
if (method == "POST" || method == "PUT" || method == "PATCH") {
|
|
176
|
+
@Suppress("DEPRECATION")
|
|
177
|
+
RequestBody.create(null, ByteString.EMPTY)
|
|
178
|
+
} else {
|
|
179
|
+
null
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
package com.swmansion.worklets
|
|
2
|
+
|
|
3
|
+
import com.facebook.jni.HybridData
|
|
4
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
5
|
+
import com.facebook.react.bridge.LifecycleEventListener
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.bridge.ReactMethod
|
|
8
|
+
import com.facebook.react.common.annotations.FrameworkAPI
|
|
9
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
10
|
+
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl
|
|
11
|
+
import com.facebook.soloader.SoLoader
|
|
12
|
+
import com.swmansion.worklets.runloop.AnimationFrameCallback
|
|
13
|
+
import com.swmansion.worklets.runloop.AnimationFrameQueue
|
|
14
|
+
import java.util.concurrent.atomic.AtomicBoolean
|
|
15
|
+
|
|
16
|
+
@Suppress("KotlinJniMissingFunction")
|
|
17
|
+
@ReactModule(name = WorkletsModule.NAME)
|
|
18
|
+
class WorkletsModule(
|
|
19
|
+
reactContext: ReactApplicationContext,
|
|
20
|
+
) : NativeWorkletsModuleSpec(reactContext),
|
|
21
|
+
LifecycleEventListener {
|
|
22
|
+
companion object {
|
|
23
|
+
const val NAME = "WorkletsModule"
|
|
24
|
+
|
|
25
|
+
init {
|
|
26
|
+
SoLoader.loadLibrary("worklets")
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@field:DoNotStrip
|
|
31
|
+
@Suppress("unused")
|
|
32
|
+
private var mHybridData: HybridData? = null
|
|
33
|
+
|
|
34
|
+
@Suppress("unused")
|
|
35
|
+
protected fun getHybridData(): HybridData? = mHybridData
|
|
36
|
+
|
|
37
|
+
init {
|
|
38
|
+
reactContext.assertOnJSQueueThread()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private val mAndroidUIScheduler = AndroidUIScheduler(reactContext)
|
|
42
|
+
private val mAnimationFrameQueue = AnimationFrameQueue(reactContext)
|
|
43
|
+
private var mSlowAnimationsEnabled = false
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Invalidating concurrently could be fatal. It shouldn't happen in a normal flow, but it doesn't
|
|
47
|
+
* cost us much to add synchronization for extra safety.
|
|
48
|
+
*/
|
|
49
|
+
private val mInvalidated = AtomicBoolean(false)
|
|
50
|
+
|
|
51
|
+
@OptIn(FrameworkAPI::class)
|
|
52
|
+
private external fun initHybrid(
|
|
53
|
+
bundleModeEnabled: Boolean,
|
|
54
|
+
jsContext: Long,
|
|
55
|
+
jsCallInvokerHolder: CallInvokerHolderImpl,
|
|
56
|
+
androidUIScheduler: AndroidUIScheduler,
|
|
57
|
+
scriptBufferWrapper: ScriptBufferWrapper?,
|
|
58
|
+
): HybridData
|
|
59
|
+
|
|
60
|
+
@OptIn(FrameworkAPI::class)
|
|
61
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
62
|
+
override fun installTurboModule(bundleModeEnabled: Boolean): Boolean {
|
|
63
|
+
val context = reactApplicationContext
|
|
64
|
+
|
|
65
|
+
context.assertOnJSQueueThread()
|
|
66
|
+
|
|
67
|
+
val jsContext = checkNotNull(context.javaScriptContextHolder).get()
|
|
68
|
+
val jsCallInvokerHolder = context.jsCallInvokerHolder as CallInvokerHolderImpl
|
|
69
|
+
|
|
70
|
+
val sourceURL = context.sourceURL
|
|
71
|
+
|
|
72
|
+
val scriptBufferWrapper: ScriptBufferWrapper? =
|
|
73
|
+
if (bundleModeEnabled) {
|
|
74
|
+
ScriptBufferWrapper(sourceURL!!, context.assets)
|
|
75
|
+
} else {
|
|
76
|
+
null
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
mHybridData =
|
|
80
|
+
initHybrid(
|
|
81
|
+
bundleModeEnabled,
|
|
82
|
+
jsContext,
|
|
83
|
+
jsCallInvokerHolder,
|
|
84
|
+
mAndroidUIScheduler,
|
|
85
|
+
scriptBufferWrapper,
|
|
86
|
+
)
|
|
87
|
+
return true
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@OptIn(FrameworkAPI::class)
|
|
91
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
92
|
+
override fun start(): Boolean {
|
|
93
|
+
reactApplicationContext.assertOnJSQueueThread()
|
|
94
|
+
startCpp()
|
|
95
|
+
return true
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@DoNotStrip
|
|
99
|
+
fun requestAnimationFrame(animationFrameCallback: AnimationFrameCallback) {
|
|
100
|
+
mAnimationFrameQueue.requestAnimationFrame(animationFrameCallback)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** @noinspection unused */
|
|
104
|
+
@DoNotStrip
|
|
105
|
+
fun isOnJSQueueThread(): Boolean = reactApplicationContext.isOnJSQueueThread
|
|
106
|
+
|
|
107
|
+
fun toggleSlowAnimations() {
|
|
108
|
+
val animationsDragFactor = 10
|
|
109
|
+
mSlowAnimationsEnabled = !mSlowAnimationsEnabled
|
|
110
|
+
mAnimationFrameQueue.enableSlowAnimations(mSlowAnimationsEnabled, animationsDragFactor)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
@OptIn(FrameworkAPI::class)
|
|
114
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
115
|
+
override fun toggleSlowAnimationsOnUIRuntime(): Boolean {
|
|
116
|
+
toggleSlowAnimations()
|
|
117
|
+
return mSlowAnimationsEnabled
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
override fun invalidate() {
|
|
121
|
+
if (mInvalidated.getAndSet(true)) {
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
if (mHybridData != null && mHybridData!!.isValid) {
|
|
125
|
+
invalidateCpp()
|
|
126
|
+
}
|
|
127
|
+
mAndroidUIScheduler.deactivate()
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private external fun invalidateCpp()
|
|
131
|
+
|
|
132
|
+
private external fun startCpp()
|
|
133
|
+
|
|
134
|
+
override fun onHostResume() {
|
|
135
|
+
mAnimationFrameQueue.resume()
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
override fun onHostPause() {
|
|
139
|
+
mAnimationFrameQueue.pause()
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
override fun onHostDestroy() {}
|
|
143
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#if __cplusplus
|
|
2
|
+
|
|
3
|
+
#import <worklets/apple/WorkletsDisplayLink.h>
|
|
4
|
+
#import <functional>
|
|
5
|
+
|
|
6
|
+
@interface AnimationFrameQueue : NSObject
|
|
7
|
+
|
|
8
|
+
- (void)requestAnimationFrame:(std::function<void(double)>)callback;
|
|
9
|
+
- (void)executeQueue:(WorkletsDisplayLink *)displayLink;
|
|
10
|
+
|
|
11
|
+
- (void)invalidate;
|
|
12
|
+
|
|
13
|
+
@end
|
|
14
|
+
|
|
15
|
+
#endif // __cplusplus
|