@depup/react-native-worklets 0.12.1-depup.0 → 0.13.0-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 (311) hide show
  1. package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.cpp +1 -2
  2. package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.h +1 -1
  3. package/Common/cpp/worklets/Compat/StableApi.cpp +24 -8
  4. package/Common/cpp/worklets/Compat/StableApi.h +1 -1
  5. package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +113 -50
  6. package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +10 -1
  7. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +95 -37
  8. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +57 -7
  9. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxyInitializer.cpp +94 -0
  10. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxyInitializer.h +58 -0
  11. package/Common/cpp/worklets/Networking/Networking.cpp +283 -0
  12. package/Common/cpp/worklets/Networking/Networking.h +51 -0
  13. package/Common/cpp/worklets/Networking/NetworkingBackend.h +47 -0
  14. package/Common/cpp/worklets/Networking/NetworkingInstaller.cpp +127 -0
  15. package/Common/cpp/worklets/Networking/NetworkingInstaller.h +19 -0
  16. package/Common/cpp/worklets/Networking/NetworkingTypes.h +33 -0
  17. package/Common/cpp/worklets/Networking/TextDecoding.cpp +189 -0
  18. package/Common/cpp/worklets/Networking/TextDecoding.h +29 -0
  19. package/Common/cpp/worklets/RunLoop/AsyncQueue.h +28 -0
  20. package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +9 -0
  21. package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +6 -0
  22. package/Common/cpp/worklets/RunLoop/EventLoop.cpp +19 -4
  23. package/Common/cpp/worklets/RunLoop/EventLoop.h +3 -0
  24. package/Common/cpp/worklets/SharedItems/MemoryManager.cpp +1 -1
  25. package/Common/cpp/worklets/SharedItems/MemoryManager.h +2 -1
  26. package/Common/cpp/worklets/SharedItems/Serializable/CustomSerializable.cpp +37 -0
  27. package/Common/cpp/worklets/SharedItems/Serializable/CustomSerializable.h +33 -0
  28. package/Common/cpp/worklets/SharedItems/Serializable/RetainingSerializable.h +112 -0
  29. package/Common/cpp/worklets/SharedItems/Serializable/Serializable.cpp +129 -0
  30. package/Common/cpp/worklets/SharedItems/Serializable/Serializable.h +121 -0
  31. package/Common/cpp/worklets/SharedItems/Serializable/SerializableArray.cpp +38 -0
  32. package/Common/cpp/worklets/SharedItems/Serializable/SerializableArray.h +39 -0
  33. package/Common/cpp/worklets/SharedItems/Serializable/SerializableArrayBuffer.cpp +35 -0
  34. package/Common/cpp/worklets/SharedItems/Serializable/SerializableArrayBuffer.h +43 -0
  35. package/Common/cpp/worklets/SharedItems/Serializable/SerializableBigInt.cpp +23 -0
  36. package/Common/cpp/worklets/SharedItems/Serializable/SerializableBigInt.h +35 -0
  37. package/Common/cpp/worklets/SharedItems/Serializable/SerializableError.cpp +38 -0
  38. package/Common/cpp/worklets/SharedItems/Serializable/SerializableError.h +30 -0
  39. package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostFunction.cpp +24 -0
  40. package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostFunction.h +32 -0
  41. package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostObject.cpp +19 -0
  42. package/Common/cpp/worklets/SharedItems/Serializable/SerializableHostObject.h +25 -0
  43. package/Common/cpp/worklets/SharedItems/Serializable/SerializableImport.cpp +29 -0
  44. package/Common/cpp/worklets/SharedItems/Serializable/SerializableImport.h +25 -0
  45. package/Common/cpp/worklets/SharedItems/Serializable/SerializableMap.cpp +44 -0
  46. package/Common/cpp/worklets/SharedItems/Serializable/SerializableMap.h +25 -0
  47. package/Common/cpp/worklets/SharedItems/Serializable/SerializableObject.cpp +80 -0
  48. package/Common/cpp/worklets/SharedItems/Serializable/SerializableObject.h +35 -0
  49. package/Common/cpp/worklets/SharedItems/Serializable/SerializableRegExp.cpp +22 -0
  50. package/Common/cpp/worklets/SharedItems/Serializable/SerializableRegExp.h +25 -0
  51. package/Common/cpp/worklets/SharedItems/{SerializableRemoteFunction.cpp → Serializable/SerializableRemoteFunction.cpp} +30 -2
  52. package/Common/cpp/worklets/SharedItems/{SerializableRemoteFunction.h → Serializable/SerializableRemoteFunction.h} +24 -10
  53. package/Common/cpp/worklets/SharedItems/Serializable/SerializableScalar.cpp +46 -0
  54. package/Common/cpp/worklets/SharedItems/Serializable/SerializableScalar.h +41 -0
  55. package/Common/cpp/worklets/SharedItems/Serializable/SerializableSet.cpp +36 -0
  56. package/Common/cpp/worklets/SharedItems/Serializable/SerializableSet.h +23 -0
  57. package/Common/cpp/worklets/SharedItems/Serializable/SerializableString.cpp +19 -0
  58. package/Common/cpp/worklets/SharedItems/Serializable/SerializableString.h +22 -0
  59. package/Common/cpp/worklets/SharedItems/Serializable/SerializableTurboModuleLike.cpp +26 -0
  60. package/Common/cpp/worklets/SharedItems/Serializable/SerializableTurboModuleLike.h +33 -0
  61. package/Common/cpp/worklets/SharedItems/Serializable/SerializableWorklet.cpp +31 -0
  62. package/Common/cpp/worklets/SharedItems/Serializable/SerializableWorklet.h +23 -0
  63. package/Common/cpp/worklets/SharedItems/Serializable.h +21 -409
  64. package/Common/cpp/worklets/SharedItems/Shareable.cpp +1 -1
  65. package/Common/cpp/worklets/SharedItems/Shareable.h +1 -1
  66. package/Common/cpp/worklets/SharedItems/Synchronizable.h +43 -20
  67. package/Common/cpp/worklets/SharedItems/SynchronizableAccess.cpp +24 -26
  68. package/Common/cpp/worklets/SharedItems/SynchronizableAccess.h +5 -7
  69. package/Common/cpp/worklets/SharedItems/SynchronizableDynamic.cpp +36 -0
  70. package/Common/cpp/worklets/SharedItems/SynchronizableDynamic.h +27 -0
  71. package/Common/cpp/worklets/SharedItems/SynchronizableFixed.cpp +76 -0
  72. package/Common/cpp/worklets/SharedItems/SynchronizableFixed.h +48 -0
  73. package/Common/cpp/worklets/Tools/ScriptBuffer.h +0 -5
  74. package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +16 -30
  75. package/Common/cpp/worklets/WorkletRuntime/RuntimeBindings.h +27 -30
  76. package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +4 -3
  77. package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +2 -1
  78. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +79 -29
  79. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +34 -19
  80. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +13 -86
  81. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +1 -7
  82. package/Package.swift +147 -0
  83. package/README.md +7 -7
  84. package/RNWorklets.podspec +1 -2
  85. package/android/CMakeLists.txt +7 -26
  86. package/android/build.gradle.kts +5 -31
  87. package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +46 -129
  88. package/android/src/main/cpp/worklets/android/WorkletsModule.h +21 -11
  89. package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +2 -4
  90. package/android/src/main/cpp/worklets/android/networking/AndroidNetworkingBackend.cpp +82 -0
  91. package/android/src/main/cpp/worklets/android/networking/AndroidNetworkingBackend.h +32 -0
  92. package/android/src/main/cpp/worklets/android/networking/JNetworkRequestListener.cpp +73 -0
  93. package/android/src/main/cpp/worklets/android/networking/JNetworkRequestListener.h +38 -0
  94. package/android/src/{no-networking → main/java}/com/swmansion/worklets/WorkletsModule.kt +40 -28
  95. package/android/src/main/java/com/swmansion/worklets/networking/NetworkRequestListener.kt +37 -0
  96. package/android/src/main/java/com/swmansion/worklets/networking/Networking.kt +244 -0
  97. package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameQueue.kt +40 -5
  98. package/apple/worklets/apple/AnimationFrameQueue.mm +9 -1
  99. package/apple/worklets/apple/AssertJavaScriptQueue.h +3 -2
  100. package/apple/worklets/apple/AssertTurboModuleManagerQueue.h +4 -0
  101. package/apple/worklets/apple/IOSUIScheduler.mm +3 -0
  102. package/apple/worklets/apple/Networking/AppleNetworkingBackend.h +29 -0
  103. package/apple/worklets/apple/Networking/AppleNetworkingBackend.mm +93 -0
  104. package/apple/worklets/apple/Networking/WorkletsURLSessionDelegate.h +37 -0
  105. package/apple/worklets/apple/Networking/WorkletsURLSessionDelegate.mm +447 -0
  106. package/apple/worklets/apple/WorkletsModule.h +3 -2
  107. package/apple/worklets/apple/WorkletsModule.mm +82 -74
  108. package/bundleMode/index.js +10 -47
  109. package/bundleMode/polyfills/prepareBundleMode.js +16 -0
  110. package/changes.json +6 -6
  111. package/compatibility.json +4 -1
  112. package/lib/module/WorkletsModule/NativeWorklets.native.js +12 -9
  113. package/lib/module/WorkletsModule/NativeWorklets.native.js.map +1 -1
  114. package/lib/module/debug/jsVersion.js +1 -1
  115. package/lib/module/featureFlags/staticFlags.json +0 -1
  116. package/lib/module/featureFlags/types.js +0 -1
  117. package/lib/module/featureFlags/types.js.map +1 -1
  118. package/lib/module/index.js +1 -1
  119. package/lib/module/index.js.map +1 -1
  120. package/lib/module/initializers/initializers.native.js +5 -12
  121. package/lib/module/initializers/initializers.native.js.map +1 -1
  122. package/lib/module/memory/bundleUnpacker.native.js +2 -10
  123. package/lib/module/memory/bundleUnpacker.native.js.map +1 -1
  124. package/lib/module/memory/serializable.native.js +3 -31
  125. package/lib/module/memory/serializable.native.js.map +1 -1
  126. package/lib/module/memory/synchronizable.js +1 -1
  127. package/lib/module/memory/synchronizable.js.map +1 -1
  128. package/lib/module/memory/synchronizable.native.js +7 -3
  129. package/lib/module/memory/synchronizable.native.js.map +1 -1
  130. package/lib/module/memory/synchronizableUnpacker.native.js +22 -9
  131. package/lib/module/memory/synchronizableUnpacker.native.js.map +1 -1
  132. package/lib/module/memory/valueUnpacker.native.js +0 -8
  133. package/lib/module/memory/valueUnpacker.native.js.map +1 -1
  134. package/lib/module/mock.js +22 -1
  135. package/lib/module/mock.js.map +1 -1
  136. package/lib/module/networking/AbortController.js +43 -0
  137. package/lib/module/networking/AbortController.js.map +1 -0
  138. package/lib/module/networking/Blob.js +60 -0
  139. package/lib/module/networking/Blob.js.map +1 -0
  140. package/lib/module/networking/DOMException.js +35 -0
  141. package/lib/module/networking/DOMException.js.map +1 -0
  142. package/lib/module/networking/FileReader.js +83 -0
  143. package/lib/module/networking/FileReader.js.map +1 -0
  144. package/lib/module/networking/FormData.js +105 -0
  145. package/lib/module/networking/FormData.js.map +1 -0
  146. package/lib/module/networking/XMLHttpRequest.js +450 -0
  147. package/lib/module/networking/XMLHttpRequest.js.map +1 -0
  148. package/lib/module/networking/bytes.js +6 -0
  149. package/lib/module/networking/bytes.js.map +1 -0
  150. package/lib/module/networking/events.js +44 -0
  151. package/lib/module/networking/events.js.map +1 -0
  152. package/lib/module/networking/http.js +100 -0
  153. package/lib/module/networking/http.js.map +1 -0
  154. package/lib/module/networking/install.js +37 -0
  155. package/lib/module/networking/install.js.map +1 -0
  156. package/lib/module/networking/utf8.js +99 -0
  157. package/lib/module/networking/utf8.js.map +1 -0
  158. package/lib/module/privateGlobals.d.js +0 -1
  159. package/lib/module/privateGlobals.d.js.map +1 -1
  160. package/lib/module/runLoop/common/queueMicrotaskPolyfill.js +9 -0
  161. package/lib/module/runLoop/common/queueMicrotaskPolyfill.js.map +1 -0
  162. package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +7 -3
  163. package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js.map +1 -1
  164. package/lib/module/runLoop/workletRuntime/index.js +1 -1
  165. package/lib/module/runLoop/workletRuntime/index.js.map +1 -1
  166. package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +1 -1
  167. package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js.map +1 -1
  168. package/lib/module/runLoop/workletRuntime/taskQueue.js +0 -13
  169. package/lib/module/runLoop/workletRuntime/taskQueue.js.map +1 -1
  170. package/lib/module/runtimes.native.js +8 -1
  171. package/lib/module/runtimes.native.js.map +1 -1
  172. package/lib/module/specs/NativeWorkletsModule.js.map +1 -1
  173. package/lib/module/threads.js +11 -0
  174. package/lib/module/threads.js.map +1 -1
  175. package/lib/module/threads.native.js +35 -42
  176. package/lib/module/threads.native.js.map +1 -1
  177. package/lib/typescript/WorkletsModule/NativeWorklets.native.d.ts.map +1 -1
  178. package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +6 -5
  179. package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -1
  180. package/lib/typescript/debug/jsVersion.d.ts +1 -1
  181. package/lib/typescript/featureFlags/types.d.ts +0 -1
  182. package/lib/typescript/featureFlags/types.d.ts.map +1 -1
  183. package/lib/typescript/index.d.ts +2 -2
  184. package/lib/typescript/index.d.ts.map +1 -1
  185. package/lib/typescript/memory/bundleUnpacker.native.d.ts.map +1 -1
  186. package/lib/typescript/memory/serializable.native.d.ts.map +1 -1
  187. package/lib/typescript/memory/synchronizable.d.ts +6 -2
  188. package/lib/typescript/memory/synchronizable.d.ts.map +1 -1
  189. package/lib/typescript/memory/synchronizable.native.d.ts +6 -2
  190. package/lib/typescript/memory/synchronizable.native.d.ts.map +1 -1
  191. package/lib/typescript/memory/synchronizableUnpacker.native.d.ts +1 -1
  192. package/lib/typescript/memory/synchronizableUnpacker.native.d.ts.map +1 -1
  193. package/lib/typescript/memory/types.d.ts +6 -0
  194. package/lib/typescript/memory/types.d.ts.map +1 -1
  195. package/lib/typescript/memory/valueUnpacker.native.d.ts.map +1 -1
  196. package/lib/typescript/networking/AbortController.d.ts +16 -0
  197. package/lib/typescript/networking/AbortController.d.ts.map +1 -0
  198. package/lib/typescript/networking/Blob.d.ts +16 -0
  199. package/lib/typescript/networking/Blob.d.ts.map +1 -0
  200. package/lib/typescript/networking/DOMException.d.ts +5 -0
  201. package/lib/typescript/networking/DOMException.d.ts.map +1 -0
  202. package/lib/typescript/networking/FileReader.d.ts +19 -0
  203. package/lib/typescript/networking/FileReader.d.ts.map +1 -0
  204. package/lib/typescript/networking/FormData.d.ts +30 -0
  205. package/lib/typescript/networking/FormData.d.ts.map +1 -0
  206. package/lib/typescript/networking/XMLHttpRequest.d.ts +77 -0
  207. package/lib/typescript/networking/XMLHttpRequest.d.ts.map +1 -0
  208. package/lib/typescript/networking/bytes.d.ts +2 -0
  209. package/lib/typescript/networking/bytes.d.ts.map +1 -0
  210. package/lib/typescript/networking/events.d.ts +18 -0
  211. package/lib/typescript/networking/events.d.ts.map +1 -0
  212. package/lib/typescript/networking/http.d.ts +14 -0
  213. package/lib/typescript/networking/http.d.ts.map +1 -0
  214. package/lib/typescript/networking/install.d.ts +2 -0
  215. package/lib/typescript/networking/install.d.ts.map +1 -0
  216. package/lib/typescript/networking/utf8.d.ts +4 -0
  217. package/lib/typescript/networking/utf8.d.ts.map +1 -0
  218. package/lib/typescript/runLoop/{workletRuntime/queueMicrotask.d.ts → common/queueMicrotaskPolyfill.d.ts} +1 -1
  219. package/lib/typescript/runLoop/common/queueMicrotaskPolyfill.d.ts.map +1 -0
  220. package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts.map +1 -1
  221. package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts +0 -2
  222. package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts.map +1 -1
  223. package/lib/typescript/runtimes.native.d.ts.map +1 -1
  224. package/lib/typescript/specs/NativeWorkletsModule.d.ts +1 -0
  225. package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -1
  226. package/lib/typescript/threads.d.ts +8 -0
  227. package/lib/typescript/threads.d.ts.map +1 -1
  228. package/lib/typescript/threads.native.d.ts +8 -1
  229. package/lib/typescript/threads.native.d.ts.map +1 -1
  230. package/lib/typescript/types.d.ts +9 -5
  231. package/lib/typescript/types.d.ts.map +1 -1
  232. package/package.json +36 -22
  233. package/plugin/index.js +63 -93
  234. package/plugin-oxc/babel.d.ts +7 -0
  235. package/plugin-oxc/babel.js +200 -0
  236. package/plugin-oxc/index.d.ts +33 -0
  237. package/plugin-oxc/index.js +36 -0
  238. package/plugin-oxc/worklets-oxc-plugin.darwin-arm64.node +0 -0
  239. package/plugin-oxc/worklets-oxc-plugin.darwin-x64.node +0 -0
  240. package/plugin-oxc/worklets-oxc-plugin.linux-arm64.node +0 -0
  241. package/plugin-oxc/worklets-oxc-plugin.linux-x64.node +0 -0
  242. package/plugin-oxc/worklets-oxc-plugin.win32-arm64.node +0 -0
  243. package/plugin-oxc/worklets-oxc-plugin.win32-x64.node +0 -0
  244. package/react-native.config.js +5 -0
  245. package/scripts/worklets_utils.rb +0 -10
  246. package/src/WorkletsModule/NativeWorklets.native.ts +26 -9
  247. package/src/WorkletsModule/workletsModuleProxy.ts +15 -5
  248. package/src/debug/jsVersion.ts +1 -1
  249. package/src/featureFlags/staticFlags.json +0 -1
  250. package/src/featureFlags/types.ts +0 -1
  251. package/src/index.ts +3 -0
  252. package/src/initializers/initializers.native.ts +5 -13
  253. package/src/memory/bundleUnpacker.native.ts +6 -13
  254. package/src/memory/serializable.native.ts +6 -46
  255. package/src/memory/synchronizable.native.ts +38 -4
  256. package/src/memory/synchronizable.ts +22 -2
  257. package/src/memory/synchronizableUnpacker.native.ts +38 -13
  258. package/src/memory/types.ts +9 -0
  259. package/src/memory/valueUnpacker.native.ts +0 -8
  260. package/src/mock.ts +28 -1
  261. package/src/networking/AbortController.ts +57 -0
  262. package/src/networking/Blob.ts +74 -0
  263. package/src/networking/DOMException.ts +37 -0
  264. package/src/networking/FileReader.ts +99 -0
  265. package/src/networking/FormData.ts +135 -0
  266. package/src/networking/XMLHttpRequest.ts +557 -0
  267. package/src/networking/bytes.ts +8 -0
  268. package/src/networking/events.ts +61 -0
  269. package/src/networking/http.ts +173 -0
  270. package/src/networking/install.ts +38 -0
  271. package/src/networking/utf8.ts +122 -0
  272. package/src/privateGlobals.d.ts +20 -13
  273. package/src/runLoop/common/queueMicrotaskPolyfill.ts +12 -0
  274. package/src/runLoop/uiRuntime/requestAnimationFrame.ts +7 -4
  275. package/src/runLoop/workletRuntime/index.ts +1 -1
  276. package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +1 -1
  277. package/src/runLoop/workletRuntime/taskQueue.ts +0 -15
  278. package/src/runtimes.native.ts +10 -1
  279. package/src/specs/NativeWorkletsModule.ts +1 -0
  280. package/src/threads.native.ts +49 -54
  281. package/src/threads.ts +11 -0
  282. package/src/types.ts +9 -5
  283. package/Common/cpp/worklets/SharedItems/Serializable.cpp +0 -373
  284. package/Common/cpp/worklets/SharedItems/SerializableFactory.cpp +0 -172
  285. package/Common/cpp/worklets/SharedItems/SerializableFactory.h +0 -85
  286. package/Common/cpp/worklets/SharedItems/Synchronizable.cpp +0 -59
  287. package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.cpp +0 -51
  288. package/android/src/main/cpp/worklets/android/JWorkletRuntimeWrapper.h +0 -43
  289. package/android/src/networking/com/swmansion/worklets/WorkletRuntimeWrapper.kt +0 -27
  290. package/android/src/networking/com/swmansion/worklets/WorkletsHeaderUtil.kt +0 -30
  291. package/android/src/networking/com/swmansion/worklets/WorkletsModule.kt +0 -203
  292. package/android/src/networking/com/swmansion/worklets/WorkletsNetworkEventUtil.kt +0 -272
  293. package/android/src/networking/com/swmansion/worklets/WorkletsNetworking.kt +0 -1124
  294. package/android/src/networking/com/swmansion/worklets/WorkletsOkHttpCallUtil.kt +0 -40
  295. package/android/src/networking/com/swmansion/worklets/WorkletsProgressListener.kt +0 -13
  296. package/android/src/networking/com/swmansion/worklets/WorkletsProgressRequestBody.kt +0 -98
  297. package/android/src/networking/com/swmansion/worklets/WorkletsProgressResponseBody.kt +0 -60
  298. package/android/src/networking/com/swmansion/worklets/WorkletsProgressiveStringDecoder.kt +0 -87
  299. package/android/src/networking/com/swmansion/worklets/WorkletsRequestBodyUtil.kt +0 -181
  300. package/apple/worklets/apple/Networking/WorkletsNetworking.h +0 -25
  301. package/apple/worklets/apple/Networking/WorkletsNetworking.mm +0 -707
  302. package/bundleMode/shims/turboModuleRegistryShim.js +0 -47
  303. package/lib/module/bundleMode/network.native.js +0 -44
  304. package/lib/module/bundleMode/network.native.js.map +0 -1
  305. package/lib/module/runLoop/workletRuntime/queueMicrotask.js +0 -11
  306. package/lib/module/runLoop/workletRuntime/queueMicrotask.js.map +0 -1
  307. package/lib/typescript/bundleMode/network.native.d.ts +0 -7
  308. package/lib/typescript/bundleMode/network.native.d.ts.map +0 -1
  309. package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts.map +0 -1
  310. package/src/bundleMode/network.native.ts +0 -63
  311. package/src/runLoop/workletRuntime/queueMicrotask.ts +0 -13
