@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,161 @@
1
+ #pragma once
2
+ #include <string>
3
+ #include <vector>
4
+
5
+ #ifdef WORKLETS_PROFILING
6
+
7
+ #if defined(__APPLE__)
8
+ #include <os/trace_base.h>
9
+
10
+ #if OS_LOG_TARGET_HAS_10_15_FEATURES
11
+ #include <os/log.h>
12
+ #include <os/signpost.h>
13
+ #include <sstream>
14
+ #endif // OS_LOG_TARGET_HAS_10_15_FEATURES
15
+
16
+ // amznmod_react - add support for tracing on Vega
17
+ #elif defined(KEPLER)
18
+
19
+ #include <Volta/trace/Tracing.h>
20
+
21
+ #elif defined(ANDROID)
22
+
23
+ #include <android/trace.h>
24
+
25
+ #endif // defined(ANDROID)
26
+
27
+ #endif // WORKLETS_PROFILING
28
+
29
+ namespace worklets {
30
+
31
+ #if defined(ANDROID) && defined(WORKLETS_PROFILING)
32
+
33
+ // avg 6.10 min 2.87 max 7.68 dev 0.42
34
+ // avg 6.09 min 3.29 max 8.62 dev 0.50
35
+
36
+ struct WorkletsSystraceSection {
37
+ public:
38
+ template <typename... ConvertsToStringPiece>
39
+ explicit WorkletsSystraceSection(
40
+ const char *name,
41
+ ConvertsToStringPiece &&...args) {
42
+ ATrace_beginSection(name);
43
+ }
44
+
45
+ ~WorkletsSystraceSection() {
46
+ ATrace_endSection();
47
+ }
48
+ };
49
+
50
+ // The apple part is copied from React Native
51
+ // from
52
+ // https://github.com/facebook/react-native/blob/5697d923a05119314b4cfcd556cb243986637764/packages/react-native/ReactCommon/cxxreact/SystraceSection.h
53
+ #elif defined(__APPLE__) && OS_LOG_TARGET_HAS_10_15_FEATURES && \
54
+ defined(WORKLETS_PROFILING)
55
+
56
+ template <typename T, typename = void>
57
+ struct renderer {
58
+ static std::string render(const T &t) {
59
+ std::ostringstream oss;
60
+ oss << t;
61
+ return oss.str();
62
+ }
63
+ };
64
+
65
+ template <typename T>
66
+ static auto render(const T &t)
67
+ -> decltype(renderer<T>::render(std::declval<const T &>())) {
68
+ return renderer<T>::render(t);
69
+ }
70
+
71
+ inline os_log_t instrumentsLogHandle = nullptr;
72
+
73
+ static inline os_log_t getOrCreateInstrumentsLogHandle() {
74
+ if (!instrumentsLogHandle) {
75
+ instrumentsLogHandle = os_log_create(
76
+ "dev.worklets.instruments", OS_LOG_CATEGORY_POINTS_OF_INTEREST);
77
+ }
78
+ return instrumentsLogHandle;
79
+ }
80
+
81
+ struct WorkletsSystraceSection {
82
+ public:
83
+ template <typename... ConvertsToStringPiece>
84
+ explicit WorkletsSystraceSection(
85
+ const char *name,
86
+ ConvertsToStringPiece &&...args) {
87
+ os_log_t instrumentsLogHandle = worklets::getOrCreateInstrumentsLogHandle();
88
+
89
+ // If the log isn't enabled, we don't want the performance overhead of the
90
+ // rest of the code below.
91
+ if (!os_signpost_enabled(instrumentsLogHandle)) {
92
+ return;
93
+ }
94
+
95
+ name_ = name;
96
+
97
+ const auto argsVector = std::vector<std::string>{worklets::render(args)...};
98
+ std::string argsString = "";
99
+ for (size_t i = 0; i < argsVector.size(); i += 2) {
100
+ argsString += argsVector[i] + "=" + argsVector[i + 1] + ";";
101
+ }
102
+
103
+ signpostID_ = os_signpost_id_make_with_pointer(instrumentsLogHandle, this);
104
+
105
+ os_signpost_interval_begin(
106
+ instrumentsLogHandle,
107
+ signpostID_,
108
+ "Worklets",
109
+ "%s begin: %s",
110
+ name,
111
+ argsString.c_str());
112
+ }
113
+
114
+ ~WorkletsSystraceSection() {
115
+ os_signpost_interval_end(
116
+ worklets::instrumentsLogHandle,
117
+ signpostID_,
118
+ "Worklets",
119
+ "%s end",
120
+ name_.data());
121
+ }
122
+
123
+ private:
124
+ os_signpost_id_t signpostID_ = OS_SIGNPOST_ID_INVALID;
125
+ std::string_view name_;
126
+ };
127
+
128
+ // amznmod_react - add support for tracing on Vega
129
+ #elif defined(KEPLER) and defined(WORKLETS_PROFILING) && not defined(VOLTA_DARWIN)
130
+
131
+ struct WorkletsSystraceSection {
132
+ public:
133
+ template <typename... ConvertsToStringPiece>
134
+ explicit WorkletsSystraceSection(
135
+ const char *name,
136
+ ConvertsToStringPiece &&...args) {
137
+ name_ = name;
138
+ VOLTA_TRACE_BEGIN_STR(name_.data());
139
+ }
140
+
141
+ ~WorkletsSystraceSection() {
142
+ VOLTA_TRACE_END_STR(name_.data());
143
+ }
144
+ private:
145
+ std::string_view name_;
146
+ };
147
+
148
+ #else
149
+
150
+ struct WorkletsSystraceSection {
151
+ public:
152
+ template <typename... ConvertsToStringPiece>
153
+ explicit WorkletsSystraceSection(
154
+ const char *name,
155
+ ConvertsToStringPiece &&...args) {}
156
+ };
157
+
158
+ #endif // defined(__APPLE__) && OS_LOG_TARGET_HAS_10_15_FEATURES &&
159
+ // defined(WORKLETS_PROFILING)
160
+
161
+ } // namespace worklets
@@ -0,0 +1,54 @@
1
+ #include <worklets/Tools/JSLogger.h>
2
+ #include <worklets/Tools/VersionUtils.h>
3
+ #include <worklets/Tools/WorkletsVersion.h>
4
+
5
+ #include <memory>
6
+ #include <string>
7
+
8
+ #ifdef WORKLETS_VERSION
9
+ #define STRINGIZE(x) #x
10
+ #define STRINGIZE2(x) STRINGIZE(x)
11
+ #define WORKLETS_VERSION_STRING STRINGIZE2(WORKLETS_VERSION)
12
+ #endif // WORKLETS_VERSION
13
+
14
+ using namespace facebook;
15
+
16
+ namespace worklets {
17
+
18
+ std::string getWorkletsCppVersion() {
19
+ return std::string(WORKLETS_VERSION_STRING);
20
+ }
21
+
22
+ void injectWorkletsCppVersion(jsi::Runtime &rnRuntime) {
23
+ auto version = getWorkletsCppVersion();
24
+ rnRuntime.global().setProperty(
25
+ rnRuntime,
26
+ "_WORKLETS_VERSION_CPP",
27
+ jsi::String::createFromUtf8(rnRuntime, version));
28
+ }
29
+
30
+ #ifndef NDEBUG
31
+ void checkJSVersion(
32
+ jsi::Runtime &rnRuntime,
33
+ const std::shared_ptr<worklets::JSLogger> &jsLogger) {
34
+ auto cppVersion = getWorkletsCppVersion();
35
+ auto jsVersionValue =
36
+ rnRuntime.global().getProperty(rnRuntime, "_WORKLETS_VERSION_JS");
37
+ worklets::checkJSVersion(
38
+ rnRuntime,
39
+ jsVersionValue,
40
+ jsLogger,
41
+ cppVersion,
42
+ "Worklets",
43
+ "https://docs.swmansion.com/react-native-worklets/docs");
44
+ }
45
+ #else
46
+ void checkJSVersion(
47
+ jsi::Runtime &rnRuntime,
48
+ const std::shared_ptr<worklets::JSLogger> &jsLogger) {
49
+ // In release builds we don't check the version, hence
50
+ // this function is a NOOP.
51
+ }
52
+ #endif // NDEBUG
53
+
54
+ }; // namespace worklets
@@ -0,0 +1,20 @@
1
+ #pragma once
2
+
3
+ #include <worklets/Tools/JSLogger.h>
4
+
5
+ #include <jsi/jsi.h>
6
+
7
+ #include <memory>
8
+ #include <string>
9
+
10
+ using namespace facebook;
11
+
12
+ namespace worklets {
13
+
14
+ std::string getWorkletsCppVersion();
15
+ void injectWorkletsCppVersion(jsi::Runtime &);
16
+ void checkJSVersion(
17
+ jsi::Runtime &,
18
+ const std::shared_ptr<worklets::JSLogger> &);
19
+
20
+ }; // namespace worklets
@@ -0,0 +1,38 @@
1
+ #include <worklets/Tools/WorkletsVersion.h>
2
+ #include <worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h>
3
+ #include <worklets/WorkletRuntime/RuntimeKind.h>
4
+ #include <worklets/WorkletRuntime/WorkletRuntimeCollector.h>
5
+ #include <memory>
6
+
7
+ #include <utility>
8
+
9
+ namespace worklets {
10
+
11
+ void RNRuntimeWorkletDecorator::decorate(
12
+ jsi::Runtime &rnRuntime,
13
+ jsi::Object &&jsiWorkletsModuleProxy,
14
+ const std::shared_ptr<JSLogger> &jsLogger) {
15
+ rnRuntime.global().setProperty(
16
+ rnRuntime,
17
+ runtimeKindBindingName,
18
+ static_cast<int>(RuntimeKind::ReactNative));
19
+
20
+ rnRuntime.global().setProperty(rnRuntime, "_WORKLET", false);
21
+
22
+ // TODO: Remove _IS_FABRIC sometime in the future
23
+ // react-native-screens 4.9.0 depends on it
24
+ rnRuntime.global().setProperty(rnRuntime, "_IS_FABRIC", true);
25
+
26
+ rnRuntime.global().setProperty(
27
+ rnRuntime, "__workletsModuleProxy", std::move(jsiWorkletsModuleProxy));
28
+
29
+ WorkletRuntimeCollector::install(rnRuntime);
30
+
31
+ #ifndef NDEBUG
32
+ checkJSVersion(rnRuntime, jsLogger);
33
+ #endif // NDEBUG
34
+
35
+ injectWorkletsCppVersion(rnRuntime);
36
+ }
37
+
38
+ } // namespace worklets
@@ -0,0 +1,21 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <worklets/NativeModules/WorkletsModuleProxy.h>
5
+ #include <worklets/Tools/JSLogger.h>
6
+ #include <memory>
7
+
8
+ using namespace facebook;
9
+
10
+ namespace worklets {
11
+
12
+ class RNRuntimeWorkletDecorator {
13
+ // TODO: Rename to `RNRuntimeWorkletsDecorator` or something more suitable.
14
+ public:
15
+ static void decorate(
16
+ jsi::Runtime &rnRuntime,
17
+ jsi::Object &&jsiWorkletsModuleProxy,
18
+ const std::shared_ptr<JSLogger> &jsLogger);
19
+ };
20
+
21
+ } // namespace worklets
@@ -0,0 +1,3 @@
1
+ #include <worklets/WorkletRuntime/RuntimeData.h>
2
+
3
+ const std::string uiRuntimeName{"UI"};
@@ -0,0 +1,12 @@
1
+ #pragma once
2
+
3
+ // amznmod_react - fix compilation issues
4
+ #include <cstdint>
5
+ #include <string>
6
+
7
+ /**
8
+ * Unused, but kept for possible future use.
9
+ */
10
+ constexpr uint64_t rnRuntimeId{0};
11
+ constexpr uint64_t uiRuntimeId{1};
12
+ extern const std::string uiRuntimeName;
@@ -0,0 +1,191 @@
1
+ # Hermes Runtime initialization
2
+
3
+ _Last updated_: 13/09/2022 by @Kwasow
4
+
5
+ This document describes the current way of initializing Hermes and connecting
6
+ it to the debugger. The work I did was mainly based on
7
+
8
+ [HermesExecutorFactory.cpp](https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp)
9
+ from React Native.
10
+
11
+ ## Runtime initialization
12
+
13
+ If you take a look at `NativeProxy` (both on Android and iOS) you'll find
14
+ that it only makes a call to `ReanimatedRuntime::make(jsQueue)`. This
15
+ static function will return the correct runtime based on the user's configuration.
16
+
17
+ The initialization process is pretty simple and has only been moved out of
18
+ `NativeProxy` into `ReanimatedRuntime` without any major changes.
19
+
20
+ ## Hermes runtime debugging
21
+
22
+ To enable debugging on the Hermes runtime we need to do two things:
23
+
24
+ 1. Include source maps in JavaScript files
25
+
26
+ This part is done purely in JavaScript via the Babel plugin. The `makeWorklet`
27
+ function received an AST tree, which is aware of the modifications it made to
28
+ the code and therefore can generate the necessary source maps. It is important
29
+ that when we want to create a string from the AST we use the `generate` function
30
+ and enable source map generation so line mappings are not lost. Then when
31
+ transforming that code (ex. with `transformSync`) we have to pass the source
32
+ map as input so it can be updated.
33
+
34
+ Source map settings should always be set to `inline` so they are automatically
35
+ appended to the source code. The generated source map will be a base64 encoded
36
+ json.
37
+
38
+ A workletized function would look like this (after formattings):
39
+
40
+ ```js
41
+ function _f(number) {
42
+ console.log(_WORKLET, number);
43
+ }
44
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6IkFBYXNCLFNBQUNBLEVBQUQsQ0FBQ0EsTUFBRCxFQUFvQjtBQUV0Q0MsU0FBTyxDQUFDQyxHQUFSRCxDQUFZRSxRQUFaRixFQUFzQkQsTUFBdEJDO0FBRmtCIiwibmFtZXMiOlsibnVtYmVyIiwiY29uc29sZSIsImxvZyIsIl9XT1JLTEVUIl0sInNvdXJjZXMiOlsiL1VzZXJzL2thcm9sL0dpdC9yZWFjdC1uYXRpdmUtcmVhbmltYXRlZC9GYWJyaWNFeGFtcGxlL3NyYy9Xb3JrbGV0RXhhbXBsZS50c3giXSwic291cmNlc0NvbnRlbnQiOlsiLyogZ2xvYmFsIF9XT1JLTEVUICovXG5pbXBvcnQgeyBCdXR0b24sIFZpZXcsIFN0eWxlU2hlZXQgfSBmcm9tICdyZWFjdC1uYXRpdmUnO1xuaW1wb3J0IHtcbiAgcnVuT25KUyxcbiAgcnVuT25VSSxcbiAgdXNlRGVyaXZlZFZhbHVlLFxuICB1c2VTaGFyZWRWYWx1ZSxcbn0gZnJvbSAncmVhY3QtbmF0aXZlLXJlYW5pbWF0ZWQnO1xuXG5pbXBvcnQgUmVhY3QgZnJvbSAncmVhY3QnO1xuXG5leHBvcnQgZGVmYXVsdCBmdW5jdGlvbiBXb3JrbGV0RXhhbXBsZSgpIHtcbiAgLy8gcnVuT25VSSBkZW1vXG4gIGNvbnN0IHNvbWVXb3JrbGV0ID0gKG51bWJlcjogbnVtYmVyKSA9PiB7XG4gICAgJ3dvcmtsZXQnO1xuICAgIGNvbnNvbGUubG9nKF9XT1JLTEVULCBudW1iZXIpOyAvLyBfV09SS0xFVCBzaG91bGQgYmUgdHJ1ZVxuICB9O1xuXG4gIGNvbnN0IGhhbmRsZVByZXNzMSA9ICgpID0+IHtcbiAgICBydW5PblVJKHNvbWVXb3JrbGV0KShNYXRoLnJhbmRvbSgpKTtcbiAgfTtcblxuICAvLyBydW5PbkpTIGRlbW9cbiAgY29uc3QgeCA9IHVzZVNoYXJlZFZhbHVlKDApO1xuXG4gIGNvbnN0IHNvbWVGdW5jdGlvbiA9IChudW1iZXI6IG51bWJlcikgPT4ge1xuICAgIGNvbnNvbGUubG9nKF9XT1JLTEVULCBudW1iZXIpOyAvLyBfV09SS0xFVCBzaG91bGQgYmUgZmFsc2VcbiAgfTtcblxuICB1c2VEZXJpdmVkVmFsdWUoKCkgPT4ge1xuICAgIHJ1bk9uSlMoc29tZUZ1bmN0aW9uKSh4LnZhbHVlKTtcbiAgfSk7XG5cbiAgY29uc3QgaGFuZGxlUHJlc3MyID0gKCkgPT4ge1xuICAgIHgudmFsdWUgPSBNYXRoLnJhbmRvbSgpO1xuICB9O1xuXG4gIHJldHVybiAoXG4gICAgPFZpZXcgc3R5bGU9e3N0eWxlcy5jb250YWluZXJ9PlxuICAgICAgPEJ1dHRvbiBvblByZXNzPXtoYW5kbGVQcmVzczF9IHRpdGxlPVwicnVuT25VSSBkZW1vXCIgLz5cbiAgICAgIDxCdXR0b24gb25QcmVzcz17aGFuZGxlUHJlc3MyfSB0aXRsZT1cInJ1bk9uSlMgZGVtb1wiIC8+XG4gICAgPC9WaWV3PlxuICApO1xufVxuXG5jb25zdCBzdHlsZXMgPSBTdHlsZVNoZWV0LmNyZWF0ZSh7XG4gIGNvbnRhaW5lcjoge1xuICAgIGZsZXg6IDEsXG4gICAgYWxpZ25JdGVtczogJ2NlbnRlcicsXG4gICAganVzdGlmeUNvbnRlbnQ6ICdjZW50ZXInLFxuICB9LFxufSk7XG4iXX0=
45
+ ```
46
+
47
+ And the base64 string after decoding is:
48
+
49
+ ```json
50
+ {
51
+ "version": 3,
52
+ "mappings": "AAasB,SAACA,EAAD,CAACA,MAAD,EAAoB;AAEtCC,SAAO,CAACC,GAARD,CAAYE,QAAZF,EAAsBD,MAAtBC;AAFkB",
53
+ "names": ["number", "console", "log", "_WORKLET"],
54
+ "sources": [
55
+ "/Users/karol/Git/react-native-reanimated/FabricExample/src/WorkletExample.tsx"
56
+ ],
57
+ "sourcesContent": [
58
+ "/* global _WORKLET */\nimport { Button, View, StyleSheet } from 'react-native';\nimport {\n runOnJS,\n runOnUI,\n useDerivedValue,\n useSharedValue,\n} from 'react-native-reanimated';\n\nimport React from 'react';\n\nexport default function WorkletExample() {\n // runOnUI demo\n const someWorklet = (number: number) => {\n 'worklet';\n console.log(_WORKLET, number); // _WORKLET should be true\n };\n\n const handlePress1 = () => {\n runOnUI(someWorklet)(Math.random());\n };\n\n // runOnJS demo\n const x = useSharedValue(0);\n\n const someFunction = (number: number) => {\n console.log(_WORKLET, number); // _WORKLET should be false\n };\n\n useDerivedValue(() => {\n runOnJS(someFunction)(x.value);\n });\n\n const handlePress2 = () => {\n x.value = Math.random();\n };\n\n return (\n <View style={styles.container}>\n <Button onPress={handlePress1} title=\"runOnUI demo\" />\n <Button onPress={handlePress2} title=\"runOnJS demo\" />\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n alignItems: 'center',\n justifyContent: 'center',\n },\n});\n"
59
+ ]
60
+ }
61
+ ```
62
+
63
+ We run jest tests in release mode, because source maps will contain absolute
64
+ paths, which will be different on every machine and therefore would also alter
65
+ worklet hashes. Running in release mode prevents this.
66
+
67
+ 2. Enable debugging on the runtime object
68
+
69
+ This is done by creating an adapter (`HermesExecutorRuntimeAdapter` inside of
70
+ `WorkletHermesRuntime.cpp`) which holds the runtime and allows the debugger
71
+ to communicate with it. The adapter is managed by a `Connection` (`ConnectionDemux`)
72
+ object, but this is not important in our case. We just have to make a call
73
+ to `facebook::hermes::inspector::chrome::enableDebugging()` and pass the adapter
74
+ and runtime name as parameters.
75
+
76
+ It is important to also `disableDebugging()` before the runtime is destroyed.
77
+ Failing to do so will probably crash the app as the debugger will try to
78
+ connect to a non-existent runtime.
79
+
80
+ The runtime should also be destroyed before the Reanimated module, because
81
+ otherwise there might be weird BAD_ACCESS errors when the gc gets it
82
+ hand on the runtime.
83
+
84
+ ## Metro endpoint
85
+
86
+ Flipper and Chrome DevTools in general use the `localhost:8081/json` (where `8081`
87
+ is the port metro is running on) endpoint of metro to get the list of debuggable
88
+ targets (runtimes). For a normal React Native app the output would look something
89
+ like this:
90
+
91
+ ```json
92
+ [
93
+ {
94
+ "id": "0-1",
95
+ "description": "org.reactjs.native.example.FabricExample",
96
+ "title": "Hermes React Native",
97
+ "faviconUrl": "https://reactjs.org/favicon.ico",
98
+ "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D1",
99
+ "type": "node",
100
+ "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=0&page=1",
101
+ "vm": "Hermes"
102
+ },
103
+ {
104
+ "id": "0--1",
105
+ "description": "org.reactjs.native.example.FabricExample",
106
+ "title": "React Native Experimental (Improved Chrome Reloads)",
107
+ "faviconUrl": "https://reactjs.org/favicon.ico",
108
+ "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D-1",
109
+ "type": "node",
110
+ "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=0&page=-1",
111
+ "vm": "don't use"
112
+ }
113
+ ]
114
+ ```
115
+
116
+ For an Android app with Reanimated it should include the Reanimated runtime like
117
+ this:
118
+
119
+ ```json
120
+ [
121
+ {
122
+ "id": "0-2",
123
+ "description": "com.fabricexample",
124
+ "title": "Reanimated Runtime",
125
+ "faviconUrl": "https://reactjs.org/favicon.ico",
126
+ "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D3",
127
+ "type": "node",
128
+ "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=1&page=2",
129
+ "vm": "Hermes"
130
+ },
131
+ {
132
+ "id": "0-1",
133
+ "description": "com.fabricexample",
134
+ "title": "Hermes React Native",
135
+ "faviconUrl": "https://reactjs.org/favicon.ico",
136
+ "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D2",
137
+ "type": "node",
138
+ "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=1&page=1",
139
+ "vm": "Hermes"
140
+ },
141
+ {
142
+ "id": "0--1",
143
+ "description": "com.fabricexample",
144
+ "title": "React Native Experimental (Improved Chrome Reloads)",
145
+ "faviconUrl": "https://reactjs.org/favicon.ico",
146
+ "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D-1",
147
+ "type": "node",
148
+ "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=1&page=-1",
149
+ "vm": "don't use"
150
+ },
151
+ {
152
+ "id": "0--2",
153
+ "description": "com.fabricexample",
154
+ "title": "Reanimated Runtime Experimental (Improved Chrome Reloads)",
155
+ "faviconUrl": "https://reactjs.org/favicon.ico",
156
+ "devtoolsFrontendUrl": "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=%5B%3A%3A1%5D%3A8081%2Finspector%2Fdebug%3Fdevice%3D0%26page%3D-2",
157
+ "type": "node",
158
+ "webSocketDebuggerUrl": "ws://[::1]:8081/inspector/debug?device=1&page=-2",
159
+ "vm": "don't use"
160
+ }
161
+ ]
162
+ ```
163
+
164
+ Runtimes with negative IDs are 'virtual' - they are just references to the real
165
+ runtimes but their IDs don't change after a reload. If we were to connect to
166
+ the normal runtime and reload the app it would crash, as the debugger would try
167
+ to communicate with a non-existent runtime. These 'virtual' runtimes are made
168
+ and managed by metro (PR: [facebook/metro#864](https://github.com/facebook/metro/pull/864)).
169
+
170
+ ## Known issues
171
+
172
+ **IFrame sandboxing**
173
+
174
+ Source maps always define a `sources` array, which contain names of files used
175
+ to generate the source map. For Chrome DevTools this is sufficient as it will
176
+ read files from disk, but the `IFrame` interface used by Flipper is sandboxed
177
+ and doesn't allow filesystem access. Therefore we also need to include the files
178
+ content in the `sourcesContent` array.
179
+
180
+ **Chrome version 105.0.5195.102 doesn't load source maps**
181
+
182
+ This version of Chrome introduced a regression into DevTools that broke source
183
+ maps loading for node.js apps. This issue is not caused by Reanimated in any
184
+ way and should be fixed by Chrome developers in later versions.
185
+
186
+ The issue was tracked here: https://bugs.chromium.org/p/chromium/issues/detail?id=1358497
187
+
188
+ **App reloads don't work**
189
+
190
+ On iOS the app will crash on every reload if a debugger is connected to the runtime.
191
+ On Android it will also crash but only after a few reloads.
@@ -0,0 +1,16 @@
1
+ #pragma once
2
+
3
+ namespace worklets {
4
+ /**
5
+ * Represents the different types of runtime environments available for
6
+ * worklets.
7
+ */
8
+ enum class RuntimeKind {
9
+ ReactNative = 1,
10
+ UI = 2,
11
+ Worker = 3,
12
+ };
13
+
14
+ constexpr auto runtimeKindBindingName = "__RUNTIME_KIND";
15
+
16
+ } // namespace worklets
@@ -0,0 +1,105 @@
1
+ #include <worklets/NativeModules/JSIWorkletsModuleProxy.h>
2
+ #include <worklets/WorkletRuntime/RuntimeManager.h>
3
+
4
+ #include <utility>
5
+
6
+ namespace worklets {
7
+
8
+ std::shared_ptr<WorkletRuntime> RuntimeManager::getRuntime(uint64_t runtimeId) {
9
+ std::shared_lock lock(weakRuntimesMutex_);
10
+ if (weakRuntimes_.contains(runtimeId)) {
11
+ return weakRuntimes_.at(runtimeId).lock();
12
+ }
13
+ return nullptr;
14
+ }
15
+
16
+ std::shared_ptr<WorkletRuntime> RuntimeManager::getRuntime(
17
+ const std::string &name) {
18
+ std::shared_lock lock(weakRuntimesMutex_);
19
+ if (nameToRuntimeId_.contains(name)) {
20
+ return getRuntime(nameToRuntimeId_.at(name));
21
+ }
22
+ return nullptr;
23
+ }
24
+
25
+ #ifdef WORKLETS_BUNDLE_MODE
26
+ std::shared_ptr<WorkletRuntime> RuntimeManager::getRuntime(
27
+ jsi::Runtime *runtime) {
28
+ std::shared_lock lock(weakRuntimesMutex_);
29
+ if (runtimeAddressToRuntimeId_.contains(runtime)) {
30
+ return getRuntime(runtimeAddressToRuntimeId_.at(runtime));
31
+ }
32
+ return nullptr;
33
+ }
34
+ #endif // WORKLETS_BUNDLE_MODE
35
+
36
+ std::vector<std::shared_ptr<WorkletRuntime>> RuntimeManager::getAllRuntimes() {
37
+ std::shared_lock lock(weakRuntimesMutex_);
38
+
39
+ std::vector<std::shared_ptr<WorkletRuntime>> runtimes;
40
+ runtimes.reserve(weakRuntimes_.size());
41
+
42
+ for (const auto &[id, weakRuntime] : weakRuntimes_) {
43
+ if (auto runtime = weakRuntime.lock()) {
44
+ runtimes.push_back(runtime);
45
+ }
46
+ }
47
+
48
+ return runtimes;
49
+ }
50
+
51
+ std::shared_ptr<WorkletRuntime> RuntimeManager::getUIRuntime() {
52
+ return getRuntime(uiRuntimeId);
53
+ }
54
+
55
+ std::shared_ptr<WorkletRuntime> RuntimeManager::createWorkletRuntime(
56
+ std::shared_ptr<JSIWorkletsModuleProxy> jsiWorkletsModuleProxy,
57
+ const std::string &name,
58
+ std::shared_ptr<SerializableWorklet> initializer,
59
+ const std::shared_ptr<AsyncQueue> &queue,
60
+ bool enableEventLoop) {
61
+ const auto runtimeId = getNextRuntimeId();
62
+ const auto jsQueue = jsiWorkletsModuleProxy->getJSQueue();
63
+
64
+ auto workletRuntime = std::make_shared<WorkletRuntime>(
65
+ runtimeId, jsQueue, name, queue, enableEventLoop);
66
+
67
+ workletRuntime->init(std::move(jsiWorkletsModuleProxy));
68
+
69
+ if (initializer) {
70
+ workletRuntime->runGuarded(initializer);
71
+ }
72
+
73
+ registerRuntime(runtimeId, name, workletRuntime);
74
+
75
+ return workletRuntime;
76
+ }
77
+
78
+ std::shared_ptr<WorkletRuntime> RuntimeManager::createUninitializedUIRuntime(
79
+ const std::shared_ptr<MessageQueueThread> &jsQueue,
80
+ const std::shared_ptr<AsyncQueue> &uiAsyncQueue) {
81
+ const auto uiRuntime = std::make_shared<WorkletRuntime>(
82
+ uiRuntimeId, jsQueue, uiRuntimeName, uiAsyncQueue);
83
+
84
+ registerRuntime(uiRuntimeId, uiRuntimeName, uiRuntime);
85
+
86
+ return uiRuntime;
87
+ }
88
+
89
+ uint64_t RuntimeManager::getNextRuntimeId() {
90
+ return nextRuntimeId_.fetch_add(1, std::memory_order_relaxed);
91
+ }
92
+
93
+ void RuntimeManager::registerRuntime(
94
+ const uint64_t runtimeId,
95
+ const std::string &name,
96
+ const std::shared_ptr<WorkletRuntime> &workletRuntime) {
97
+ std::unique_lock lock(weakRuntimesMutex_);
98
+ weakRuntimes_[runtimeId] = workletRuntime;
99
+ nameToRuntimeId_[name] = runtimeId;
100
+ #ifdef WORKLETS_BUNDLE_MODE
101
+ runtimeAddressToRuntimeId_[&workletRuntime->getJSIRuntime()] = runtimeId;
102
+ #endif // WORKLETS_BUNDLE_MODE
103
+ }
104
+
105
+ } // namespace worklets