@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.
Files changed (457) hide show
  1. package/.worklets/dummy.md +1 -0
  2. package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.cpp +64 -0
  3. package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.h +38 -0
  4. package/Common/cpp/worklets/Compat/Holders.h +25 -0
  5. package/Common/cpp/worklets/Compat/StableApi.cpp +145 -0
  6. package/Common/cpp/worklets/Compat/StableApi.h +128 -0
  7. package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +729 -0
  8. package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +126 -0
  9. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +81 -0
  10. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +76 -0
  11. package/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +95 -0
  12. package/Common/cpp/worklets/Registries/EventHandlerRegistry.h +44 -0
  13. package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +10 -0
  14. package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +43 -0
  15. package/Common/cpp/worklets/RunLoop/AsyncQueue.h +14 -0
  16. package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +69 -0
  17. package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +48 -0
  18. package/Common/cpp/worklets/RunLoop/EventLoop.cpp +103 -0
  19. package/Common/cpp/worklets/RunLoop/EventLoop.h +52 -0
  20. package/Common/cpp/worklets/SharedItems/MemoryManager.cpp +60 -0
  21. package/Common/cpp/worklets/SharedItems/MemoryManager.h +29 -0
  22. package/Common/cpp/worklets/SharedItems/Serializable.cpp +373 -0
  23. package/Common/cpp/worklets/SharedItems/Serializable.h +413 -0
  24. package/Common/cpp/worklets/SharedItems/SerializableFactory.cpp +172 -0
  25. package/Common/cpp/worklets/SharedItems/SerializableFactory.h +85 -0
  26. package/Common/cpp/worklets/SharedItems/SerializableRemoteFunction.cpp +71 -0
  27. package/Common/cpp/worklets/SharedItems/SerializableRemoteFunction.h +75 -0
  28. package/Common/cpp/worklets/SharedItems/Shareable.cpp +84 -0
  29. package/Common/cpp/worklets/SharedItems/Shareable.h +43 -0
  30. package/Common/cpp/worklets/SharedItems/Synchronizable.cpp +59 -0
  31. package/Common/cpp/worklets/SharedItems/Synchronizable.h +57 -0
  32. package/Common/cpp/worklets/SharedItems/SynchronizableAccess.cpp +78 -0
  33. package/Common/cpp/worklets/SharedItems/SynchronizableAccess.h +45 -0
  34. package/Common/cpp/worklets/SharedItems/UnpackerLoader.h +78 -0
  35. package/Common/cpp/worklets/Tools/FeatureFlags.cpp +18 -0
  36. package/Common/cpp/worklets/Tools/FeatureFlags.h +44 -0
  37. package/Common/cpp/worklets/Tools/JSISerializer.cpp +312 -0
  38. package/Common/cpp/worklets/Tools/JSISerializer.h +42 -0
  39. package/Common/cpp/worklets/Tools/JSLogger.cpp +92 -0
  40. package/Common/cpp/worklets/Tools/JSLogger.h +48 -0
  41. package/Common/cpp/worklets/Tools/JSScheduler.cpp +21 -0
  42. package/Common/cpp/worklets/Tools/JSScheduler.h +35 -0
  43. package/Common/cpp/worklets/Tools/PlatformLogger.h +16 -0
  44. package/Common/cpp/worklets/Tools/RNRuntimeStatus.h +27 -0
  45. package/Common/cpp/worklets/Tools/ScriptBuffer.h +56 -0
  46. package/Common/cpp/worklets/Tools/SingleInstanceChecker.h +75 -0
  47. package/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -0
  48. package/Common/cpp/worklets/Tools/UIScheduler.cpp +19 -0
  49. package/Common/cpp/worklets/Tools/UIScheduler.h +22 -0
  50. package/Common/cpp/worklets/Tools/VersionUtils.cpp +61 -0
  51. package/Common/cpp/worklets/Tools/VersionUtils.h +24 -0
  52. package/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +34 -0
  53. package/Common/cpp/worklets/Tools/WorkletEventHandler.h +44 -0
  54. package/Common/cpp/worklets/Tools/WorkletsJSIUtils.cpp +30 -0
  55. package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +222 -0
  56. package/Common/cpp/worklets/Tools/WorkletsSystraceSection.h +116 -0
  57. package/Common/cpp/worklets/Tools/WorkletsVersion.cpp +46 -0
  58. package/Common/cpp/worklets/Tools/WorkletsVersion.h +18 -0
  59. package/Common/cpp/worklets/WorkletRuntime/BundleModeConfig.h +17 -0
  60. package/Common/cpp/worklets/WorkletRuntime/HermesProfiling.cpp +45 -0
  61. package/Common/cpp/worklets/WorkletRuntime/HermesProfiling.h +12 -0
  62. package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +68 -0
  63. package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +24 -0
  64. package/Common/cpp/worklets/WorkletRuntime/RuntimeBindings.h +59 -0
  65. package/Common/cpp/worklets/WorkletRuntime/RuntimeData.h +38 -0
  66. package/Common/cpp/worklets/WorkletRuntime/RuntimeHolder.h +19 -0
  67. package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +122 -0
  68. package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +75 -0
  69. package/Common/cpp/worklets/WorkletRuntime/ScriptLoader.h +116 -0
  70. package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.cpp +14 -0
  71. package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.h +15 -0
  72. package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.cpp +58 -0
  73. package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.h +100 -0
  74. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +327 -0
  75. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +256 -0
  76. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -0
  77. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +320 -0
  78. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +36 -0
  79. package/LICENSE +20 -0
  80. package/README.md +43 -0
  81. package/RNWorklets.podspec +94 -0
  82. package/android/CMakeLists.txt +108 -0
  83. package/android/build.gradle.kts +369 -0
  84. package/android/fix-prefab.gradle.kts +56 -0
  85. package/android/generate-stub-pch.gradle.kts +84 -0
  86. package/android/gradle.properties +25 -0
  87. package/android/proguard-rules.pro +3 -0
  88. package/android/settings.gradle.kts +21 -0
  89. package/android/src/main/AndroidManifest.xml +2 -0
  90. package/android/src/main/cpp/WorkletsPCH.h +26 -0
  91. package/android/src/main/cpp/worklets/android/AndroidUIScheduler.cpp +66 -0
  92. package/android/src/main/cpp/worklets/android/AndroidUIScheduler.h +38 -0
  93. package/android/src/main/cpp/worklets/android/AnimationFrameCallback.h +30 -0
  94. package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.cpp +66 -0
  95. package/android/src/main/cpp/worklets/android/JScriptBufferWrapper.h +48 -0
  96. package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.cpp +51 -0
  97. package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.h +43 -0
  98. package/android/src/main/cpp/worklets/android/PlatformLogger.cpp +31 -0
  99. package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +203 -0
  100. package/android/src/main/cpp/worklets/android/WorkletsModule.h +75 -0
  101. package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +19 -0
  102. package/android/src/main/java/com/swmansion/worklets/AndroidUIScheduler.kt +56 -0
  103. package/android/src/main/java/com/swmansion/worklets/ScriptBufferWrapper.kt +103 -0
  104. package/android/src/main/java/com/swmansion/worklets/WorkletsPackage.kt +42 -0
  105. package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameCallback.kt +14 -0
  106. package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameQueue.kt +112 -0
  107. package/android/src/networking/com/swmansion/worklets/WorkletRuntimeWrapper.kt +27 -0
  108. package/android/src/networking/com/swmansion/worklets/WorkletsHeaderUtil.kt +30 -0
  109. package/android/src/networking/com/swmansion/worklets/WorkletsModule.kt +187 -0
  110. package/android/src/networking/com/swmansion/worklets/WorkletsNetworkEventUtil.kt +272 -0
  111. package/android/src/networking/com/swmansion/worklets/WorkletsNetworking.kt +1124 -0
  112. package/android/src/networking/com/swmansion/worklets/WorkletsOkHttpCallUtil.kt +40 -0
  113. package/android/src/networking/com/swmansion/worklets/WorkletsProgressListener.kt +13 -0
  114. package/android/src/networking/com/swmansion/worklets/WorkletsProgressRequestBody.kt +98 -0
  115. package/android/src/networking/com/swmansion/worklets/WorkletsProgressResponseBody.kt +60 -0
  116. package/android/src/networking/com/swmansion/worklets/WorkletsProgressiveStringDecoder.kt +87 -0
  117. package/android/src/networking/com/swmansion/worklets/WorkletsRequestBodyUtil.kt +181 -0
  118. package/android/src/no-networking/com/swmansion/worklets/WorkletsModule.kt +143 -0
  119. package/apple/worklets/apple/AnimationFrameQueue.h +15 -0
  120. package/apple/worklets/apple/AnimationFrameQueue.mm +145 -0
  121. package/apple/worklets/apple/AssertJavaScriptQueue.h +14 -0
  122. package/apple/worklets/apple/AssertTurboModuleManagerQueue.h +12 -0
  123. package/apple/worklets/apple/IOSUIScheduler.h +14 -0
  124. package/apple/worklets/apple/IOSUIScheduler.mm +29 -0
  125. package/apple/worklets/apple/Networking/WorkletsNetworking.h +25 -0
  126. package/apple/worklets/apple/Networking/WorkletsNetworking.mm +707 -0
  127. package/apple/worklets/apple/PlatformLogger.mm +31 -0
  128. package/apple/worklets/apple/SlowAnimations.h +8 -0
  129. package/apple/worklets/apple/SlowAnimations.mm +45 -0
  130. package/apple/worklets/apple/WorkletsDisplayLink.h +21 -0
  131. package/apple/worklets/apple/WorkletsModule.h +28 -0
  132. package/apple/worklets/apple/WorkletsModule.mm +177 -0
  133. package/bundleMode/index.d.ts +6 -0
  134. package/bundleMode/index.js +182 -0
  135. package/bundleMode/shims/reactNativeShim.js +21 -0
  136. package/bundleMode/shims/turboModuleRegistryShim.js +47 -0
  137. package/changes.json +58 -0
  138. package/compatibility.json +29 -0
  139. package/jest/pluginTestUtils.ts +16 -0
  140. package/jest/resolver.js +18 -0
  141. package/lib/module/WorkletsModule/NativeWorklets.js +4 -0
  142. package/lib/module/WorkletsModule/NativeWorklets.js.map +1 -0
  143. package/lib/module/WorkletsModule/NativeWorklets.native.js +199 -0
  144. package/lib/module/WorkletsModule/NativeWorklets.native.js.map +1 -0
  145. package/lib/module/WorkletsModule/workletsModuleProxy.js +4 -0
  146. package/lib/module/WorkletsModule/workletsModuleProxy.js.map +1 -0
  147. package/lib/module/bundleMode/metroOverrides.native.js +26 -0
  148. package/lib/module/bundleMode/metroOverrides.native.js.map +1 -0
  149. package/lib/module/bundleMode/network.native.js +44 -0
  150. package/lib/module/bundleMode/network.native.js.map +1 -0
  151. package/lib/module/debug/bundleMode.js +6 -0
  152. package/lib/module/debug/bundleMode.js.map +1 -0
  153. package/lib/module/debug/bundleMode.native.js +11 -0
  154. package/lib/module/debug/bundleMode.native.js.map +1 -0
  155. package/lib/module/debug/checkCppVersion.js +29 -0
  156. package/lib/module/debug/checkCppVersion.js.map +1 -0
  157. package/lib/module/debug/errors.native.js +67 -0
  158. package/lib/module/debug/errors.native.js.map +1 -0
  159. package/lib/module/debug/jsVersion.js +9 -0
  160. package/lib/module/debug/jsVersion.js.map +1 -0
  161. package/lib/module/debug/logger.js +15 -0
  162. package/lib/module/debug/logger.js.map +1 -0
  163. package/lib/module/debug/slowAnimations.js +7 -0
  164. package/lib/module/debug/slowAnimations.js.map +1 -0
  165. package/lib/module/debug/slowAnimations.native.js +17 -0
  166. package/lib/module/debug/slowAnimations.native.js.map +1 -0
  167. package/lib/module/deprecated.js +27 -0
  168. package/lib/module/deprecated.js.map +1 -0
  169. package/lib/module/featureFlags/featureFlags.js +12 -0
  170. package/lib/module/featureFlags/featureFlags.js.map +1 -0
  171. package/lib/module/featureFlags/featureFlags.native.js +51 -0
  172. package/lib/module/featureFlags/featureFlags.native.js.map +1 -0
  173. package/lib/module/featureFlags/staticFlags.json +6 -0
  174. package/lib/module/featureFlags/types.js +16 -0
  175. package/lib/module/featureFlags/types.js.map +1 -0
  176. package/lib/module/guardImplementation.native.js +17 -0
  177. package/lib/module/guardImplementation.native.js.map +1 -0
  178. package/lib/module/index.js +26 -0
  179. package/lib/module/index.js.map +1 -0
  180. package/lib/module/initializers/initializers.js +24 -0
  181. package/lib/module/initializers/initializers.js.map +1 -0
  182. package/lib/module/initializers/initializers.native.js +195 -0
  183. package/lib/module/initializers/initializers.native.js.map +1 -0
  184. package/lib/module/memory/bundleUnpacker.native.js +38 -0
  185. package/lib/module/memory/bundleUnpacker.native.js.map +1 -0
  186. package/lib/module/memory/customSerializableUnpacker.native.js +20 -0
  187. package/lib/module/memory/customSerializableUnpacker.native.js.map +1 -0
  188. package/lib/module/memory/isShareable.js +8 -0
  189. package/lib/module/memory/isShareable.js.map +1 -0
  190. package/lib/module/memory/isSynchronizable.js +8 -0
  191. package/lib/module/memory/isSynchronizable.js.map +1 -0
  192. package/lib/module/memory/remoteFunctionUnpacker.native.js +18 -0
  193. package/lib/module/memory/remoteFunctionUnpacker.native.js.map +1 -0
  194. package/lib/module/memory/serializable.js +18 -0
  195. package/lib/module/memory/serializable.js.map +1 -0
  196. package/lib/module/memory/serializable.native.js +619 -0
  197. package/lib/module/memory/serializable.native.js.map +1 -0
  198. package/lib/module/memory/serializableMappingCache.js +11 -0
  199. package/lib/module/memory/serializableMappingCache.js.map +1 -0
  200. package/lib/module/memory/serializableMappingCache.native.js +29 -0
  201. package/lib/module/memory/serializableMappingCache.native.js.map +1 -0
  202. package/lib/module/memory/shareable.js +18 -0
  203. package/lib/module/memory/shareable.js.map +1 -0
  204. package/lib/module/memory/shareable.native.js +42 -0
  205. package/lib/module/memory/shareable.native.js.map +1 -0
  206. package/lib/module/memory/shareableGuestUnpacker.native.js +105 -0
  207. package/lib/module/memory/shareableGuestUnpacker.native.js.map +1 -0
  208. package/lib/module/memory/shareableHostUnpacker.native.js +20 -0
  209. package/lib/module/memory/shareableHostUnpacker.native.js.map +1 -0
  210. package/lib/module/memory/synchronizable.js +6 -0
  211. package/lib/module/memory/synchronizable.js.map +1 -0
  212. package/lib/module/memory/synchronizable.native.js +9 -0
  213. package/lib/module/memory/synchronizable.native.js.map +1 -0
  214. package/lib/module/memory/synchronizableUnpacker.native.js +47 -0
  215. package/lib/module/memory/synchronizableUnpacker.native.js.map +1 -0
  216. package/lib/module/memory/types.js +12 -0
  217. package/lib/module/memory/types.js.map +1 -0
  218. package/lib/module/memory/valueUnpacker.native.js +52 -0
  219. package/lib/module/memory/valueUnpacker.native.js.map +1 -0
  220. package/lib/module/mock.js +85 -0
  221. package/lib/module/mock.js.map +1 -0
  222. package/lib/module/package.json +1 -0
  223. package/lib/module/platformChecker.js +4 -0
  224. package/lib/module/platformChecker.js.map +1 -0
  225. package/lib/module/platformChecker.native.js +4 -0
  226. package/lib/module/platformChecker.native.js.map +1 -0
  227. package/lib/module/privateGlobals.d.js +7 -0
  228. package/lib/module/privateGlobals.d.js.map +1 -0
  229. package/lib/module/runLoop/common/setImmediatePolyfill.js +15 -0
  230. package/lib/module/runLoop/common/setImmediatePolyfill.js.map +1 -0
  231. package/lib/module/runLoop/common/setIntervalPolyfill.js +26 -0
  232. package/lib/module/runLoop/common/setIntervalPolyfill.js.map +1 -0
  233. package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js +10 -0
  234. package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js.map +1 -0
  235. package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +71 -0
  236. package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js.map +1 -0
  237. package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js +32 -0
  238. package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js.map +1 -0
  239. package/lib/module/runLoop/workletRuntime/index.js +19 -0
  240. package/lib/module/runLoop/workletRuntime/index.js.map +1 -0
  241. package/lib/module/runLoop/workletRuntime/queueMicrotask.js +11 -0
  242. package/lib/module/runLoop/workletRuntime/queueMicrotask.js.map +1 -0
  243. package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +48 -0
  244. package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js.map +1 -0
  245. package/lib/module/runLoop/workletRuntime/setTimeout.js +28 -0
  246. package/lib/module/runLoop/workletRuntime/setTimeout.js.map +1 -0
  247. package/lib/module/runLoop/workletRuntime/taskQueue.js +37 -0
  248. package/lib/module/runLoop/workletRuntime/taskQueue.js.map +1 -0
  249. package/lib/module/runtimeKind.js +92 -0
  250. package/lib/module/runtimeKind.js.map +1 -0
  251. package/lib/module/runtimes.js +36 -0
  252. package/lib/module/runtimes.js.map +1 -0
  253. package/lib/module/runtimes.native.js +379 -0
  254. package/lib/module/runtimes.native.js.map +1 -0
  255. package/lib/module/specs/NativeWorkletsModule.js +5 -0
  256. package/lib/module/specs/NativeWorkletsModule.js.map +1 -0
  257. package/lib/module/specs/index.js +10 -0
  258. package/lib/module/specs/index.js.map +1 -0
  259. package/lib/module/threads.js +60 -0
  260. package/lib/module/threads.js.map +1 -0
  261. package/lib/module/threads.native.js +295 -0
  262. package/lib/module/threads.native.js.map +1 -0
  263. package/lib/module/types.js +5 -0
  264. package/lib/module/types.js.map +1 -0
  265. package/lib/module/workletFunction.js +36 -0
  266. package/lib/module/workletFunction.js.map +1 -0
  267. package/lib/typescript/WorkletsModule/NativeWorklets.d.ts +3 -0
  268. package/lib/typescript/WorkletsModule/NativeWorklets.d.ts.map +1 -0
  269. package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts +3 -0
  270. package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts.map +1 -0
  271. package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +59 -0
  272. package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -0
  273. package/lib/typescript/bundleMode/metroOverrides.native.d.ts +9 -0
  274. package/lib/typescript/bundleMode/metroOverrides.native.d.ts.map +1 -0
  275. package/lib/typescript/bundleMode/network.native.d.ts +7 -0
  276. package/lib/typescript/bundleMode/network.native.d.ts.map +1 -0
  277. package/lib/typescript/debug/bundleMode.d.ts +2 -0
  278. package/lib/typescript/debug/bundleMode.d.ts.map +1 -0
  279. package/lib/typescript/debug/bundleMode.native.d.ts +2 -0
  280. package/lib/typescript/debug/bundleMode.native.d.ts.map +1 -0
  281. package/lib/typescript/debug/checkCppVersion.d.ts +3 -0
  282. package/lib/typescript/debug/checkCppVersion.d.ts.map +1 -0
  283. package/lib/typescript/debug/errors.native.d.ts +13 -0
  284. package/lib/typescript/debug/errors.native.d.ts.map +1 -0
  285. package/lib/typescript/debug/jsVersion.d.ts +7 -0
  286. package/lib/typescript/debug/jsVersion.d.ts.map +1 -0
  287. package/lib/typescript/debug/logger.d.ts +5 -0
  288. package/lib/typescript/debug/logger.d.ts.map +1 -0
  289. package/lib/typescript/debug/slowAnimations.d.ts +2 -0
  290. package/lib/typescript/debug/slowAnimations.d.ts.map +1 -0
  291. package/lib/typescript/debug/slowAnimations.native.d.ts +11 -0
  292. package/lib/typescript/debug/slowAnimations.native.d.ts.map +1 -0
  293. package/lib/typescript/deprecated.d.ts +19 -0
  294. package/lib/typescript/deprecated.d.ts.map +1 -0
  295. package/lib/typescript/featureFlags/featureFlags.d.ts +5 -0
  296. package/lib/typescript/featureFlags/featureFlags.d.ts.map +1 -0
  297. package/lib/typescript/featureFlags/featureFlags.native.d.ts +6 -0
  298. package/lib/typescript/featureFlags/featureFlags.native.d.ts.map +1 -0
  299. package/lib/typescript/featureFlags/types.d.ts +23 -0
  300. package/lib/typescript/featureFlags/types.d.ts.map +1 -0
  301. package/lib/typescript/guardImplementation.native.d.ts +3 -0
  302. package/lib/typescript/guardImplementation.native.d.ts.map +1 -0
  303. package/lib/typescript/index.d.ts +19 -0
  304. package/lib/typescript/index.d.ts.map +1 -0
  305. package/lib/typescript/initializers/initializers.d.ts +2 -0
  306. package/lib/typescript/initializers/initializers.d.ts.map +1 -0
  307. package/lib/typescript/initializers/initializers.native.d.ts +19 -0
  308. package/lib/typescript/initializers/initializers.native.d.ts.map +1 -0
  309. package/lib/typescript/memory/bundleUnpacker.native.d.ts +7 -0
  310. package/lib/typescript/memory/bundleUnpacker.native.d.ts.map +1 -0
  311. package/lib/typescript/memory/customSerializableUnpacker.native.d.ts +3 -0
  312. package/lib/typescript/memory/customSerializableUnpacker.native.d.ts.map +1 -0
  313. package/lib/typescript/memory/isShareable.d.ts +3 -0
  314. package/lib/typescript/memory/isShareable.d.ts.map +1 -0
  315. package/lib/typescript/memory/isSynchronizable.d.ts +3 -0
  316. package/lib/typescript/memory/isSynchronizable.d.ts.map +1 -0
  317. package/lib/typescript/memory/remoteFunctionUnpacker.native.d.ts +3 -0
  318. package/lib/typescript/memory/remoteFunctionUnpacker.native.d.ts.map +1 -0
  319. package/lib/typescript/memory/serializable.d.ts +7 -0
  320. package/lib/typescript/memory/serializable.d.ts.map +1 -0
  321. package/lib/typescript/memory/serializable.native.d.ts +37 -0
  322. package/lib/typescript/memory/serializable.native.d.ts.map +1 -0
  323. package/lib/typescript/memory/serializableMappingCache.d.ts +6 -0
  324. package/lib/typescript/memory/serializableMappingCache.d.ts.map +1 -0
  325. package/lib/typescript/memory/serializableMappingCache.native.d.ts +13 -0
  326. package/lib/typescript/memory/serializableMappingCache.native.d.ts.map +1 -0
  327. package/lib/typescript/memory/shareable.d.ts +15 -0
  328. package/lib/typescript/memory/shareable.d.ts.map +1 -0
  329. package/lib/typescript/memory/shareable.native.d.ts +15 -0
  330. package/lib/typescript/memory/shareable.native.d.ts.map +1 -0
  331. package/lib/typescript/memory/shareableGuestUnpacker.native.d.ts +4 -0
  332. package/lib/typescript/memory/shareableGuestUnpacker.native.d.ts.map +1 -0
  333. package/lib/typescript/memory/shareableHostUnpacker.native.d.ts +4 -0
  334. package/lib/typescript/memory/shareableHostUnpacker.native.d.ts.map +1 -0
  335. package/lib/typescript/memory/synchronizable.d.ts +3 -0
  336. package/lib/typescript/memory/synchronizable.d.ts.map +1 -0
  337. package/lib/typescript/memory/synchronizable.native.d.ts +3 -0
  338. package/lib/typescript/memory/synchronizable.native.d.ts.map +1 -0
  339. package/lib/typescript/memory/synchronizableUnpacker.native.d.ts +4 -0
  340. package/lib/typescript/memory/synchronizableUnpacker.native.d.ts.map +1 -0
  341. package/lib/typescript/memory/types.d.ts +136 -0
  342. package/lib/typescript/memory/types.d.ts.map +1 -0
  343. package/lib/typescript/memory/valueUnpacker.native.d.ts +7 -0
  344. package/lib/typescript/memory/valueUnpacker.native.d.ts.map +1 -0
  345. package/lib/typescript/mock.d.ts +2 -0
  346. package/lib/typescript/mock.d.ts.map +1 -0
  347. package/lib/typescript/package.json +1 -0
  348. package/lib/typescript/platformChecker.d.ts +2 -0
  349. package/lib/typescript/platformChecker.d.ts.map +1 -0
  350. package/lib/typescript/platformChecker.native.d.ts +2 -0
  351. package/lib/typescript/platformChecker.native.d.ts.map +1 -0
  352. package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts +2 -0
  353. package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts.map +1 -0
  354. package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts +2 -0
  355. package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts.map +1 -0
  356. package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts +6 -0
  357. package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts.map +1 -0
  358. package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts +2 -0
  359. package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts.map +1 -0
  360. package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts +2 -0
  361. package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts.map +1 -0
  362. package/lib/typescript/runLoop/workletRuntime/index.d.ts +2 -0
  363. package/lib/typescript/runLoop/workletRuntime/index.d.ts.map +1 -0
  364. package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts +2 -0
  365. package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts.map +1 -0
  366. package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts +2 -0
  367. package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts.map +1 -0
  368. package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts +2 -0
  369. package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts.map +1 -0
  370. package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts +10 -0
  371. package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts.map +1 -0
  372. package/lib/typescript/runtimeKind.d.ts +56 -0
  373. package/lib/typescript/runtimeKind.d.ts.map +1 -0
  374. package/lib/typescript/runtimes.d.ts +15 -0
  375. package/lib/typescript/runtimes.d.ts.map +1 -0
  376. package/lib/typescript/runtimes.native.d.ts +155 -0
  377. package/lib/typescript/runtimes.native.d.ts.map +1 -0
  378. package/lib/typescript/specs/NativeWorkletsModule.d.ts +9 -0
  379. package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -0
  380. package/lib/typescript/specs/index.d.ts +3 -0
  381. package/lib/typescript/specs/index.d.ts.map +1 -0
  382. package/lib/typescript/threads.d.ts +8 -0
  383. package/lib/typescript/threads.d.ts.map +1 -0
  384. package/lib/typescript/threads.native.d.ts +125 -0
  385. package/lib/typescript/threads.native.d.ts.map +1 -0
  386. package/lib/typescript/types.d.ts +136 -0
  387. package/lib/typescript/types.d.ts.map +1 -0
  388. package/lib/typescript/workletFunction.d.ts +26 -0
  389. package/lib/typescript/workletFunction.d.ts.map +1 -0
  390. package/package.json +220 -0
  391. package/plugin/index.d.ts +168 -0
  392. package/plugin/index.js +2188 -0
  393. package/scripts/validate-react-native-version.js +43 -0
  394. package/scripts/worklets_utils.rb +94 -0
  395. package/src/WorkletsModule/NativeWorklets.native.ts +461 -0
  396. package/src/WorkletsModule/NativeWorklets.ts +5 -0
  397. package/src/WorkletsModule/workletsModuleProxy.ts +247 -0
  398. package/src/bundleMode/metroOverrides.native.ts +33 -0
  399. package/src/bundleMode/network.native.ts +63 -0
  400. package/src/debug/bundleMode.native.ts +18 -0
  401. package/src/debug/bundleMode.ts +5 -0
  402. package/src/debug/checkCppVersion.ts +34 -0
  403. package/src/debug/errors.native.ts +74 -0
  404. package/src/debug/jsVersion.ts +8 -0
  405. package/src/debug/logger.ts +16 -0
  406. package/src/debug/slowAnimations.native.ts +15 -0
  407. package/src/debug/slowAnimations.ts +6 -0
  408. package/src/deprecated.ts +38 -0
  409. package/src/featureFlags/featureFlags.native.ts +70 -0
  410. package/src/featureFlags/featureFlags.ts +20 -0
  411. package/src/featureFlags/staticFlags.json +6 -0
  412. package/src/featureFlags/types.ts +32 -0
  413. package/src/guardImplementation.native.ts +26 -0
  414. package/src/index.ts +95 -0
  415. package/src/initializers/initializers.native.ts +218 -0
  416. package/src/initializers/initializers.ts +24 -0
  417. package/src/memory/bundleUnpacker.native.ts +59 -0
  418. package/src/memory/customSerializableUnpacker.native.ts +30 -0
  419. package/src/memory/isShareable.ts +16 -0
  420. package/src/memory/isSynchronizable.ts +14 -0
  421. package/src/memory/remoteFunctionUnpacker.native.ts +27 -0
  422. package/src/memory/serializable.native.ts +889 -0
  423. package/src/memory/serializable.ts +36 -0
  424. package/src/memory/serializableMappingCache.native.ts +37 -0
  425. package/src/memory/serializableMappingCache.ts +12 -0
  426. package/src/memory/shareable.native.ts +68 -0
  427. package/src/memory/shareable.ts +27 -0
  428. package/src/memory/shareableGuestUnpacker.native.ts +168 -0
  429. package/src/memory/shareableHostUnpacker.native.ts +31 -0
  430. package/src/memory/synchronizable.native.ts +17 -0
  431. package/src/memory/synchronizable.ts +9 -0
  432. package/src/memory/synchronizableUnpacker.native.ts +65 -0
  433. package/src/memory/types.ts +191 -0
  434. package/src/memory/valueUnpacker.native.ts +79 -0
  435. package/src/mock.ts +111 -0
  436. package/src/platformChecker.native.ts +3 -0
  437. package/src/platformChecker.ts +4 -0
  438. package/src/privateGlobals.d.ts +127 -0
  439. package/src/runLoop/common/setImmediatePolyfill.ts +20 -0
  440. package/src/runLoop/common/setIntervalPolyfill.ts +38 -0
  441. package/src/runLoop/uiRuntime/mockedRequestAnimationFrame.ts +11 -0
  442. package/src/runLoop/uiRuntime/requestAnimationFrame.ts +87 -0
  443. package/src/runLoop/uiRuntime/setTimeoutPolyfill.ts +40 -0
  444. package/src/runLoop/workletRuntime/index.ts +18 -0
  445. package/src/runLoop/workletRuntime/queueMicrotask.ts +13 -0
  446. package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +61 -0
  447. package/src/runLoop/workletRuntime/setTimeout.ts +37 -0
  448. package/src/runLoop/workletRuntime/taskQueue.ts +44 -0
  449. package/src/runtimeKind.ts +85 -0
  450. package/src/runtimes.native.ts +572 -0
  451. package/src/runtimes.ts +107 -0
  452. package/src/specs/NativeWorkletsModule.ts +11 -0
  453. package/src/specs/index.ts +13 -0
  454. package/src/threads.native.ts +408 -0
  455. package/src/threads.ts +110 -0
  456. package/src/types.ts +164 -0
  457. 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,13 @@
1
+ /**
2
+ * Based on ProgressListener.kt from React Native
3
+ */
4
+
5
+ package com.swmansion.worklets
6
+
7
+ public fun interface WorkletsProgressListener {
8
+ public fun onProgress(
9
+ bytesWritten: Long,
10
+ contentLength: Long,
11
+ done: Boolean,
12
+ )
13
+ }
@@ -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