@@ -0,0 +1,73 @@
1
+ #include <worklets/android/networking/JNetworkRequestListener.h>
2
+
3
+ #include <string>
4
+ #include <utility>
5
+ #include <vector>
6
+
7
+ namespace worklets {
8
+
9
+ // Must match the error codes in
10
+ // `android/src/main/java/com/swmansion/worklets/networking/Networking.kt`.
11
+ constexpr jint kErrorTimeout = 1;
12
+ constexpr jint kErrorAborted = 2;
13
+
14
+ void JNetworkRequestListener::onResponse(
15
+ jint status,
16
+ jni::alias_ref<jni::JString> statusText, // NOLINT //(performance-unnecessary-value-param)
17
+ jni::alias_ref<jni::JArrayClass<jni::JString>> headerNames, // NOLINT //(performance-unnecessary-value-param)
18
+ jni::alias_ref<jni::JArrayClass<jni::JString>> headerValues, // NOLINT //(performance-unnecessary-value-param)
19
+ jni::alias_ref<jni::JString> url // NOLINT //(performance-unnecessary-value-param)
20
+ ) {
21
+ ResponseInfo responseInfo;
22
+ responseInfo.status = status;
23
+ responseInfo.statusText = statusText->toStdString();
24
+ const auto size = headerNames->size();
25
+ responseInfo.headers.reserve(size);
26
+ for (size_t i = 0; i < size; i++) {
27
+ responseInfo.headers.emplace_back(
28
+ headerNames->getElement(i)->toStdString(), headerValues->getElement(i)->toStdString());
29
+ }
30
+ responseInfo.url = url->toStdString();
31
+ listener_->onResponse(std::move(responseInfo));
32
+ }
33
+
34
+ void JNetworkRequestListener::onUploadProgress(jlong sent, jlong total) {
35
+ listener_->onUploadProgress(sent, total);
36
+ }
37
+
38
+ void JNetworkRequestListener::onDownloadProgress(jlong received, jlong total) {
39
+ listener_->onDownloadProgress(received, total);
40
+ }
41
+
42
+ void JNetworkRequestListener::onComplete(
43
+ jni::alias_ref<jni::JArrayByte> body // NOLINT //(performance-unnecessary-value-param)
44
+ ) {
45
+ const auto size = body->size();
46
+ std::vector<uint8_t> bytes(size);
47
+ body->getRegion(0, size, reinterpret_cast<jbyte *>(bytes.data()));
48
+ listener_->onComplete(std::move(bytes));
49
+ }
50
+
51
+ void JNetworkRequestListener::onError(
52
+ jint errorCode,
53
+ jni::alias_ref<jni::JString> message // NOLINT //(performance-unnecessary-value-param)
54
+ ) {
55
+ auto error = RequestError::Network;
56
+ if (errorCode == kErrorTimeout) {
57
+ error = RequestError::Timeout;
58
+ } else if (errorCode == kErrorAborted) {
59
+ error = RequestError::Aborted;
60
+ }
61
+ listener_->onError(error, message->toStdString());
62
+ }
63
+
64
+ void JNetworkRequestListener::registerNatives() {
65
+ registerHybrid(
66
+ {makeNativeMethod("onResponse", JNetworkRequestListener::onResponse),
67
+ makeNativeMethod("onUploadProgress", JNetworkRequestListener::onUploadProgress),
68
+ makeNativeMethod("onDownloadProgress", JNetworkRequestListener::onDownloadProgress),
69
+ makeNativeMethod("onComplete", JNetworkRequestListener::onComplete),
70
+ makeNativeMethod("onError", JNetworkRequestListener::onError)});
71
+ }
72
+
73
+ } // namespace worklets
@@ -0,0 +1,38 @@
1
+ #pragma once
2
+
3
+ #include <fbjni/fbjni.h>
4
+ #include <worklets/Networking/NetworkingBackend.h>
5
+
6
+ #include <memory>
7
+ #include <utility>
8
+
9
+ namespace worklets {
10
+
11
+ using namespace facebook;
12
+
13
+ class JNetworkRequestListener : public jni::HybridClass<JNetworkRequestListener> {
14
+ public:
15
+ static auto constexpr kJavaDescriptor = "Lcom/swmansion/worklets/networking/NetworkRequestListener;";
16
+
17
+ static void registerNatives();
18
+
19
+ void onResponse(
20
+ jint status,
21
+ jni::alias_ref<jni::JString> statusText,
22
+ jni::alias_ref<jni::JArrayClass<jni::JString>> headerNames,
23
+ jni::alias_ref<jni::JArrayClass<jni::JString>> headerValues,
24
+ jni::alias_ref<jni::JString> url);
25
+ void onUploadProgress(jlong sent, jlong total);
26
+ void onDownloadProgress(jlong received, jlong total);
27
+ void onComplete(jni::alias_ref<jni::JArrayByte> body);
28
+ void onError(jint errorCode, jni::alias_ref<jni::JString> message);
29
+
30
+ private:
31
+ friend HybridBase;
32
+
33
+ explicit JNetworkRequestListener(std::shared_ptr<NetworkRequestListener> listener) : listener_(std::move(listener)) {}
34
+
35
+ const std::shared_ptr<NetworkRequestListener> listener_;
36
+ };
37
+
38
+ } // namespace worklets
@@ -9,11 +9,12 @@ import com.facebook.react.common.annotations.FrameworkAPI
9
9
  import com.facebook.react.module.annotations.ReactModule
