@amazon-devices/react-native-worklets 1.0.0-rn-83

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 (348) hide show
  1. package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.cpp +71 -0
  2. package/Common/cpp/worklets/AnimationFrameQueue/AnimationFrameBatchinator.h +38 -0
  3. package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.cpp +712 -0
  4. package/Common/cpp/worklets/NativeModules/JSIWorkletsModuleProxy.h +88 -0
  5. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +89 -0
  6. package/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +80 -0
  7. package/Common/cpp/worklets/Public/AsyncQueue.h +14 -0
  8. package/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +94 -0
  9. package/Common/cpp/worklets/Registries/EventHandlerRegistry.h +51 -0
  10. package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +8 -0
  11. package/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +40 -0
  12. package/Common/cpp/worklets/Resources/SynchronizableUnpacker.cpp +49 -0
  13. package/Common/cpp/worklets/Resources/Unpackers.h +6 -0
  14. package/Common/cpp/worklets/Resources/ValueUnpacker.cpp +53 -0
  15. package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.cpp +62 -0
  16. package/Common/cpp/worklets/RunLoop/AsyncQueueImpl.h +46 -0
  17. package/Common/cpp/worklets/RunLoop/EventLoop.cpp +112 -0
  18. package/Common/cpp/worklets/RunLoop/EventLoop.h +52 -0
  19. package/Common/cpp/worklets/SharedItems/Serializable.cpp +545 -0
  20. package/Common/cpp/worklets/SharedItems/Serializable.h +473 -0
  21. package/Common/cpp/worklets/SharedItems/Synchronizable.cpp +67 -0
  22. package/Common/cpp/worklets/SharedItems/Synchronizable.h +59 -0
  23. package/Common/cpp/worklets/SharedItems/SynchronizableAccess.cpp +81 -0
  24. package/Common/cpp/worklets/SharedItems/SynchronizableAccess.h +45 -0
  25. package/Common/cpp/worklets/Tools/Defs.h +10 -0
  26. package/Common/cpp/worklets/Tools/FeatureFlags.cpp +15 -0
  27. package/Common/cpp/worklets/Tools/FeatureFlags.h +44 -0
  28. package/Common/cpp/worklets/Tools/JSISerializer.cpp +342 -0
  29. package/Common/cpp/worklets/Tools/JSISerializer.h +51 -0
  30. package/Common/cpp/worklets/Tools/JSLogger.cpp +68 -0
  31. package/Common/cpp/worklets/Tools/JSLogger.h +37 -0
  32. package/Common/cpp/worklets/Tools/JSScheduler.cpp +24 -0
  33. package/Common/cpp/worklets/Tools/JSScheduler.h +39 -0
  34. package/Common/cpp/worklets/Tools/PlatformLogger.h +16 -0
  35. package/Common/cpp/worklets/Tools/SingleInstanceChecker.h +82 -0
  36. package/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -0
  37. package/Common/cpp/worklets/Tools/UIScheduler.cpp +19 -0
  38. package/Common/cpp/worklets/Tools/UIScheduler.h +26 -0
  39. package/Common/cpp/worklets/Tools/VersionUtils.cpp +75 -0
  40. package/Common/cpp/worklets/Tools/VersionUtils.h +28 -0
  41. package/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +29 -0
  42. package/Common/cpp/worklets/Tools/WorkletEventHandler.h +41 -0
  43. package/Common/cpp/worklets/Tools/WorkletsJSIUtils.cpp +46 -0
  44. package/Common/cpp/worklets/Tools/WorkletsJSIUtils.h +208 -0
  45. package/Common/cpp/worklets/Tools/WorkletsSystraceSection.h +161 -0
  46. package/Common/cpp/worklets/Tools/WorkletsVersion.cpp +54 -0
  47. package/Common/cpp/worklets/Tools/WorkletsVersion.h +20 -0
  48. package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +38 -0
  49. package/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +21 -0
  50. package/Common/cpp/worklets/WorkletRuntime/RuntimeData.cpp +3 -0
  51. package/Common/cpp/worklets/WorkletRuntime/RuntimeData.h +12 -0
  52. package/Common/cpp/worklets/WorkletRuntime/RuntimeInitialization.md +191 -0
  53. package/Common/cpp/worklets/WorkletRuntime/RuntimeKind.h +16 -0
  54. package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp +105 -0
  55. package/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h +63 -0
  56. package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.cpp +23 -0
  57. package/Common/cpp/worklets/WorkletRuntime/UIRuntimeDecorator.h +16 -0
  58. package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.cpp +119 -0
  59. package/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.h +134 -0
  60. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +244 -0
  61. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +102 -0
  62. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -0
  63. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +308 -0
  64. package/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +26 -0
  65. package/LICENSE +7 -0
  66. package/README.md +31 -0
  67. package/RNWorklets.podspec +94 -0
  68. package/SystemBundles/cc12deac6e91c435b76698c8445aed85612f2f88e733218d14f88a35d06fb0f4.bundle +10512 -0
  69. package/SystemBundles/cc12deac6e91c435b76698c8445aed85612f2f88e733218d14f88a35d06fb0f4.map +3771 -0
  70. package/SystemModules/amzn__react-native-worklets-1.modules.txt +39 -0
  71. package/SystemModules/amzn__react-native-worklets-1.private.modules.txt +61 -0
  72. package/SystemModules/keplerscript-system-bundle-config.json +7 -0
  73. package/android/CMakeLists.txt +124 -0
  74. package/android/build.gradle +350 -0
  75. package/android/gradle.properties +5 -0
  76. package/android/proguard-rules.pro +3 -0
  77. package/android/spotless.gradle +9 -0
  78. package/android/src/experimentalBundling/com/swmansion/worklets/WorkletsModule.java +149 -0
  79. package/android/src/legacyBundling/com/swmansion/worklets/WorkletsModule.java +122 -0
  80. package/android/src/main/AndroidManifest.xml +2 -0
  81. package/android/src/main/cpp/worklets/android/AndroidUIScheduler.cpp +63 -0
  82. package/android/src/main/cpp/worklets/android/AndroidUIScheduler.h +43 -0
  83. package/android/src/main/cpp/worklets/android/AnimationFrameCallback.h +34 -0
  84. package/android/src/main/cpp/worklets/android/PlatformLogger.cpp +29 -0
  85. package/android/src/main/cpp/worklets/android/WorkletsModule.cpp +115 -0
  86. package/android/src/main/cpp/worklets/android/WorkletsModule.h +78 -0
  87. package/android/src/main/cpp/worklets/android/WorkletsOnLoad.cpp +13 -0
  88. package/android/src/main/java/com/swmansion/worklets/AndroidUIScheduler.java +60 -0
  89. package/android/src/main/java/com/swmansion/worklets/JSCallInvokerResolver.java +27 -0
  90. package/android/src/main/java/com/swmansion/worklets/WorkletsMessageQueueThread.java +16 -0
  91. package/android/src/main/java/com/swmansion/worklets/WorkletsMessageQueueThreadBase.java +73 -0
  92. package/android/src/main/java/com/swmansion/worklets/WorkletsPackage.java +48 -0
  93. package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameCallback.java +19 -0
  94. package/android/src/main/java/com/swmansion/worklets/runloop/AnimationFrameQueue.java +113 -0
  95. package/apple/worklets/apple/AnimationFrameQueue.h +15 -0
  96. package/apple/worklets/apple/AnimationFrameQueue.mm +135 -0
  97. package/apple/worklets/apple/AssertJavaScriptQueue.h +14 -0
  98. package/apple/worklets/apple/AssertTurboModuleManagerQueue.h +16 -0
  99. package/apple/worklets/apple/IOSUIScheduler.h +15 -0
  100. package/apple/worklets/apple/IOSUIScheduler.mm +29 -0
  101. package/apple/worklets/apple/PlatformLogger.mm +31 -0
  102. package/apple/worklets/apple/SlowAnimations.h +8 -0
  103. package/apple/worklets/apple/SlowAnimations.mm +45 -0
  104. package/apple/worklets/apple/WorkletsDisplayLink.h +21 -0
  105. package/apple/worklets/apple/WorkletsMessageThread.h +16 -0
  106. package/apple/worklets/apple/WorkletsMessageThread.mm +31 -0
  107. package/apple/worklets/apple/WorkletsModule.h +28 -0
  108. package/apple/worklets/apple/WorkletsModule.mm +121 -0
  109. package/bundleMode/index.d.ts +3 -0
  110. package/bundleMode/index.js +59 -0
  111. package/compatibility.json +11 -0
  112. package/kepler-compatibility.json +5 -0
  113. package/kepler-transformed-package-info.json +3 -0
  114. package/lib/module/PlatformChecker/PlatformChecker.js +8 -0
  115. package/lib/module/PlatformChecker/PlatformChecker.js.map +1 -0
  116. package/lib/module/PlatformChecker/index.js +18 -0
  117. package/lib/module/PlatformChecker/index.js.map +1 -0
  118. package/lib/module/WorkletsError.js +29 -0
  119. package/lib/module/WorkletsError.js.map +1 -0
  120. package/lib/module/WorkletsModule/JSWorklets.js +111 -0
  121. package/lib/module/WorkletsModule/JSWorklets.js.map +1 -0
  122. package/lib/module/WorkletsModule/NativeWorklets.js +126 -0
  123. package/lib/module/WorkletsModule/NativeWorklets.js.map +1 -0
  124. package/lib/module/WorkletsModule/index.js +4 -0
  125. package/lib/module/WorkletsModule/index.js.map +1 -0
  126. package/lib/module/WorkletsModule/workletsModuleInstance.js +7 -0
  127. package/lib/module/WorkletsModule/workletsModuleInstance.js.map +1 -0
  128. package/lib/module/WorkletsModule/workletsModuleInstance.web.js +5 -0
  129. package/lib/module/WorkletsModule/workletsModuleInstance.web.js.map +1 -0
  130. package/lib/module/WorkletsModule/workletsModuleProxy.js +4 -0
  131. package/lib/module/WorkletsModule/workletsModuleProxy.js.map +1 -0
  132. package/lib/module/bundleUnpacker.js +47 -0
  133. package/lib/module/bundleUnpacker.js.map +1 -0
  134. package/lib/module/callGuard.js +30 -0
  135. package/lib/module/callGuard.js.map +1 -0
  136. package/lib/module/deprecated.js +20 -0
  137. package/lib/module/deprecated.js.map +1 -0
  138. package/lib/module/errors.js +69 -0
  139. package/lib/module/errors.js.map +1 -0
  140. package/lib/module/featureFlags/index.js +48 -0
  141. package/lib/module/featureFlags/index.js.map +1 -0
  142. package/lib/module/featureFlags/staticFlags.json +4 -0
  143. package/lib/module/index.js +26 -0
  144. package/lib/module/index.js.map +1 -0
  145. package/lib/module/initializers.js +221 -0
  146. package/lib/module/initializers.js.map +1 -0
  147. package/lib/module/isSynchronizable.js +6 -0
  148. package/lib/module/isSynchronizable.js.map +1 -0
  149. package/lib/module/logger.js +15 -0
  150. package/lib/module/logger.js.map +1 -0
  151. package/lib/module/privateGlobals.d.js +7 -0
  152. package/lib/module/privateGlobals.d.js.map +1 -0
  153. package/lib/module/publicGlobals.js +6 -0
  154. package/lib/module/publicGlobals.js.map +1 -0
  155. package/lib/module/runLoop/common/setImmediatePolyfill.js +15 -0
  156. package/lib/module/runLoop/common/setImmediatePolyfill.js.map +1 -0
  157. package/lib/module/runLoop/common/setIntervalPolyfill.js +26 -0
  158. package/lib/module/runLoop/common/setIntervalPolyfill.js.map +1 -0
  159. package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js +10 -0
  160. package/lib/module/runLoop/uiRuntime/mockedRequestAnimationFrame.js.map +1 -0
  161. package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js +52 -0
  162. package/lib/module/runLoop/uiRuntime/requestAnimationFrame.js.map +1 -0
  163. package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js +32 -0
  164. package/lib/module/runLoop/uiRuntime/setTimeoutPolyfill.js.map +1 -0
  165. package/lib/module/runLoop/workletRuntime/index.js +19 -0
  166. package/lib/module/runLoop/workletRuntime/index.js.map +1 -0
  167. package/lib/module/runLoop/workletRuntime/queueMicrotask.js +11 -0
  168. package/lib/module/runLoop/workletRuntime/queueMicrotask.js.map +1 -0
  169. package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js +48 -0
  170. package/lib/module/runLoop/workletRuntime/requestAnimationFramePolyfill.js.map +1 -0
  171. package/lib/module/runLoop/workletRuntime/setTimeout.js +28 -0
  172. package/lib/module/runLoop/workletRuntime/setTimeout.js.map +1 -0
  173. package/lib/module/runLoop/workletRuntime/taskQueue.js +37 -0
  174. package/lib/module/runLoop/workletRuntime/taskQueue.js.map +1 -0
  175. package/lib/module/runtimeKind.js +39 -0
  176. package/lib/module/runtimeKind.js.map +1 -0
  177. package/lib/module/runtimes.js +100 -0
  178. package/lib/module/runtimes.js.map +1 -0
  179. package/lib/module/serializable.js +568 -0
  180. package/lib/module/serializable.js.map +1 -0
  181. package/lib/module/serializableMappingCache.js +37 -0
  182. package/lib/module/serializableMappingCache.js.map +1 -0
  183. package/lib/module/specs/NativeWorkletsModule.js +5 -0
  184. package/lib/module/specs/NativeWorkletsModule.js.map +1 -0
  185. package/lib/module/specs/NativeWorkletsModule.kepler.js +7 -0
  186. package/lib/module/specs/NativeWorkletsModule.kepler.js.map +1 -0
  187. package/lib/module/specs/index.js +10 -0
  188. package/lib/module/specs/index.js.map +1 -0
  189. package/lib/module/synchronizable.js +9 -0
  190. package/lib/module/synchronizable.js.map +1 -0
  191. package/lib/module/synchronizableUnpacker.js +42 -0
  192. package/lib/module/synchronizableUnpacker.js.map +1 -0
  193. package/lib/module/threads.js +347 -0
  194. package/lib/module/threads.js.map +1 -0
  195. package/lib/module/utils/checkCppVersion.js +30 -0
  196. package/lib/module/utils/checkCppVersion.js.map +1 -0
  197. package/lib/module/utils/jsVersion.js +9 -0
  198. package/lib/module/utils/jsVersion.js.map +1 -0
  199. package/lib/module/valueUnpacker.js +60 -0
  200. package/lib/module/valueUnpacker.js.map +1 -0
  201. package/lib/module/workletFunction.js +37 -0
  202. package/lib/module/workletFunction.js.map +1 -0
  203. package/lib/module/workletRuntimeEntry.js +32 -0
  204. package/lib/module/workletRuntimeEntry.js.map +1 -0
  205. package/lib/module/workletTypes.js +12 -0
  206. package/lib/module/workletTypes.js.map +1 -0
  207. package/lib/typescript/PlatformChecker/PlatformChecker.d.ts +5 -0
  208. package/lib/typescript/PlatformChecker/PlatformChecker.d.ts.map +1 -0
  209. package/lib/typescript/PlatformChecker/index.d.ts +10 -0
  210. package/lib/typescript/PlatformChecker/index.d.ts.map +1 -0
  211. package/lib/typescript/WorkletsError.d.ts +15 -0
  212. package/lib/typescript/WorkletsError.d.ts.map +1 -0
  213. package/lib/typescript/WorkletsModule/JSWorklets.d.ts +3 -0
  214. package/lib/typescript/WorkletsModule/JSWorklets.d.ts.map +1 -0
  215. package/lib/typescript/WorkletsModule/NativeWorklets.d.ts +3 -0
  216. package/lib/typescript/WorkletsModule/NativeWorklets.d.ts.map +1 -0
  217. package/lib/typescript/WorkletsModule/index.d.ts +3 -0
  218. package/lib/typescript/WorkletsModule/index.d.ts.map +1 -0
  219. package/lib/typescript/WorkletsModule/workletsModuleInstance.d.ts +2 -0
  220. package/lib/typescript/WorkletsModule/workletsModuleInstance.d.ts.map +1 -0
  221. package/lib/typescript/WorkletsModule/workletsModuleInstance.web.d.ts +2 -0
  222. package/lib/typescript/WorkletsModule/workletsModuleInstance.web.d.ts.map +1 -0
  223. package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts +37 -0
  224. package/lib/typescript/WorkletsModule/workletsModuleProxy.d.ts.map +1 -0
  225. package/lib/typescript/bundleUnpacker.d.ts +7 -0
  226. package/lib/typescript/bundleUnpacker.d.ts.map +1 -0
  227. package/lib/typescript/callGuard.d.ts +4 -0
  228. package/lib/typescript/callGuard.d.ts.map +1 -0
  229. package/lib/typescript/deprecated.d.ts +20 -0
  230. package/lib/typescript/deprecated.d.ts.map +1 -0
  231. package/lib/typescript/errors.d.ts +16 -0
  232. package/lib/typescript/errors.d.ts.map +1 -0
  233. package/lib/typescript/featureFlags/index.d.ts +23 -0
  234. package/lib/typescript/featureFlags/index.d.ts.map +1 -0
  235. package/lib/typescript/index.d.ts +17 -0
  236. package/lib/typescript/index.d.ts.map +1 -0
  237. package/lib/typescript/initializers.d.ts +17 -0
  238. package/lib/typescript/initializers.d.ts.map +1 -0
  239. package/lib/typescript/isSynchronizable.d.ts +3 -0
  240. package/lib/typescript/isSynchronizable.d.ts.map +1 -0
  241. package/lib/typescript/logger.d.ts +5 -0
  242. package/lib/typescript/logger.d.ts.map +1 -0
  243. package/lib/typescript/publicGlobals.d.ts +31 -0
  244. package/lib/typescript/publicGlobals.d.ts.map +1 -0
  245. package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts +2 -0
  246. package/lib/typescript/runLoop/common/setImmediatePolyfill.d.ts.map +1 -0
  247. package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts +2 -0
  248. package/lib/typescript/runLoop/common/setIntervalPolyfill.d.ts.map +1 -0
  249. package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts +6 -0
  250. package/lib/typescript/runLoop/uiRuntime/mockedRequestAnimationFrame.d.ts.map +1 -0
  251. package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts +2 -0
  252. package/lib/typescript/runLoop/uiRuntime/requestAnimationFrame.d.ts.map +1 -0
  253. package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts +2 -0
  254. package/lib/typescript/runLoop/uiRuntime/setTimeoutPolyfill.d.ts.map +1 -0
  255. package/lib/typescript/runLoop/workletRuntime/index.d.ts +2 -0
  256. package/lib/typescript/runLoop/workletRuntime/index.d.ts.map +1 -0
  257. package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts +2 -0
  258. package/lib/typescript/runLoop/workletRuntime/queueMicrotask.d.ts.map +1 -0
  259. package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts +2 -0
  260. package/lib/typescript/runLoop/workletRuntime/requestAnimationFramePolyfill.d.ts.map +1 -0
  261. package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts +2 -0
  262. package/lib/typescript/runLoop/workletRuntime/setTimeout.d.ts.map +1 -0
  263. package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts +10 -0
  264. package/lib/typescript/runLoop/workletRuntime/taskQueue.d.ts.map +1 -0
  265. package/lib/typescript/runtimeKind.d.ts +25 -0
  266. package/lib/typescript/runtimeKind.d.ts.map +1 -0
  267. package/lib/typescript/runtimes.d.ts +77 -0
  268. package/lib/typescript/runtimes.d.ts.map +1 -0
  269. package/lib/typescript/serializable.d.ts +20 -0
  270. package/lib/typescript/serializable.d.ts.map +1 -0
  271. package/lib/typescript/serializableMappingCache.d.ts +16 -0
  272. package/lib/typescript/serializableMappingCache.d.ts.map +1 -0
  273. package/lib/typescript/specs/NativeWorkletsModule.d.ts +7 -0
  274. package/lib/typescript/specs/NativeWorkletsModule.d.ts.map +1 -0
  275. package/lib/typescript/specs/NativeWorkletsModule.kepler.d.ts +7 -0
  276. package/lib/typescript/specs/NativeWorkletsModule.kepler.d.ts.map +1 -0
  277. package/lib/typescript/specs/index.d.ts +3 -0
  278. package/lib/typescript/specs/index.d.ts.map +1 -0
  279. package/lib/typescript/synchronizable.d.ts +15 -0
  280. package/lib/typescript/synchronizable.d.ts.map +1 -0
  281. package/lib/typescript/synchronizableUnpacker.d.ts +4 -0
  282. package/lib/typescript/synchronizableUnpacker.d.ts.map +1 -0
  283. package/lib/typescript/threads.d.ts +138 -0
  284. package/lib/typescript/threads.d.ts.map +1 -0
  285. package/lib/typescript/utils/checkCppVersion.d.ts +3 -0
  286. package/lib/typescript/utils/checkCppVersion.d.ts.map +1 -0
  287. package/lib/typescript/utils/jsVersion.d.ts +7 -0
  288. package/lib/typescript/utils/jsVersion.d.ts.map +1 -0
  289. package/lib/typescript/valueUnpacker.d.ts +6 -0
  290. package/lib/typescript/valueUnpacker.d.ts.map +1 -0
  291. package/lib/typescript/workletFunction.d.ts +27 -0
  292. package/lib/typescript/workletFunction.d.ts.map +1 -0
  293. package/lib/typescript/workletRuntimeEntry.d.ts +14 -0
  294. package/lib/typescript/workletRuntimeEntry.d.ts.map +1 -0
  295. package/lib/typescript/workletTypes.d.ts +61 -0
  296. package/lib/typescript/workletTypes.d.ts.map +1 -0
  297. package/package.json +153 -0
  298. package/plugin/index.js +1761 -0
  299. package/react-native.config.js +21 -0
  300. package/scripts/validate-react-native-version.js +43 -0
  301. package/scripts/worklets_utils.rb +94 -0
  302. package/src/PlatformChecker/PlatformChecker.ts +7 -0
  303. package/src/PlatformChecker/index.ts +30 -0
  304. package/src/WorkletsError.ts +36 -0
  305. package/src/WorkletsModule/JSWorklets.ts +200 -0
  306. package/src/WorkletsModule/NativeWorklets.ts +256 -0
  307. package/src/WorkletsModule/index.ts +7 -0
  308. package/src/WorkletsModule/workletsModuleInstance.ts +9 -0
  309. package/src/WorkletsModule/workletsModuleInstance.web.ts +5 -0
  310. package/src/WorkletsModule/workletsModuleProxy.ts +126 -0
  311. package/src/bundleUnpacker.ts +75 -0
  312. package/src/callGuard.ts +33 -0
  313. package/src/deprecated.ts +32 -0
  314. package/src/errors.ts +80 -0
  315. package/src/featureFlags/index.ts +72 -0
  316. package/src/featureFlags/staticFlags.json +4 -0
  317. package/src/index.ts +53 -0
  318. package/src/initializers.ts +262 -0
  319. package/src/isSynchronizable.ts +13 -0
  320. package/src/logger.ts +16 -0
  321. package/src/privateGlobals.d.ts +79 -0
  322. package/src/publicGlobals.ts +39 -0
  323. package/src/runLoop/common/setImmediatePolyfill.ts +20 -0
  324. package/src/runLoop/common/setIntervalPolyfill.ts +38 -0
  325. package/src/runLoop/uiRuntime/mockedRequestAnimationFrame.ts +11 -0
  326. package/src/runLoop/uiRuntime/requestAnimationFrame.ts +66 -0
  327. package/src/runLoop/uiRuntime/setTimeoutPolyfill.ts +40 -0
  328. package/src/runLoop/workletRuntime/index.ts +18 -0
  329. package/src/runLoop/workletRuntime/queueMicrotask.ts +13 -0
  330. package/src/runLoop/workletRuntime/requestAnimationFramePolyfill.ts +61 -0
  331. package/src/runLoop/workletRuntime/setTimeout.ts +37 -0
  332. package/src/runLoop/workletRuntime/taskQueue.ts +44 -0
  333. package/src/runtimeKind.ts +37 -0
  334. package/src/runtimes.ts +193 -0
  335. package/src/serializable.ts +801 -0
  336. package/src/serializableMappingCache.ts +42 -0
  337. package/src/specs/NativeWorkletsModule.kepler.ts +11 -0
  338. package/src/specs/NativeWorkletsModule.ts +9 -0
  339. package/src/specs/index.ts +13 -0
  340. package/src/synchronizable.ts +32 -0
  341. package/src/synchronizableUnpacker.ts +67 -0
  342. package/src/threads.ts +452 -0
  343. package/src/utils/checkCppVersion.ts +34 -0
  344. package/src/utils/jsVersion.ts +7 -0
  345. package/src/valueUnpacker.ts +90 -0
  346. package/src/workletFunction.ts +42 -0
  347. package/src/workletRuntimeEntry.ts +35 -0
  348. package/src/workletTypes.ts +81 -0
