@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,149 @@
1
+ package com.swmansion.worklets;
2
+
3
+ import androidx.annotation.OptIn;
4
+ import com.facebook.jni.HybridData;
5
+ import com.facebook.proguard.annotations.DoNotStrip;
6
+ import com.facebook.react.bridge.BundleConsumer;
7
+ import com.facebook.react.bridge.LifecycleEventListener;
8
+ import com.facebook.react.bridge.ReactApplicationContext;
9
+ import com.facebook.react.bridge.ReactMethod;
10
+ import com.facebook.react.bridge.queue.MessageQueueThread;
11
+ import com.facebook.react.common.annotations.FrameworkAPI;
12
+ import com.facebook.react.fabric.BigStringBufferWrapper;
13
+ import com.facebook.react.module.annotations.ReactModule;
14
+ import com.facebook.react.turbomodule.core.CallInvokerHolderImpl;
15
+ import com.facebook.soloader.SoLoader;
16
+ import com.swmansion.worklets.runloop.AnimationFrameCallback;
17
+ import com.swmansion.worklets.runloop.AnimationFrameQueue;
18
+ import java.util.Objects;
19
+ import java.util.concurrent.atomic.AtomicBoolean;
20
+
21
+ @SuppressWarnings("JavaJniMissingFunction")
22
+ @ReactModule(name = WorkletsModule.NAME)
23
+ public class WorkletsModule extends NativeWorkletsModuleSpec
24
+ implements LifecycleEventListener, BundleConsumer {
25
+ static {
26
+ SoLoader.loadLibrary("worklets");
27
+ }
28
+
29
+ @DoNotStrip
30
+ @SuppressWarnings("unused")
31
+ private HybridData mHybridData;
32
+
33
+ @SuppressWarnings("unused")
34
+ protected HybridData getHybridData() {
35
+ return mHybridData;
36
+ }
37
+
38
+ private final WorkletsMessageQueueThread mMessageQueueThread = new WorkletsMessageQueueThread();
39
+ private final AndroidUIScheduler mAndroidUIScheduler;
40
+ private final AnimationFrameQueue mAnimationFrameQueue;
41
+ private boolean mSlowAnimationsEnabled;
42
+ private BigStringBufferWrapper mScriptWrapper = null;
43
+ private String mSourceURL = null;
44
+
45
+ @Override
46
+ public void setScriptWrapper(BigStringBufferWrapper scriptWrapper) {
47
+ mScriptWrapper = scriptWrapper;
48
+ }
49
+
50
+ @Override
51
+ public void setSourceURL(String sourceURL) {
52
+ mSourceURL = sourceURL;
53
+ }
54
+
55
+ /**
56
+ * Invalidating concurrently could be fatal. It shouldn't happen in a normal flow, but it doesn't
57
+ * cost us much to add synchronization for extra safety.
58
+ */
59
+ private final AtomicBoolean mInvalidated = new AtomicBoolean(false);
60
+
61
+ @OptIn(markerClass = FrameworkAPI.class)
62
+ private native HybridData initHybrid(
63
+ long jsContext,
64
+ MessageQueueThread messageQueueThread,
65
+ CallInvokerHolderImpl jsCallInvokerHolder,
66
+ AndroidUIScheduler androidUIScheduler,
67
+ BigStringBufferWrapper scriptWrapper,
68
+ String sourceURL);
69
+
70
+ public WorkletsModule(ReactApplicationContext reactContext) {
71
+ super(reactContext);
72
+
73
+ if (!BuildConfig.BUNDLE_MODE) {
74
+ reactContext.assertOnJSQueueThread();
75
+ }
76
+
77
+ mAndroidUIScheduler = new AndroidUIScheduler(reactContext);
78
+ mAnimationFrameQueue = new AnimationFrameQueue(reactContext);
79
+ }
80
+
81
+ @OptIn(markerClass = FrameworkAPI.class)
82
+ @ReactMethod(isBlockingSynchronousMethod = true)
83
+ public boolean installTurboModule() {
84
+ var context = getReactApplicationContext();
85
+
86
+ if (!BuildConfig.BUNDLE_MODE) {
87
+ context.assertOnNativeModulesQueueThread();
88
+ }
89
+
90
+ var jsContext = Objects.requireNonNull(context.getJavaScriptContextHolder()).get();
91
+ var jsCallInvokerHolder = JSCallInvokerResolver.getJSCallInvokerHolder(context);
92
+
93
+ mHybridData =
94
+ initHybrid(
95
+ jsContext,
96
+ mMessageQueueThread,
97
+ jsCallInvokerHolder,
98
+ mAndroidUIScheduler,
99
+ mScriptWrapper,
100
+ mSourceURL);
101
+ return true;
102
+ }
103
+
104
+ public void requestAnimationFrame(AnimationFrameCallback animationFrameCallback) {
105
+ mAnimationFrameQueue.requestAnimationFrame(animationFrameCallback);
106
+ }
107
+
108
+ /**
109
+ * @noinspection unused
110
+ */
111
+ @DoNotStrip
112
+ public boolean isOnJSQueueThread() {
113
+ return getReactApplicationContext().isOnJSQueueThread();
114
+ }
115
+
116
+ public void toggleSlowAnimations() {
117
+ final int ANIMATIONS_DRAG_FACTOR = 10;
118
+ mSlowAnimationsEnabled = !mSlowAnimationsEnabled;
119
+ mAnimationFrameQueue.enableSlowAnimations(mSlowAnimationsEnabled, ANIMATIONS_DRAG_FACTOR);
120
+ }
121
+
122
+ public void invalidate() {
123
+ if (mInvalidated.getAndSet(true)) {
124
+ return;
125
+ }
126
+ if (mHybridData != null && mHybridData.isValid()) {
127
+ // We have to destroy extra runtimes when invalidate is called. If we clean
128
+ // it up later instead there's a chance the runtime will retain references
129
+ // to invalidated memory and will crash on its destruction.
130
+ invalidateCpp();
131
+ }
132
+ mAndroidUIScheduler.deactivate();
133
+ }
134
+
135
+ private native void invalidateCpp();
136
+
137
+ @Override
138
+ public void onHostResume() {
139
+ mAnimationFrameQueue.resume();
140
+ }
141
+
142
+ @Override
143
+ public void onHostPause() {
144
+ mAnimationFrameQueue.pause();
145
+ }
146
+
147
+ @Override
148
+ public void onHostDestroy() {}
149
+ }
@@ -0,0 +1,122 @@
1
+ package com.swmansion.worklets;
2
+
3
+ import androidx.annotation.OptIn;
4
+ import com.facebook.jni.HybridData;
5
+ import com.facebook.proguard.annotations.DoNotStrip;
6
+ import com.facebook.react.bridge.LifecycleEventListener;
7
+ import com.facebook.react.bridge.ReactApplicationContext;
8
+ import com.facebook.react.bridge.ReactMethod;
9
+ import com.facebook.react.bridge.queue.MessageQueueThread;
10
+ import com.facebook.react.common.annotations.FrameworkAPI;
11
+ import com.facebook.react.module.annotations.ReactModule;
12
+ import com.facebook.react.turbomodule.core.CallInvokerHolderImpl;
13
+ import com.facebook.soloader.SoLoader;
14
+ import com.swmansion.worklets.runloop.AnimationFrameCallback;
15
+ import com.swmansion.worklets.runloop.AnimationFrameQueue;
16
+ import java.util.Objects;
17
+ import java.util.concurrent.atomic.AtomicBoolean;
18
+
19
+ @SuppressWarnings("JavaJniMissingFunction")
20
+ @ReactModule(name = WorkletsModule.NAME)
21
+ public class WorkletsModule extends NativeWorkletsModuleSpec implements LifecycleEventListener {
22
+ static {
23
+ SoLoader.loadLibrary("worklets");
24
+ }
25
+
26
+ @DoNotStrip
27
+ @SuppressWarnings("unused")
28
+ private HybridData mHybridData;
29
+
30
+ @SuppressWarnings("unused")
31
+ protected HybridData getHybridData() {
32
+ return mHybridData;
33
+ }
34
+
35
+ private final WorkletsMessageQueueThread mMessageQueueThread = new WorkletsMessageQueueThread();
36
+ private final AndroidUIScheduler mAndroidUIScheduler;
37
+ private final AnimationFrameQueue mAnimationFrameQueue;
38
+ private boolean mSlowAnimationsEnabled;
39
+
40
+ /**
41
+ * Invalidating concurrently could be fatal. It shouldn't happen in a normal flow, but it doesn't
42
+ * cost us much to add synchronization for extra safety.
43
+ */
44
+ private final AtomicBoolean mInvalidated = new AtomicBoolean(false);
45
+
46
+ @OptIn(markerClass = FrameworkAPI.class)
47
+ private native HybridData initHybrid(
48
+ long jsContext,
49
+ MessageQueueThread messageQueueThread,
50
+ CallInvokerHolderImpl jsCallInvokerHolder,
51
+ AndroidUIScheduler androidUIScheduler);
52
+
53
+ public WorkletsModule(ReactApplicationContext reactContext) {
54
+ super(reactContext);
55
+
56
+ reactContext.assertOnJSQueueThread();
57
+
58
+ mAndroidUIScheduler = new AndroidUIScheduler(reactContext);
59
+ mAnimationFrameQueue = new AnimationFrameQueue(reactContext);
60
+ }
61
+
62
+ @OptIn(markerClass = FrameworkAPI.class)
63
+ @ReactMethod(isBlockingSynchronousMethod = true)
64
+ public boolean installTurboModule() {
65
+ var context = getReactApplicationContext();
66
+
67
+ context.assertOnJSQueueThread();
68
+
69
+ var jsContext = Objects.requireNonNull(context.getJavaScriptContextHolder()).get();
70
+ var jsCallInvokerHolder = JSCallInvokerResolver.getJSCallInvokerHolder(context);
71
+
72
+ mHybridData =
73
+ initHybrid(jsContext, mMessageQueueThread, jsCallInvokerHolder, mAndroidUIScheduler);
74
+ return true;
75
+ }
76
+
77
+ public void requestAnimationFrame(AnimationFrameCallback animationFrameCallback) {
78
+ mAnimationFrameQueue.requestAnimationFrame(animationFrameCallback);
79
+ }
80
+
81
+ /**
82
+ * @noinspection unused
83
+ */
84
+ @DoNotStrip
85
+ public boolean isOnJSQueueThread() {
86
+ return getReactApplicationContext().isOnJSQueueThread();
87
+ }
88
+
89
+ public void toggleSlowAnimations() {
90
+ final int ANIMATIONS_DRAG_FACTOR = 10;
91
+ mSlowAnimationsEnabled = !mSlowAnimationsEnabled;
92
+ mAnimationFrameQueue.enableSlowAnimations(mSlowAnimationsEnabled, ANIMATIONS_DRAG_FACTOR);
93
+ }
94
+
95
+ public void invalidate() {
96
+ if (mInvalidated.getAndSet(true)) {
97
+ return;
98
+ }
99
+ if (mHybridData != null && mHybridData.isValid()) {
100
+ // We have to destroy extra runtimes when invalidate is called. If we clean
101
+ // it up later instead there's a chance the runtime will retain references
102
+ // to invalidated memory and will crash on its destruction.
103
+ invalidateCpp();
104
+ }
105
+ mAndroidUIScheduler.deactivate();
106
+ }
107
+
108
+ private native void invalidateCpp();
109
+
110
+ @Override
111
+ public void onHostResume() {
112
+ mAnimationFrameQueue.resume();
113
+ }
114
+
115
+ @Override
116
+ public void onHostPause() {
117
+ mAnimationFrameQueue.pause();
118
+ }
119
+
120
+ @Override
121
+ public void onHostDestroy() {}
122
+ }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,63 @@
1
+ #include <worklets/android/AndroidUIScheduler.h>
2
+
3
+ namespace worklets {
4
+
5
+ using namespace facebook;
6
+ using namespace react;
7
+
8
+ class UISchedulerWrapper : public UIScheduler {
9
+ private:
10
+ jni::global_ref<AndroidUIScheduler::javaobject> androidUiScheduler_;
11
+
12
+ public:
13
+ explicit UISchedulerWrapper(
14
+ jni::global_ref<AndroidUIScheduler::javaobject> androidUiScheduler)
15
+ : androidUiScheduler_(androidUiScheduler) {}
16
+
17
+ void scheduleOnUI(std::function<void()> job) override {
18
+ UIScheduler::scheduleOnUI(job);
19
+ if (!scheduledOnUI_) {
20
+ scheduledOnUI_ = true;
21
+ androidUiScheduler_->cthis()->scheduleTriggerOnUI();
22
+ }
23
+ }
24
+ };
25
+
26
+ AndroidUIScheduler::AndroidUIScheduler(
27
+ jni::alias_ref<AndroidUIScheduler::javaobject> jThis)
28
+ : javaPart_(jni::make_global(jThis)),
29
+ uiScheduler_(
30
+ std::make_shared<UISchedulerWrapper>(jni::make_global(jThis))) {}
31
+
32
+ jni::local_ref<AndroidUIScheduler::jhybriddata> AndroidUIScheduler::initHybrid(
33
+ jni::alias_ref<jhybridobject> jThis) {
34
+ return makeCxxInstance(jThis);
35
+ }
36
+
37
+ void AndroidUIScheduler::triggerUI() {
38
+ if (!uiScheduler_) {
39
+ return;
40
+ }
41
+ uiScheduler_->triggerUI();
42
+ }
43
+
44
+ void AndroidUIScheduler::scheduleTriggerOnUI() {
45
+ static const auto method =
46
+ javaPart_->getClass()->getMethod<void()>("scheduleTriggerOnUI");
47
+ method(javaPart_.get());
48
+ }
49
+
50
+ void AndroidUIScheduler::invalidate() {
51
+ javaPart_ = nullptr;
52
+ uiScheduler_.reset();
53
+ }
54
+
55
+ void AndroidUIScheduler::registerNatives() {
56
+ registerHybrid({
57
+ makeNativeMethod("initHybrid", AndroidUIScheduler::initHybrid),
58
+ makeNativeMethod("triggerUI", AndroidUIScheduler::triggerUI),
59
+ makeNativeMethod("invalidate", AndroidUIScheduler::invalidate),
60
+ });
61
+ }
62
+
63
+ } // namespace worklets
@@ -0,0 +1,43 @@
1
+ #pragma once
2
+
3
+ #include <worklets/Tools/UIScheduler.h>
4
+
5
+ #include <fbjni/fbjni.h>
6
+ #include <jsi/jsi.h>
7
+
8
+ #include <memory>
9
+
10
+ namespace worklets {
11
+
12
+ using namespace facebook;
13
+ using namespace worklets;
14
+
15
+ class AndroidUIScheduler : public jni::HybridClass<AndroidUIScheduler> {
16
+ public:
17
+ static auto constexpr kJavaDescriptor =
18
+ "Lcom/swmansion/worklets/AndroidUIScheduler;";
19
+ static jni::local_ref<jhybriddata> initHybrid(
20
+ jni::alias_ref<jhybridobject> jThis);
21
+ static void registerNatives();
22
+
23
+ std::shared_ptr<UIScheduler> getUIScheduler() {
24
+ return uiScheduler_;
25
+ }
26
+
27
+ void scheduleTriggerOnUI();
28
+
29
+ private:
30
+ friend HybridBase;
31
+
32
+ void triggerUI();
33
+
34
+ void invalidate();
35
+
36
+ jni::global_ref<AndroidUIScheduler::javaobject> javaPart_;
37
+ std::shared_ptr<UIScheduler> uiScheduler_;
38
+
39
+ explicit AndroidUIScheduler(
40
+ jni::alias_ref<AndroidUIScheduler::jhybridobject> jThis);
41
+ };
42
+
43
+ } // namespace worklets
@@ -0,0 +1,34 @@
1
+ #pragma once
2
+
3
+ #include <fbjni/fbjni.h>
4
+
5
+ #include <utility>
6
+
7
+ namespace worklets {
8
+
9
+ class AnimationFrameCallback
10
+ : public facebook::jni::HybridClass<AnimationFrameCallback> {
11
+ public:
12
+ static auto constexpr kJavaDescriptor =
13
+ "Lcom/swmansion/worklets/runloop/AnimationFrameCallback;";
14
+
15
+ void onAnimationFrame(double timestampMs) {
16
+ callback_(timestampMs);
17
+ }
18
+
19
+ static void registerNatives() {
20
+ javaClassStatic()->registerNatives({
21
+ makeNativeMethod(
22
+ "onAnimationFrame", AnimationFrameCallback::onAnimationFrame),
23
+ });
24
+ }
25
+
26
+ private:
27
+ friend HybridBase;
28
+
29
+ explicit AnimationFrameCallback(std::function<void(const double)> callback)
30
+ : callback_(std::move(callback)) {}
31
+
32
+ std::function<void(double)> callback_;
33
+ };
34
+ } // namespace worklets
@@ -0,0 +1,29 @@
1
+ #include <android/log.h>
2
+
3
+ #include <worklets/Tools/PlatformLogger.h>
4
+
5
+ constexpr const auto tag = "Worklets";
6
+
7
+ namespace worklets {
8
+
9
+ void PlatformLogger::log(const char *str) {
10
+ __android_log_print(ANDROID_LOG_VERBOSE, tag, "%s", str);
11
+ }
12
+
13
+ void PlatformLogger::log(const std::string &str) {
14
+ log(str.c_str());
15
+ }
16
+
17
+ void PlatformLogger::log(const double d) {
18
+ __android_log_print(ANDROID_LOG_VERBOSE, tag, "%f", d);
19
+ }
20
+
21
+ void PlatformLogger::log(const int i) {
22
+ __android_log_print(ANDROID_LOG_VERBOSE, tag, "%d", i);
23
+ }
24
+
25
+ void PlatformLogger::log(const bool b) {
26
+ log(b ? "true" : "false");
27
+ }
28
+
29
+ } // namespace worklets
@@ -0,0 +1,115 @@
1
+ #include <worklets/NativeModules/JSIWorkletsModuleProxy.h>
2
+ #include <worklets/Tools/WorkletsJSIUtils.h>
3
+ #include <worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h>
4
+ #include <worklets/android/AnimationFrameCallback.h>
5
+ #include <worklets/android/WorkletsModule.h>
6
+
7
+ #include <memory>
8
+ #include <utility>
9
+
10
+ namespace worklets {
11
+
12
+ using namespace facebook;
13
+ using namespace react;
14
+
15
+ WorkletsModule::WorkletsModule(
16
+ jni::alias_ref<jhybridobject> jThis,
17
+ jsi::Runtime *rnRuntime,
18
+ jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread,
19
+ const std::shared_ptr<facebook::react::CallInvoker> &jsCallInvoker,
20
+ const std::shared_ptr<UIScheduler> &uiScheduler,
21
+ const std::shared_ptr<const BigStringBuffer> &script,
22
+ const std::string &sourceURL)
23
+ : javaPart_(jni::make_global(jThis)),
24
+ rnRuntime_(rnRuntime),
25
+ workletsModuleProxy_(std::make_shared<WorkletsModuleProxy>(
26
+ *rnRuntime,
27
+ std::make_shared<JMessageQueueThread>(messageQueueThread),
28
+ jsCallInvoker,
29
+ uiScheduler,
30
+ getIsOnJSQueueThread(),
31
+ getForwardedRequestAnimationFrame(),
32
+ script,
33
+ sourceURL)) {
34
+ auto jsiWorkletsModuleProxy =
35
+ workletsModuleProxy_->createJSIWorkletsModuleProxy();
36
+ auto optimizedJsiWorkletsModuleProxy = jsi_utils::optimizedFromHostObject(
37
+ *rnRuntime_,
38
+ std::static_pointer_cast<jsi::HostObject>(
39
+ std::move(jsiWorkletsModuleProxy)));
40
+ RNRuntimeWorkletDecorator::decorate(
41
+ *rnRuntime_,
42
+ std::move(optimizedJsiWorkletsModuleProxy),
43
+ workletsModuleProxy_->getJSLogger());
44
+ }
45
+
46
+ jni::local_ref<WorkletsModule::jhybriddata> WorkletsModule::initHybrid(
47
+ jni::alias_ref<jhybridobject> jThis,
48
+ jlong jsContext,
49
+ jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread,
50
+ jni::alias_ref<facebook::react::CallInvokerHolder::javaobject>
51
+ jsCallInvokerHolder,
52
+ jni::alias_ref<worklets::AndroidUIScheduler::javaobject> androidUIScheduler
53
+ #ifdef WORKLETS_BUNDLE_MODE
54
+ ,
55
+ jni::alias_ref<facebook::react::BigStringBufferWrapper::javaobject>
56
+ scriptWrapper,
57
+ const std::string &sourceURL
58
+ #endif // WORKLETS_BUNDLE_MODE
59
+ ) {
60
+ auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker();
61
+ auto rnRuntime = reinterpret_cast<jsi::Runtime *>(jsContext);
62
+ auto uiScheduler = androidUIScheduler->cthis()->getUIScheduler();
63
+
64
+ std::shared_ptr<const BigStringBuffer> script = nullptr;
65
+ #ifdef WORKLETS_BUNDLE_MODE
66
+ script = scriptWrapper->cthis()->getScript();
67
+ #else
68
+ const auto sourceURL = std::string{};
69
+ #endif // WORKLETS_BUNDLE_MODE
70
+
71
+ return makeCxxInstance(
72
+ jThis,
73
+ rnRuntime,
74
+ messageQueueThread,
75
+ jsCallInvoker,
76
+ uiScheduler,
77
+ script,
78
+ sourceURL);
79
+ }
80
+
81
+ std::function<void(std::function<void(const double)>)>
82
+ WorkletsModule::getForwardedRequestAnimationFrame() {
83
+ return [javaPart =
84
+ javaPart_](std::function<void(const double)> &&callback) -> void {
85
+ static const auto jRequestAnimationFrame =
86
+ javaPart->getClass()
87
+ ->getMethod<void(AnimationFrameCallback::javaobject)>(
88
+ "requestAnimationFrame");
89
+ jRequestAnimationFrame(
90
+ javaPart.get(),
91
+ AnimationFrameCallback::newObjectCxxArgs(std::move(callback)).get());
92
+ };
93
+ }
94
+
95
+ std::function<bool()> WorkletsModule::getIsOnJSQueueThread() {
96
+ return [javaPart = javaPart_]() -> bool {
97
+ return javaPart->getClass()
98
+ ->getMethod<jboolean()>("isOnJSQueueThread")
99
+ .operator()(javaPart);
100
+ };
101
+ }
102
+
103
+ void WorkletsModule::invalidateCpp() {
104
+ javaPart_.reset();
105
+ workletsModuleProxy_.reset();
106
+ }
107
+
108
+ void WorkletsModule::registerNatives() {
109
+ registerHybrid({
110
+ makeNativeMethod("initHybrid", WorkletsModule::initHybrid),
111
+ makeNativeMethod("invalidateCpp", WorkletsModule::invalidateCpp),
112
+ });
113
+ }
114
+
115
+ } // namespace worklets
@@ -0,0 +1,78 @@
1
+ #pragma once
2
+
3
+ #include <ReactCommon/CallInvokerHolder.h>
4
+ #include <fbjni/fbjni.h>
5
+ #include <jsi/jsi.h>
6
+ #include <jsireact/JSIExecutor.h>
7
+ #include <react/jni/JMessageQueueThread.h>
8
+ #ifdef WORKLETS_BUNDLE_MODE
9
+ #include <react/fabric/BigStringBufferWrapper.h>
10
+ #endif // WORKLETS_BUNDLE_MODE
11
+
12
+ #include <worklets/NativeModules/WorkletsModuleProxy.h>
13
+ #include <worklets/android/AndroidUIScheduler.h>
14
+
15
+ #include <memory>
16
+ #include <string>
17
+
18
+ namespace worklets {
19
+
20
+ using namespace facebook;
21
+ using namespace facebook::jni;
22
+
23
+ class WorkletsModule : public jni::HybridClass<WorkletsModule> {
24
+ public:
25
+ static auto constexpr kJavaDescriptor =
26
+ "Lcom/swmansion/worklets/WorkletsModule;";
27
+
28
+ static jni::local_ref<jhybriddata> initHybrid(
29
+ jni::alias_ref<jhybridobject> jThis,
30
+ jlong jsContext,
31
+ jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread,
32
+ jni::alias_ref<facebook::react::CallInvokerHolder::javaobject>
33
+ jsCallInvokerHolder,
34
+ jni::alias_ref<worklets::AndroidUIScheduler::javaobject>
35
+ androidUIScheduler
36
+ #ifdef WORKLETS_BUNDLE_MODE
37
+ ,
38
+ jni::alias_ref<facebook::react::BigStringBufferWrapper::javaobject>
39
+ scriptWrapper,
40
+ const std::string &sourceURL
41
+ #endif // WORKLETS_BUNDLE_MODE
42
+ );
43
+
44
+ static void registerNatives();
45
+
46
+ inline std::shared_ptr<WorkletsModuleProxy> getWorkletsModuleProxy() {
47
+ return workletsModuleProxy_;
48
+ }
49
+
50
+ private:
51
+ explicit WorkletsModule(
52
+ jni::alias_ref<jhybridobject> jThis,
53
+ jsi::Runtime *rnRuntime,
54
+ jni::alias_ref<JavaMessageQueueThread::javaobject> messageQueueThread,
55
+ const std::shared_ptr<facebook::react::CallInvoker> &jsCallInvoker,
56
+ const std::shared_ptr<UIScheduler> &uiScheduler,
57
+ const std::shared_ptr<const BigStringBuffer> &script,
58
+ const std::string &sourceURL);
59
+
60
+ void invalidateCpp();
61
+
62
+ template <class Signature>
63
+ JMethod<Signature> getJniMethod(std::string const &methodName) {
64
+ return javaPart_->getClass()->getMethod<Signature>(methodName.c_str());
65
+ }
66
+
67
+ std::function<void(std::function<void(const double)>)>
68
+ getForwardedRequestAnimationFrame();
69
+
70
+ std::function<bool()> getIsOnJSQueueThread();
71
+
72
+ friend HybridBase;
73
+ jni::global_ref<WorkletsModule::javaobject> javaPart_;
74
+ jsi::Runtime *rnRuntime_;
75
+ std::shared_ptr<WorkletsModuleProxy> workletsModuleProxy_;
76
+ };
77
+
78
+ } // namespace worklets
@@ -0,0 +1,13 @@
1
+ #include <fbjni/fbjni.h>
2
+
3
+ #include <worklets/android/AndroidUIScheduler.h>
4
+ #include <worklets/android/AnimationFrameCallback.h>
5
+ #include <worklets/android/WorkletsModule.h>
6
+
7
+ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
8
+ return facebook::jni::initialize(vm, [] {
9
+ worklets::WorkletsModule::registerNatives();
10
+ worklets::AndroidUIScheduler::registerNatives();
11
+ worklets::AnimationFrameCallback::registerNatives();
12
+ });
13
+ }