10
10
  import com.facebook.react.turbomodule.core.CallInvokerHolderImpl
11
11
  import com.facebook.soloader.SoLoader
12
+ import com.swmansion.worklets.networking.Networking
12
13
  import com.swmansion.worklets.runloop.AnimationFrameCallback
13
14
  import com.swmansion.worklets.runloop.AnimationFrameQueue
14
15
 
15
16
  @Suppress("KotlinJniMissingFunction")
16
- @ReactModule(name = WorkletsModule.NAME)
17
+ @ReactModule(name = WorkletsModule.NAME, needsEagerInit = true)
17
18
  class WorkletsModule(
18
19
  reactContext: ReactApplicationContext,
19
20
  ) : NativeWorkletsModuleSpec(reactContext),
@@ -33,12 +34,9 @@ class WorkletsModule(
33
34
  @Suppress("unused")
34
35
  protected fun getHybridData(): HybridData? = mHybridData
35
36
 
36
- init {
37
- reactContext.assertOnJSQueueThread()
38
- }
39
-
40
37
  private val mAndroidUIScheduler = AndroidUIScheduler(reactContext)
41
38
  private val mAnimationFrameQueue = AnimationFrameQueue(reactContext)
39
+ private val mNetworking = Networking()
42
40
  private var mSlowAnimationsEnabled = false
43
41
 
44
42
  /**
@@ -50,38 +48,34 @@ class WorkletsModule(
50
48
 
51
49
  @OptIn(FrameworkAPI::class)
52
50
  private external fun initHybrid(
53
- bundleModeEnabled: Boolean,
54
51
  jsContext: Long,
55
52
  jsCallInvokerHolder: CallInvokerHolderImpl,
56
53
  androidUIScheduler: AndroidUIScheduler,
57
- scriptBufferWrapper: ScriptBufferWrapper?,
54
+ networking: Networking,
58
55
  ): HybridData
59
56
 
60
- @OptIn(FrameworkAPI::class)
61
- @ReactMethod(isBlockingSynchronousMethod = true)
62
- override fun installTurboModule(bundleModeEnabled: Boolean): Boolean {
63
- val context = reactApplicationContext
57
+ private external fun prepareProxyCpp()
64
58
 
65
- context.assertOnJSQueueThread()
59
+ private external fun beginBundleModeAOTCpp()
66
60
 
67
- val jsContext = checkNotNull(context.javaScriptContextHolder).get()
68
- val jsCallInvokerHolder = context.jsCallInvokerHolder as CallInvokerHolderImpl
61
+ private external fun prepareBundleModeAOTCpp()
69
62
 
70
- val scriptBufferWrapper: ScriptBufferWrapper? =
71
- if (bundleModeEnabled) {
72
- ScriptBufferWrapper(context.sourceURL, context)
73
- } else {
74
- null
75
- }
63
+ private external fun installTurboModuleCpp(bundleModeEnabled: Boolean)
64
+
65
+ @OptIn(FrameworkAPI::class)
66
+ @ReactMethod(isBlockingSynchronousMethod = true)
67
+ override fun prepareBundleMode(): Boolean {
68
+ reactApplicationContext.assertOnJSQueueThread()
69
+ beginBundleModeAOTCpp()
70
+ Thread({ prepareBundleModeAOTCpp() }, "WorkletsBundleModePrepare").start()
71
+ return true
72
+ }
76
73
 
77
- mHybridData =
78
- initHybrid(
79
- bundleModeEnabled,
80
- jsContext,
81
- jsCallInvokerHolder,
82
- mAndroidUIScheduler,
83
- scriptBufferWrapper,
84
- )
74
+ @OptIn(FrameworkAPI::class)
75
+ @ReactMethod(isBlockingSynchronousMethod = true)
76
+ override fun installTurboModule(bundleModeEnabled: Boolean): Boolean {
77
+ reactApplicationContext.assertOnJSQueueThread()
78
+ installTurboModuleCpp(bundleModeEnabled)
85
79
  return true
86
80
  }
87
81
 
@@ -102,6 +96,10 @@ class WorkletsModule(
102
96
  @DoNotStrip
103
97
  fun isOnJSQueueThread(): Boolean = reactApplicationContext.isOnJSQueueThread
104
98
 
99
+ /** @noinspection unused */
100
+ @DoNotStrip
101
+ fun createScriptBufferWrapper(): ScriptBufferWrapper = ScriptBufferWrapper(reactApplicationContext.sourceURL, reactApplicationContext)
102
+
105
103
  fun toggleSlowAnimations() {
106
104
  val animationsDragFactor = 10
107
105
  mSlowAnimationsEnabled = !mSlowAnimationsEnabled
@@ -117,6 +115,8 @@ class WorkletsModule(
117
115
 
118
116
  override fun initialize() {
119
117
  reactApplicationContext.addLifecycleEventListener(this)
118
+ createHybrid()
119
+ Thread({ prepareProxyCpp() }, "WorkletsProxyPrepare").start()
120
120
  }
121
121
 
122
122
  override fun invalidate() {
@@ -127,6 +127,7 @@ class WorkletsModule(
127
127
  mInvalidated = true
128
128
  reactApplicationContext.removeLifecycleEventListener(this)
129
129
  }
130
+ mAnimationFrameQueue.invalidate()
130
131
  if (mHybridData != null && mHybridData!!.isValid) {
131
132
  invalidateCpp()
132
133
  }
@@ -156,4 +157,15 @@ class WorkletsModule(
156
157
  }
157
158
 
158
159
  override fun onHostDestroy() {}
160
+
161
+ @OptIn(FrameworkAPI::class)
162
+ private fun createHybrid() {
163
+ val context = reactApplicationContext
164
+ val jsContext =
165
+ checkNotNull(context.javaScriptContextHolder) {
166
+ "[Worklets] JavaScript context is not available yet."
167
+ }.get()
168
+ val jsCallInvokerHolder = context.jsCallInvokerHolder as CallInvokerHolderImpl
169
+ mHybridData = initHybrid(jsContext, jsCallInvokerHolder, mAndroidUIScheduler, mNetworking)
170
+ }
159
171
  }
@@ -0,0 +1,37 @@
1
+ package com.swmansion.worklets.networking
2
+
3
+ import com.facebook.jni.HybridData
4
+ import com.facebook.proguard.annotations.DoNotStrip
5
+
6
+ @DoNotStrip
7
+ @Suppress("KotlinJniMissingFunction")
8
+ class NetworkRequestListener
9
+ @DoNotStrip
10
+ private constructor(
11
+ @field:DoNotStrip private val mHybridData: HybridData,
12
+ ) {
13
+ external fun onResponse(
14
+ status: Int,
15
+ statusText: String,
16
+ headerNames: Array<String>,
17
+ headerValues: Array<String>,
18
+ url: String,
19
+ )
20
+
21
+ external fun onUploadProgress(
22
+ sent: Long,
23
+ total: Long,
24
+ )
25
+
26
+ external fun onDownloadProgress(
27
+ received: Long,
28
+ total: Long,
29
+ )
30
+
31
+ external fun onComplete(body: ByteArray)
32
+
33
+ external fun onError(
34
+ errorCode: Int,
35
+ message: String,
36
+ )
37
+ }
@@ -0,0 +1,244 @@
1
+ package com.swmansion.worklets.networking
2
+
3
+ import com.facebook.proguard.annotations.DoNotStrip
4
+ import com.facebook.react.modules.network.CookieJarContainer
5
+ import com.facebook.react.modules.network.ForwardingCookieHandler
6
+ import com.facebook.react.modules.network.OkHttpClientProvider
7
+ import okhttp3.Call
8
+ import okhttp3.Callback
9
+ import okhttp3.CookieJar
10
+ import okhttp3.JavaNetCookieJar
11
+ import okhttp3.MediaType
12
+ import okhttp3.MediaType.Companion.toMediaTypeOrNull
13
+ import okhttp3.OkHttpClient
14
+ import okhttp3.Request
15
+ import okhttp3.RequestBody
16
+ import okhttp3.Response
17
+ import okio.Buffer
18
+ import okio.BufferedSink
19
+ import okio.ForwardingSink
20
+ import okio.buffer
21
+ import java.io.IOException
22
+ import java.io.InterruptedIOException
23
+ import java.nio.charset.Charset
24
+ import java.util.Collections
25
+ import java.util.concurrent.ConcurrentHashMap
26
+ import java.util.concurrent.TimeUnit
27
+
28
+ class Networking {
29
+ companion object {
30
+ const val ERROR_NETWORK = 0
31
+ const val ERROR_TIMEOUT = 1
32
+ const val ERROR_ABORTED = 2
33
+ private const val PROGRESS_INTERVAL_MS = 50L
34
+ private const val READ_BUFFER_SIZE = 65536L
35
+ private val METHODS_REQUIRING_BODY = setOf("POST", "PUT", "PATCH")
36
+ }
37
+
38
+ private val mClient: OkHttpClient by lazy {
39
+ val client = OkHttpClientProvider.createClient()
40
+ (client.cookieJar as? CookieJarContainer)?.setCookieJar(JavaNetCookieJar(ForwardingCookieHandler()))
41
+ client
42
+ }
43
+ private val mCalls = ConcurrentHashMap<Long, Call>()
44
+ private val mAbortedIds: MutableSet<Long> = Collections.newSetFromMap(ConcurrentHashMap())
45
+
46
+ @DoNotStrip
47
+ @Suppress("TooGenericExceptionCaught")
48
+ fun sendRequest(
49
+ requestIdAsDouble: Double,
50
+ method: String,
51
+ url: String,
52
+ headerNames: Array<String>,
53
+ headerValues: Array<String>,
54
+ body: ByteArray?,
55
+ timeoutMs: Double,
56
+ withCredentials: Boolean,
57
+ listener: NetworkRequestListener,
58
+ ) {
59
+ val requestId = requestIdAsDouble.toLong()
60
+ try {
61
+ val call = buildCall(method, url, headerNames, headerValues, body, timeoutMs, withCredentials, listener)
62
+ mCalls[requestId] = call
63
+ if (mAbortedIds.contains(requestId)) {
64
+ call.cancel()
65
+ }
66
+ call.enqueue(
67
+ object : Callback {
68
+ override fun onFailure(
69
+ call: Call,
70
+ e: IOException,
71
+ ) {
72
+ val code = errorCode(requestId, call, e)
73
+ cleanup(requestId)
74
+ listener.onError(code, e.message ?: e.javaClass.simpleName)
75
+ }
76
+
77
+ override fun onResponse(
78
+ call: Call,
79
+ response: Response,
80
+ ) {
81
+ try {
82
+ response.use { handleResponse(it, listener) }
83
+ } catch (t: Throwable) {
84
+ listener.onError(
85
+ if (t is IOException) errorCode(requestId, call, t) else ERROR_NETWORK,
86
+ t.message ?: t.javaClass.simpleName,
87
+ )
88
+ } finally {
89
+ cleanup(requestId)
90
+ }
91
+ }
92
+ },
93
+ )
94
+ } catch (e: Exception) {
95
+ cleanup(requestId)
96
+ listener.onError(ERROR_NETWORK, e.message ?: e.javaClass.simpleName)
97
+ }
98
+ }
99
+
100
+ @DoNotStrip
101
+ @Suppress("SwallowedException")
102
+ fun decodeText(
103
+ bytes: ByteArray,
104
+ label: String,
105
+ ): String? =
106
+ try {
107
+ String(bytes, Charset.forName(label))
108
+ } catch (e: IllegalArgumentException) {
109
+ null
110
+ }
111
+
112
+ @DoNotStrip
113
+ fun abortRequest(requestIdAsDouble: Double) {
114
+ val requestId = requestIdAsDouble.toLong()
115
+ mAbortedIds.add(requestId)
116
+ mCalls[requestId]?.cancel()
117
+ }
118
+
119
+ @Suppress("LongParameterList")
120
+ private fun buildCall(
121
+ method: String,
122
+ url: String,
123
+ headerNames: Array<String>,
124
+ headerValues: Array<String>,
125
+ body: ByteArray?,
126
+ timeoutMs: Double,
127
+ withCredentials: Boolean,
128
+ listener: NetworkRequestListener,
129
+ ): Call {
130
+ val requestBuilder = Request.Builder().url(url)
131
+ var contentType: MediaType? = null
132
+ for (i in headerNames.indices) {
133
+ requestBuilder.addHeader(headerNames[i], headerValues[i])
134
+ if (headerNames[i].equals("content-type", ignoreCase = true)) {
135
+ contentType = headerValues[i].toMediaTypeOrNull()
136
+ }
137
+ }
138
+ val requestBody =
139
+ when {
140
+ body != null -> ProgressRequestBody(body, contentType, listener)
141
+ method.uppercase() in METHODS_REQUIRING_BODY ->
142
+ ProgressRequestBody(ByteArray(0), contentType, listener)
143
+ else -> null
144
+ }
145
+ requestBuilder.method(method, requestBody)
146
+
147
+ val clientBuilder =
148
+ mClient
149
+ .newBuilder()
150
+ .callTimeout(if (timeoutMs > 0) timeoutMs.toLong() else 0, TimeUnit.MILLISECONDS)
151
+ if (!withCredentials) {
152
+ clientBuilder.cookieJar(CookieJar.NO_COOKIES)
153
+ }
154
+ return clientBuilder.build().newCall(requestBuilder.build())
155
+ }
156
+
157
+ private fun handleResponse(
158
+ response: Response,
159
+ listener: NetworkRequestListener,
160
+ ) {
161
+ val headers = response.headers
162
+ val headerNames = Array(headers.size) { headers.name(it) }
163
+ val headerValues = Array(headers.size) { headers.value(it) }
164
+ listener.onResponse(response.code, response.message, headerNames, headerValues, response.request.url.toString())
165
+
166
+ val responseBody = response.body
167
+ if (responseBody == null) {
168
+ listener.onComplete(ByteArray(0))
169
+ return
170
+ }
171
+
172
+ val contentLength = responseBody.contentLength()
173
+ val source = responseBody.source()
174
+ val output = Buffer()
175
+ var lastProgressAt = 0L
176
+ while (true) {
177
+ val read = source.read(output, READ_BUFFER_SIZE)
178
+ if (read == -1L) {
179
+ break
180
+ }
181
+ val now = System.currentTimeMillis()
182
+ if (now - lastProgressAt >= PROGRESS_INTERVAL_MS) {
183
+ lastProgressAt = now
184
+ listener.onDownloadProgress(output.size, contentLength)
185
+ }
186
+ }
187
+
188
+ listener.onComplete(output.readByteArray())
189
+ }
190
+
191
+ private fun cleanup(requestId: Long) {
192
+ mCalls.remove(requestId)
193
+ mAbortedIds.remove(requestId)
194
+ }
195
+
196
+ private fun errorCode(
197
+ requestId: Long,
198
+ call: Call,
199
+ e: IOException,
200
+ ): Int =
201
+ when {
202
+ mAbortedIds.contains(requestId) -> ERROR_ABORTED
203
+ e is InterruptedIOException -> ERROR_TIMEOUT
204
+ call.isCanceled() -> ERROR_ABORTED
205
+ else -> ERROR_NETWORK
206
+ }
207
+
208
+ private class ProgressRequestBody(
209
+ private val body: ByteArray,
210
+ private val contentType: MediaType?,
211
+ private val listener: NetworkRequestListener,
212
+ ) : RequestBody() {
213
+ override fun contentType(): MediaType? = contentType
214
+
215
+ override fun contentLength(): Long = body.size.toLong()
216
+
217
+ override fun writeTo(sink: BufferedSink) {
218
+ var sent = 0L
219
+ var lastProgressAt = 0L
220
+ val total = body.size.toLong()
221
+ val countingSink =
222
+ object : ForwardingSink(sink) {
223
+ override fun write(
224
+ source: Buffer,
225
+ byteCount: Long,
226
+ ) {
227
+ super.write(source, byteCount)
228
+ sent += byteCount
229
+ val now = System.currentTimeMillis()
230
+ if (sent == total || now - lastProgressAt >= PROGRESS_INTERVAL_MS) {
231
+ lastProgressAt = now
232
+ listener.onUploadProgress(sent, total)
233
+ }
234
+ }
235
+ }
236
+ val bufferedSink = countingSink.buffer()
237
+ bufferedSink.write(body)
238
+ bufferedSink.flush()
239
+ if (sent == 0L) {
240
+ listener.onUploadProgress(0L, 0L)
241
+ }
242
+ }
243
+ }
244
+ }
@@ -25,7 +25,9 @@ class AnimationFrameQueue(
25
25
  }
26
26
  private val mCallbackPosted = AtomicBoolean()
27
27
  private val mPaused = AtomicBoolean()
28
+ private val mInvalidated = AtomicBoolean()
28
29
  private val mFrameCallbacks = mutableListOf<AnimationFrameCallback>()
30
+ private val mDispatchLock = Any()
29
31
 
30
32
  fun resume() {
31
33
  if (mPaused.getAndSet(false)) {
@@ -44,8 +46,21 @@ class AnimationFrameQueue(
44
46
  }
45
47
  }
46
48
 
49
+ fun invalidate() {
50
+ mInvalidated.set(true)
51
+ removePostedFrameCallback()
52
+ synchronized(mDispatchLock) {
53
+ synchronized(mFrameCallbacks) {
54
+ mFrameCallbacks.clear()
55
+ }
56
+ }
57
+ }
58
+
47
59
  fun requestAnimationFrame(animationFrameCallback: AnimationFrameCallback) {
48
60
  synchronized(mFrameCallbacks) {
61
+ if (mInvalidated.get()) {
62
+ return
63
+ }
49
64
  mFrameCallbacks.add(animationFrameCallback)
50
65
  }
51
66
  scheduleQueueExecution()
@@ -64,6 +79,9 @@ class AnimationFrameQueue(
64
79
 
65
80
  private fun scheduleQueueExecution() {
66
81
  synchronized(mPaused) {
82
+ if (mInvalidated.get()) {
83
+ return
84
+ }
67
85
  if (!mPaused.get() && !mCallbackPosted.getAndSet(true)) {
68
86
  mReactChoreographer.postFrameCallback(
69
87
  ReactChoreographer.CallbackType.NATIVE_ANIMATED_MODULE,
@@ -73,6 +91,15 @@ class AnimationFrameQueue(
73
91
  }
74
92
  }
75
93
 
94
+ private fun removePostedFrameCallback() {
95
+ if (mCallbackPosted.getAndSet(false)) {
96
+ mReactChoreographer.removeFrameCallback(
97
+ ReactChoreographer.CallbackType.NATIVE_ANIMATED_MODULE,
98
+ mChoreographerCallback,
99
+ )
100
+ }
101
+ }
102
+
76
103
  private fun executeQueue(frameTimeNanos: Long) {
77
104
  val currentFrameTimeMs = calculateTimestamp(frameTimeNanos)
78
105
  if (currentFrameTimeMs <= lastFrameTimeMs) {
@@ -83,12 +110,20 @@ class AnimationFrameQueue(
83
110
  return
84
111
  }
85
112
 
86
- val frameCallbacks = pullCallbacks()
87
- mCallbackPosted.set(false)
113
+ synchronized(mDispatchLock) {
114
+ val frameCallbacks = pullCallbacks()
115
+ mCallbackPosted.set(false)
116
+ if (mInvalidated.get()) {
117
+ return
118
+ }
88
119
 
89
- lastFrameTimeMs = currentFrameTimeMs
90
- for (callback in frameCallbacks) {
91
- callback.onAnimationFrame(currentFrameTimeMs)
120
+ lastFrameTimeMs = currentFrameTimeMs
121
+ for (callback in frameCallbacks) {
122
+ if (mInvalidated.get()) {
123
+ break
124
+ }
125
+ callback.onAnimationFrame(currentFrameTimeMs)
126
+ }
92
127
  }
93
128
  }
94
129
 
@@ -5,11 +5,17 @@
5
5
  #import <worklets/apple/SlowAnimations.h>
6
6
  #import <chrono>
7
7
 
8
+ #import <Foundation/Foundation.h>
9
+ #if !TARGET_OS_OSX
10
+ #import <UIKit/UIKit.h>
11
+ #endif // !TARGET_OS_OSX
12
+
8
13
  #if TARGET_OS_OSX
9
14
  #import <QuartzCore/CADisplayLink.h>
10
15
  #endif // TARGET_OS_OSX
11
16
 
12
17
  #import <React/RCTAssert.h>
18
+ #import <React/RCTUtils.h>
13
19
 
14
20
  constexpr auto TIME_SAMPLES_AMOUNT = 4;
15
21
 
@@ -36,7 +42,9 @@ typedef void (^AnimationFrameCallback)(WorkletsDisplayLink *displayLink);
36
42
 
37
43
  - (instancetype)init
38
44
  {
39
- AssertJavaScriptQueue();
45
+ react_native_assert(
46
+ (IsJavaScriptQueue() || RCTIsMainQueue()) &&
47
+ "AnimationFrameQueue must be created on the JavaScript queue or the main queue");
40
48
  if constexpr (worklets::StaticFeatureFlags::getFlag("IOS_DYNAMIC_FRAMERATE_ENABLED")) {
41
49
  bool supportsProMotion = false;
42
50
  #if !TARGET_OS_OSX
@@ -1,14 +1,15 @@
1
+ #import <Foundation/Foundation.h>
1
2
  #import <react/debug/react_native_assert.h>
2
3
 
3
4
  // Copied from RCTJSThreadManager.mm
4
5
  static NSString *const RCTJSThreadName = @"com.facebook.react.runtime.JavaScript";
5
6
 
6
- static BOOL IsJavaScriptQueue()
7
+ static inline BOOL IsJavaScriptQueue()
7
8
  {
8
9
  return [NSThread.currentThread.name isEqualToString:RCTJSThreadName];
9
10
  }
10
11
 
11
- static void AssertJavaScriptQueue()
12
+ static inline void AssertJavaScriptQueue()
12
13
  {
13
14
  react_native_assert(IsJavaScriptQueue() && "This function must be called on the JavaScript queue");
14
15
  }
@@ -1,3 +1,7 @@
1
+ #import <dispatch/dispatch.h>
2
+
3
+ #import <cstring>
4
+
1
5
  #import <react/debug/react_native_assert.h>
2
6
 
3
7
  constexpr auto turboModuleManagerQueueLabel = "com.meta.react.turbomodulemanager.queue";
@@ -1,3 +1,6 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <dispatch/dispatch.h>
3
+
1
4
  #import <worklets/apple/IOSUIScheduler.h>
2
5
 
3
6
  namespace worklets {