@@ -0,0 +1,88 @@
1
+
2
+ #pragma once
3
+
4
+ #include <cxxreact/MessageQueueThread.h>
5
+ #include <react/renderer/uimanager/UIManagerBinding.h>
6
+ #include <react/renderer/uimanager/primitives.h>
7
+
8
+ #include <worklets/SharedItems/Serializable.h>
9
+ #include <worklets/Tools/Defs.h>
10
+ #include <worklets/WorkletRuntime/RuntimeManager.h>
11
+ #include <worklets/WorkletRuntime/UIRuntimeDecorator.h>
12
+
13
+ #ifdef __ANDROID__
14
+ #include <fbjni/fbjni.h>
15
+ #endif // __ANDROID__
16
+
17
+ #include <jsi/jsi.h>
18
+
19
+ #include <memory>
20
+ #include <string>
21
+ #include <vector>
22
+
23
+ using namespace facebook;
24
+
25
+ namespace worklets {
26
+
27
+ class WorkletRuntime;
28
+
29
+ class JSIWorkletsModuleProxy : public jsi::HostObject {
30
+ public:
31
+ explicit JSIWorkletsModuleProxy(
32
+ const bool isDevBundle,
33
+ const std::shared_ptr<const BigStringBuffer> &script,
34
+ const std::string &sourceUrl,
35
+ const std::shared_ptr<MessageQueueThread> &jsQueue,
36
+ const std::shared_ptr<JSScheduler> &jsScheduler,
37
+ const std::shared_ptr<UIScheduler> &uiScheduler,
38
+ const std::shared_ptr<RuntimeManager> &runtimeManager,
39
+ const std::weak_ptr<WorkletRuntime> &uiWorkletRuntime);
40
+
41
+ JSIWorkletsModuleProxy(const JSIWorkletsModuleProxy &other);
42
+
43
+ ~JSIWorkletsModuleProxy() override;
44
+
45
+ std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
46
+
47
+ jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propName) override;
48
+
49
+ [[nodiscard]] std::shared_ptr<MessageQueueThread> getJSQueue() const {
50
+ return jsQueue_;
51
+ }
52
+
53
+ [[nodiscard]] std::shared_ptr<JSScheduler> getJSScheduler() const {
54
+ return jsScheduler_;
55
+ }
56
+
57
+ [[nodiscard]] std::shared_ptr<UIScheduler> getUIScheduler() const {
58
+ return uiScheduler_;
59
+ }
60
+
61
+ [[nodiscard]] bool isDevBundle() const {
62
+ return isDevBundle_;
63
+ }
64
+
65
+ [[nodiscard]] std::shared_ptr<const BigStringBuffer> getScript() const {
66
+ return script_;
67
+ }
68
+
69
+ [[nodiscard]] std::string getSourceUrl() const {
70
+ return sourceUrl_;
71
+ }
72
+
73
+ [[nodiscard]] std::shared_ptr<RuntimeManager> getRuntimeManager() const {
74
+ return runtimeManager_;
75
+ }
76
+
77
+ private:
78
+ const bool isDevBundle_;
79
+ const std::shared_ptr<const BigStringBuffer> script_;
80
+ const std::string sourceUrl_;
81
+ const std::shared_ptr<MessageQueueThread> jsQueue_;
82
+ const std::shared_ptr<JSScheduler> jsScheduler_;
83
+ const std::shared_ptr<UIScheduler> uiScheduler_;
84
+ const std::shared_ptr<RuntimeManager> runtimeManager_;
85
+ const std::weak_ptr<WorkletRuntime> uiWorkletRuntime_;
86
+ };
87
+
88
+ } // namespace worklets
@@ -0,0 +1,89 @@
1
+ #include <react/renderer/uimanager/UIManagerBinding.h>
2
+ #include <react/renderer/uimanager/primitives.h>
3
+
4
+ #include <worklets/NativeModules/WorkletsModuleProxy.h>
5
+ #include <worklets/RunLoop/AsyncQueueImpl.h>
6
+ #include <worklets/SharedItems/Serializable.h>
7
+ #include <worklets/Tools/Defs.h>
8
+ #include <worklets/WorkletRuntime/UIRuntimeDecorator.h>
9
+
10
+ #ifdef __ANDROID__
11
+ #include <fbjni/fbjni.h>
12
+ #endif // __ANDROID__
13
+
14
+ #include <memory>
15
+ #include <utility>
16
+
17
+ using namespace facebook;
18
+
19
+ namespace worklets {
20
+
21
+ auto isDevBundleFromRNRuntime(jsi::Runtime &rnRuntime) -> bool;
22
+
23
+ WorkletsModuleProxy::WorkletsModuleProxy(
24
+ jsi::Runtime &rnRuntime,
25
+ const std::shared_ptr<MessageQueueThread> &jsQueue,
26
+ const std::shared_ptr<CallInvoker> &jsCallInvoker,
27
+ const std::shared_ptr<UIScheduler> &uiScheduler,
28
+ std::function<bool()> &&isJavaScriptThread,
29
+ std::function<void(std::function<void(const double)>)>
30
+ &&forwardedRequestAnimationFrame,
31
+ const std::shared_ptr<const BigStringBuffer> &script,
32
+ const std::string &sourceUrl)
33
+ : isDevBundle_(isDevBundleFromRNRuntime(rnRuntime)),
34
+ jsQueue_(jsQueue),
35
+ jsScheduler_(std::make_shared<JSScheduler>(
36
+ rnRuntime,
37
+ jsCallInvoker,
38
+ std::move(isJavaScriptThread))),
39
+ uiScheduler_(uiScheduler),
40
+ jsLogger_(std::make_shared<JSLogger>(jsScheduler_)),
41
+ script_(script),
42
+ sourceUrl_(sourceUrl),
43
+ runtimeManager_(std::make_shared<RuntimeManager>()),
44
+ uiWorkletRuntime_(runtimeManager_->createUninitializedUIRuntime(
45
+ jsQueue_,
46
+ std::make_shared<AsyncQueueUI>(uiScheduler_))) {
47
+ /**
48
+ * We call additional `init` method here because
49
+ * JSIWorkletsModuleProxy needs a weak_ptr to the UI Runtime.
50
+ */
51
+ uiWorkletRuntime_->init(createJSIWorkletsModuleProxy());
52
+
53
+ animationFrameBatchinator_ = std::make_shared<AnimationFrameBatchinator>(
54
+ uiWorkletRuntime_->getJSIRuntime(),
55
+ std::move(forwardedRequestAnimationFrame));
56
+
57
+ UIRuntimeDecorator::decorate(
58
+ uiWorkletRuntime_->getJSIRuntime(),
59
+ animationFrameBatchinator_->getJsiRequestAnimationFrame());
60
+ }
61
+
62
+ std::shared_ptr<JSIWorkletsModuleProxy>
63
+ WorkletsModuleProxy::createJSIWorkletsModuleProxy() const {
64
+ assert(
65
+ uiWorkletRuntime_ &&
66
+ "UI Worklet Runtime must be initialized before creating JSI proxy.");
67
+ return std::make_shared<JSIWorkletsModuleProxy>(
68
+ isDevBundle_,
69
+ script_,
70
+ sourceUrl_,
71
+ jsQueue_,
72
+ jsScheduler_,
73
+ uiScheduler_,
74
+ runtimeManager_,
75
+ uiWorkletRuntime_);
76
+ }
77
+
78
+ WorkletsModuleProxy::~WorkletsModuleProxy() {
79
+ animationFrameBatchinator_.reset();
80
+ jsQueue_->quitSynchronous();
81
+ uiWorkletRuntime_.reset();
82
+ }
83
+
84
+ auto isDevBundleFromRNRuntime(jsi::Runtime &rnRuntime) -> bool {
85
+ const auto rtDev = rnRuntime.global().getProperty(rnRuntime, "__DEV__");
86
+ return rtDev.isBool() && rtDev.asBool();
87
+ }
88
+
89
+ } // namespace worklets
@@ -0,0 +1,80 @@
1
+ #pragma once
2
+
3
+ #include <cxxreact/MessageQueueThread.h>
4
+ #include <jsi/jsi.h>
5
+ #include <jsireact/JSIExecutor.h>
6
+ #include <worklets/AnimationFrameQueue/AnimationFrameBatchinator.h>
7
+ #include <worklets/NativeModules/JSIWorkletsModuleProxy.h>
8
+ #include <worklets/Tools/JSLogger.h>
9
+ #include <worklets/Tools/JSScheduler.h>
10
+ #include <worklets/Tools/SingleInstanceChecker.h>
11
+ #include <worklets/Tools/UIScheduler.h>
12
+ #include <worklets/WorkletRuntime/RuntimeManager.h>
13
+ #include <worklets/WorkletRuntime/WorkletRuntime.h>
14
+
15
+ #include <memory>
16
+ #include <string>
17
+
18
+ namespace worklets {
19
+
20
+ class WorkletsModuleProxy
21
+ : public std::enable_shared_from_this<WorkletsModuleProxy> {
22
+ public:
23
+ explicit WorkletsModuleProxy(
24
+ jsi::Runtime &rnRuntime,
25
+ const std::shared_ptr<MessageQueueThread> &jsQueue,
26
+ const std::shared_ptr<CallInvoker> &jsCallInvoker,
27
+ const std::shared_ptr<UIScheduler> &uiScheduler,
28
+ std::function<bool()> &&isJavaScriptQueue,
29
+ std::function<void(std::function<void(const double)>)>
30
+ &&forwardedRequestAnimationFrame,
31
+ const std::shared_ptr<const BigStringBuffer> &script,
32
+ const std::string &sourceUrl);
33
+
34
+ ~WorkletsModuleProxy();
35
+
36
+ [[nodiscard]] inline std::shared_ptr<MessageQueueThread> getJSQueue() const {
37
+ return jsQueue_;
38
+ }
39
+
40
+ [[nodiscard]] inline std::shared_ptr<JSScheduler> getJSScheduler() const {
41
+ return jsScheduler_;
42
+ }
43
+
44
+ [[nodiscard]] inline std::shared_ptr<UIScheduler> getUIScheduler() const {
45
+ return uiScheduler_;
46
+ }
47
+
48
+ [[nodiscard]] inline std::shared_ptr<JSLogger> getJSLogger() const {
49
+ return jsLogger_;
50
+ }
51
+
52
+ [[nodiscard]] inline std::shared_ptr<WorkletRuntime> getUIWorkletRuntime()
53
+ const {
54
+ return uiWorkletRuntime_;
55
+ }
56
+
57
+ [[nodiscard]] std::shared_ptr<JSIWorkletsModuleProxy>
58
+ createJSIWorkletsModuleProxy() const;
59
+
60
+ [[nodiscard]] inline bool isDevBundle() const {
61
+ return isDevBundle_;
62
+ }
63
+
64
+ private:
65
+ const bool isDevBundle_;
66
+ const std::shared_ptr<MessageQueueThread> jsQueue_;
67
+ const std::shared_ptr<JSScheduler> jsScheduler_;
68
+ const std::shared_ptr<UIScheduler> uiScheduler_;
69
+ const std::shared_ptr<JSLogger> jsLogger_;
70
+ const std::shared_ptr<const BigStringBuffer> script_;
71
+ const std::string sourceUrl_;
72
+ const std::shared_ptr<RuntimeManager> runtimeManager_;
73
+ std::shared_ptr<WorkletRuntime> uiWorkletRuntime_;
74
+ std::shared_ptr<AnimationFrameBatchinator> animationFrameBatchinator_;
75
+ #ifndef NDEBUG
76
+ SingleInstanceChecker<WorkletsModuleProxy> singleInstanceChecker_;
77
+ #endif // NDEBUG
78
+ };
79
+
80
+ } // namespace worklets
@@ -0,0 +1,14 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+
5
+ namespace worklets {
6
+
7
+ class AsyncQueue : public facebook::jsi::NativeState {
8
+ public:
9
+ virtual ~AsyncQueue() = default;
10
+
11
+ virtual void push(std::function<void()> &&job) = 0;
12
+ };
13
+
14
+ } // namespace worklets
@@ -0,0 +1,94 @@
1
+ #include <worklets/Registries/EventHandlerRegistry.h>
2
+ #include <worklets/Tools/WorkletEventHandler.h>
3
+
4
+ #include <utility>
5
+ #include <vector>
6
+
7
+ namespace worklets {
8
+
9
+ void EventHandlerRegistry::registerEventHandler(
10
+ const std::shared_ptr<WorkletEventHandler> &eventHandler) {
11
+ const std::lock_guard<std::mutex> lock(instanceMutex);
12
+ const auto &eventName = eventHandler->getEventName();
13
+ auto handlerId = eventHandler->getHandlerId();
14
+
15
+ if (eventHandler->shouldIgnoreEmitterReactTag()) {
16
+ eventMappingsWithoutTag[eventName][handlerId] = eventHandler;
17
+ } else {
18
+ const auto emitterReactTag = eventHandler->getEmitterReactTag();
19
+ const auto eventHash = std::make_pair(emitterReactTag, eventName);
20
+ eventMappingsWithTag[eventHash][handlerId] = eventHandler;
21
+ }
22
+ eventHandlers[handlerId] = eventHandler;
23
+ }
24
+
25
+ void EventHandlerRegistry::unregisterEventHandler(const uint64_t id) {
26
+ const std::lock_guard<std::mutex> lock(instanceMutex);
27
+ auto handlerIt = eventHandlers.find(id);
28
+ if (handlerIt != eventHandlers.end()) {
29
+ const auto &eventHandler = handlerIt->second;
30
+ const auto &eventName = eventHandler->getEventName();
31
+
32
+ if (eventHandler->shouldIgnoreEmitterReactTag()) {
33
+ const auto eventMappingIt = eventMappingsWithoutTag.find(eventName);
34
+ auto &handlersMap = eventMappingIt->second;
35
+ handlersMap.erase(id);
36
+ if (handlersMap.empty()) {
37
+ eventMappingsWithoutTag.erase(eventMappingIt);
38
+ }
39
+ } else {
40
+ const auto emitterReactTag = eventHandler->getEmitterReactTag();
41
+ const auto eventHash = std::make_pair(emitterReactTag, eventName);
42
+ const auto eventMappingIt = eventMappingsWithTag.find(eventHash);
43
+ auto &handlersMap = eventMappingIt->second;
44
+ handlersMap.erase(id);
45
+ if (handlersMap.empty()) {
46
+ eventMappingsWithTag.erase(eventMappingIt);
47
+ }
48
+ }
49
+ eventHandlers.erase(handlerIt);
50
+ }
51
+ }
52
+
53
+ void EventHandlerRegistry::processEvent(
54
+ const std::shared_ptr<WorkletRuntime> &uiWorkletRuntime,
55
+ const double eventTimestamp,
56
+ const std::string &eventName,
57
+ const int emitterReactTag,
58
+ const jsi::Value &eventPayload) {
59
+ std::vector<std::shared_ptr<WorkletEventHandler>> handlersForEvent;
60
+ {
61
+ const std::lock_guard<std::mutex> lock(instanceMutex);
62
+ auto handlersIt = eventMappingsWithoutTag.find(eventName);
63
+ if (handlersIt != eventMappingsWithoutTag.end()) {
64
+ for (auto handler : handlersIt->second) {
65
+ handlersForEvent.push_back(handler.second);
66
+ }
67
+ }
68
+ const auto eventHash = std::make_pair(emitterReactTag, eventName);
69
+ auto handlersWithTagIt = eventMappingsWithTag.find(eventHash);
70
+ if (handlersWithTagIt != eventMappingsWithTag.end()) {
71
+ for (auto handler : handlersWithTagIt->second) {
72
+ handlersForEvent.push_back(handler.second);
73
+ }
74
+ }
75
+ }
76
+
77
+ jsi::Runtime &rt = uiWorkletRuntime->getJSIRuntime();
78
+ eventPayload.asObject(rt).setProperty(
79
+ rt, "eventName", jsi::String::createFromUtf8(rt, eventName));
80
+ for (auto handler : handlersForEvent) {
81
+ handler->process(uiWorkletRuntime, eventTimestamp, eventPayload);
82
+ }
83
+ }
84
+
85
+ bool EventHandlerRegistry::isAnyHandlerWaitingForEvent(
86
+ const std::string &eventName,
87
+ const int emitterReactTag) {
88
+ const std::lock_guard<std::mutex> lock(instanceMutex);
89
+ const auto eventHash = std::make_pair(emitterReactTag, eventName);
90
+ auto it = eventMappingsWithTag.find(eventHash);
91
+ return it != eventMappingsWithTag.end() && !it->second.empty();
92
+ }
93
+
94
+ } // namespace worklets
@@ -0,0 +1,51 @@
1
+ #pragma once
2
+
3
+ #include <keplerui-083/keplerscript-export.h>
4
+
5
+ #include <worklets/WorkletRuntime/WorkletRuntime.h>
6
+
7
+ #include <jsi/jsi.h>
8
+
9
+ #include <map>
10
+ #include <memory>
11
+ #include <mutex>
12
+ #include <string>
13
+ #include <unordered_map>
14
+ #include <utility>
15
+
16
+ using namespace facebook;
17
+
18
+ namespace worklets {
19
+
20
+ class WorkletEventHandler;
21
+
22
+ class KEPLERSCRIPT_EXPORT EventHandlerRegistry {
23
+ std::map<
24
+ std::pair<int, std::string>,
25
+ std::unordered_map<uint64_t, std::shared_ptr<WorkletEventHandler>>>
26
+ eventMappingsWithTag;
27
+ std::map<
28
+ std::string,
29
+ std::unordered_map<uint64_t, std::shared_ptr<WorkletEventHandler>>>
30
+ eventMappingsWithoutTag;
31
+ std::map<uint64_t, std::shared_ptr<WorkletEventHandler>> eventHandlers;
32
+ std::mutex instanceMutex;
33
+
34
+ public:
35
+ void registerEventHandler(
36
+ const std::shared_ptr<WorkletEventHandler> &eventHandler);
37
+ void unregisterEventHandler(const uint64_t id);
38
+
39
+ void processEvent(
40
+ const std::shared_ptr<WorkletRuntime> &uiWorkletRuntime,
41
+ const double eventTimestamp,
42
+ const std::string &eventName,
43
+ const int emitterReactTag,
44
+ const jsi::Value &eventPayload);
45
+
46
+ bool isAnyHandlerWaitingForEvent(
47
+ const std::string &eventName,
48
+ const int emitterReactTag);
49
+ };
50
+
51
+ } // namespace worklets
@@ -0,0 +1,8 @@
1
+ #include <worklets/Registries/WorkletRuntimeRegistry.h>
2
+
3
+ namespace worklets {
4
+
5
+ std::set<jsi::Runtime *> WorkletRuntimeRegistry::registry_{};
6
+ std::mutex WorkletRuntimeRegistry::mutex_{};
7
+
8
+ } // namespace worklets
@@ -0,0 +1,40 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <react/debug/react_native_assert.h>
5
+
6
+ #include <mutex>
7
+ #include <set>
8
+
9
+ using namespace facebook;
10
+
11
+ namespace worklets {
12
+
13
+ class WorkletRuntimeRegistry {
14
+ private:
15
+ static std::set<jsi::Runtime *> registry_;
16
+ static std::mutex mutex_; // Protects `registry_`.
17
+
18
+ WorkletRuntimeRegistry() {} // private ctor
19
+
20
+ static void registerRuntime(jsi::Runtime &runtime) {
21
+ std::lock_guard<std::mutex> lock(mutex_);
22
+ registry_.insert(&runtime);
23
+ }
24
+
25
+ static void unregisterRuntime(jsi::Runtime &runtime) {
26
+ std::lock_guard<std::mutex> lock(mutex_);
27
+ registry_.erase(&runtime);
28
+ }
29
+
30
+ friend class WorkletRuntimeCollector;
31
+
32
+ public:
33
+ static bool isRuntimeAlive(jsi::Runtime *runtime) {
34
+ react_native_assert(runtime != nullptr && "runtime is nullptr");
35
+ std::lock_guard<std::mutex> lock(mutex_);
36
+ return registry_.find(runtime) != registry_.end();
37
+ }
38
+ };
39
+
40
+ } // namespace worklets
@@ -0,0 +1,49 @@
1
+ // This file was generated with
2
+ // `packages/react-native-worklets/scripts/export-unpackers.js`.
3
+ // Please do not modify it directly.
4
+
5
+ #include <worklets/Resources/Unpackers.h>
6
+
7
+ namespace worklets {
8
+
9
+ const char SynchronizableUnpackerCode[] =
10
+ R"DELIMITER__((function () {
11
+ var serializer = !globalThis._WORKLET || globalThis._WORKLETS_BUNDLE_MODE ? function (value, _) {
12
+ return (0, _serializable.createSerializable)(value);
13
+ } : globalThis._createSerializable;
14
+ function synchronizableUnpacker(synchronizableRef) {
15
+ var synchronizable = synchronizableRef;
16
+ var proxy = globalThis.__workletsModuleProxy;
17
+ synchronizable.__synchronizableRef = true;
18
+ synchronizable.getDirty = function () {
19
+ return proxy.synchronizableGetDirty(synchronizable);
20
+ };
21
+ synchronizable.getBlocking = function () {
22
+ return proxy.synchronizableGetBlocking(synchronizable);
23
+ };
24
+ synchronizable.setBlocking = function (valueOrFunction) {
25
+ var newValue;
26
+ if (typeof valueOrFunction === 'function') {
27
+ var func = valueOrFunction;
28
+ synchronizable.lock();
29
+ var prev = synchronizable.getBlocking();
30
+ newValue = func(prev);
31
+ proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, undefined));
32
+ synchronizable.unlock();
33
+ } else {
34
+ var value = valueOrFunction;
35
+ newValue = value;
36
+ proxy.synchronizableSetBlocking(synchronizable, serializer(newValue, undefined));
37
+ }
38
+ };
39
+ synchronizable.lock = function () {
40
+ proxy.synchronizableLock(synchronizable);
41
+ };
42
+ synchronizable.unlock = function () {
43
+ proxy.synchronizableUnlock(synchronizable);
44
+ };
45
+ return synchronizable;
46
+ }
47
+ globalThis.__synchronizableUnpacker = synchronizableUnpacker;
48
+ })();)DELIMITER__";
49
+ } // namespace worklets
@@ -0,0 +1,6 @@
1
+ #pragma once
2
+
3
+ namespace worklets {
4
+ extern const char ValueUnpackerCode[];
5
+ extern const char SynchronizableUnpackerCode[];
6
+ } // namespace worklets
@@ -0,0 +1,53 @@
1
+ // This file was generated with
2
+ // `packages/react-native-worklets/scripts/export-unpackers.js`.
3
+ // Please do not modify it directly.
4
+
5
+ #include <worklets/Resources/Unpackers.h>
6
+
7
+ namespace worklets {
8
+
9
+ const char ValueUnpackerCode[] =
10
+ R"DELIMITER__((function () {
11
+ var workletsCache = new Map();
12
+ var handleCache = new WeakMap();
13
+ function valueUnpacker(objectToUnpack, category, remoteFunctionName) {
14
+ 'use strict';
15
+
16
+ var workletHash = objectToUnpack.__workletHash;
17
+ if (workletHash !== undefined) {
18
+ var workletFun = workletsCache.get(workletHash);
19
+ if (workletFun === undefined) {
20
+ var initData = objectToUnpack.__initData;
21
+ if (globalThis.evalWithSourceMap) {
22
+ workletFun = globalThis.evalWithSourceMap('(' + initData.code + '\n)', initData.location, initData.sourceMap);
23
+ } else if (globalThis.evalWithSourceUrl) {
24
+ workletFun = globalThis.evalWithSourceUrl('(' + initData.code + '\n)', "worklet_".concat(workletHash));
25
+ } else {
26
+ workletFun = eval('(' + initData.code + '\n)');
27
+ }
28
+ workletsCache.set(workletHash, workletFun);
29
+ }
30
+ var functionInstance = workletFun.bind(objectToUnpack);
31
+ objectToUnpack._recur = functionInstance;
32
+ return functionInstance;
33
+ } else if (objectToUnpack.__init !== undefined) {
34
+ var value = handleCache.get(objectToUnpack);
35
+ if (value === undefined) {
36
+ value = objectToUnpack.__init();
37
+ handleCache.set(objectToUnpack, value);
38
+ }
39
+ return value;
40
+ } else if (category === 'RemoteFunction') {
41
+ var fun = function fun() {
42
+ var label = remoteFunctionName ? "function `".concat(remoteFunctionName, "`") : 'anonymous function';
43
+ throw new Error("[Worklets] Tried to synchronously call a non-worklet ".concat(label, " on the UI thread.\nSee https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-synchronously-call-a-non-worklet-function-on-the-ui-thread for more details."));
44
+ };
45
+ fun.__remoteFunction = objectToUnpack;
46
+ return fun;
47
+ } else {
48
+ throw new Error("[Worklets] Data type in category \"".concat(category, "\" not recognized by value unpacker: \"").concat(globalThis._toString(objectToUnpack), "\"."));
49
+ }
50
+ }
51
+ globalThis.__valueUnpacker = valueUnpacker;
52
+ })();)DELIMITER__";
53
+ } // namespace worklets
@@ -0,0 +1,62 @@
1
+ #include <worklets/RunLoop/AsyncQueueImpl.h>
2
+
3
+ #include <thread>
4
+ #include <utility>
5
+
6
+ namespace worklets {
7
+
8
+ AsyncQueueImpl::AsyncQueueImpl(std::string name)
9
+ : state_(std::make_shared<AsyncQueueState>()) {
10
+ auto thread = std::thread([name, state = state_] {
11
+ // amzn_mod - include check for VOLTA_DARWIN
12
+ #if __APPLE__ || defined(VOLTA_DARWIN)
13
+ pthread_setname_np(name.c_str());
14
+ #endif // __APPLE__ || VOLTA_DARWIN
15
+ while (state->running) {
16
+ std::unique_lock<std::mutex> lock(state->mutex);
17
+ state->cv.wait(
18
+ lock, [state] { return !state->queue.empty() || !state->running; });
19
+ if (!state->running) {
20
+ return;
21
+ }
22
+ if (state->queue.empty()) {
23
+ continue;
24
+ }
25
+ auto job = std::move(state->queue.front());
26
+ state->queue.pop();
27
+ lock.unlock();
28
+ job();
29
+ }
30
+ });
31
+ // amzn_mod - exclude VOLTA_DARWIN
32
+ #if defined(ANDROID) && not defined(VOLTA_DARWIN)
33
+ pthread_setname_np(thread.native_handle(), name.c_str());
34
+ #endif // ANDROID && !VOLTA_DARWIN
35
+ thread.detach();
36
+ }
37
+
38
+ AsyncQueueImpl::~AsyncQueueImpl() {
39
+ {
40
+ std::unique_lock<std::mutex> lock(state_->mutex);
41
+ state_->running = false;
42
+ state_->queue = {};
43
+ }
44
+ state_->cv.notify_all();
45
+ }
46
+
47
+ void AsyncQueueImpl::push(std::function<void()> &&job) {
48
+ {
49
+ std::unique_lock<std::mutex> lock(state_->mutex);
50
+ state_->queue.emplace(job);
51
+ }
52
+ state_->cv.notify_one();
53
+ }
54
+
55
+ AsyncQueueUI::AsyncQueueUI(const std::shared_ptr<UIScheduler> &uiScheduler)
56
+ : uiScheduler_(uiScheduler) {}
57
+
58
+ void AsyncQueueUI::push(std::function<void()> &&job) {
59
+ uiScheduler_->scheduleOnUI(std::move(job));
60
+ }
61
+
62
+ } // namespace worklets
@@ -0,0 +1,46 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <worklets/Public/AsyncQueue.h>
5
+ #include <worklets/Tools/UIScheduler.h>
6
+
7
+ #include <atomic>
8
+ #include <condition_variable>
9
+ #include <memory>
10
+ #include <queue>
11
+ #include <string>
12
+
13
+ namespace worklets {
14
+
15
+ struct AsyncQueueState {
16
+ std::atomic_bool running{true};
17
+ std::mutex mutex;
18
+ std::condition_variable cv;
19
+ std::queue<std::function<void()>> queue;
20
+ };
21
+
22
+ class AsyncQueueImpl : public AsyncQueue {
23
+ public:
24
+ explicit AsyncQueueImpl(std::string name);
25
+
26
+ ~AsyncQueueImpl() override;
27
+
28
+ void push(std::function<void()> &&job) override;
29
+
30
+ private:
31
+ const std::shared_ptr<AsyncQueueState> state_;
32
+ };
33
+
34
+ class AsyncQueueUI : public AsyncQueue {
35
+ public:
36
+ explicit AsyncQueueUI(const std::shared_ptr<UIScheduler> &uiScheduler);
37
+
38
+ ~AsyncQueueUI() override = default;
39
+
40
+ void push(std::function<void()> &&job) override;
41
+
42
+ private:
43
+ std::shared_ptr<UIScheduler> uiScheduler_;
44
+ };
45
+
46
+ } // namespace worklets