react-native-reanimated 2.3.0-alpha.1 → 2.3.0-beta.2

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 (328) hide show
  1. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +15 -8
  2. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +170 -166
  3. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +36 -34
  4. package/Common/cpp/Registries/EventHandlerRegistry.cpp +13 -6
  5. package/Common/cpp/Registries/MapperRegistry.cpp +19 -15
  6. package/Common/cpp/Registries/WorkletsCache.cpp +19 -9
  7. package/Common/cpp/SharedItems/FrozenObject.cpp +19 -8
  8. package/Common/cpp/SharedItems/MutableValue.cpp +38 -25
  9. package/Common/cpp/SharedItems/MutableValueSetterProxy.cpp +11 -7
  10. package/Common/cpp/SharedItems/RemoteObject.cpp +9 -5
  11. package/Common/cpp/SharedItems/ShareableValue.cpp +216 -143
  12. package/Common/cpp/Tools/JSIStoreValueUser.cpp +36 -24
  13. package/Common/cpp/Tools/Mapper.cpp +41 -29
  14. package/Common/cpp/Tools/RuntimeDecorator.cpp +103 -84
  15. package/Common/cpp/Tools/Scheduler.cpp +14 -6
  16. package/Common/cpp/Tools/WorkletEventHandler.cpp +1 -1
  17. package/Common/cpp/headers/LayoutAnimations/LayoutAnimationsProxy.h +12 -11
  18. package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +45 -34
  19. package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +28 -16
  20. package/Common/cpp/headers/Registries/EventHandlerRegistry.h +14 -8
  21. package/Common/cpp/headers/Registries/MapperRegistry.h +4 -4
  22. package/Common/cpp/headers/Registries/WorkletsCache.h +9 -7
  23. package/Common/cpp/headers/SharedItems/FrozenObject.h +15 -11
  24. package/Common/cpp/headers/SharedItems/HostFunctionHandler.h +6 -4
  25. package/Common/cpp/headers/SharedItems/MutableValue.h +21 -12
  26. package/Common/cpp/headers/SharedItems/MutableValueSetterProxy.h +10 -7
  27. package/Common/cpp/headers/SharedItems/RemoteObject.h +16 -8
  28. package/Common/cpp/headers/SharedItems/RuntimeManager.h +39 -21
  29. package/Common/cpp/headers/SharedItems/ShareableValue.h +31 -27
  30. package/Common/cpp/headers/SharedItems/SharedParent.h +7 -4
  31. package/Common/cpp/headers/SharedItems/ValueWrapper.h +80 -61
  32. package/Common/cpp/headers/SpecTools/ErrorHandler.h +17 -19
  33. package/Common/cpp/headers/Tools/JSIStoreValueUser.h +18 -13
  34. package/Common/cpp/headers/Tools/Mapper.h +24 -18
  35. package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +12 -7
  36. package/Common/cpp/headers/Tools/ReanimatedHiddenHeaders.h +7 -7
  37. package/Common/cpp/headers/Tools/RuntimeDecorator.h +29 -23
  38. package/Common/cpp/headers/Tools/Scheduler.h +28 -33
  39. package/Common/cpp/headers/Tools/WorkletEventHandler.h +9 -7
  40. package/Common/cpp/hidden_headers/Logger.h +14 -14
  41. package/Common/cpp/hidden_headers/LoggerInterface.h +8 -9
  42. package/Common/cpp/hidden_headers/SpeedChecker.h +7 -8
  43. package/README.md +1 -1
  44. package/RNReanimated.podspec +4 -4
  45. package/android/build.gradle +80 -3
  46. package/android/react-native-reanimated-63-hermes.aar +0 -0
  47. package/android/react-native-reanimated-63-jsc.aar +0 -0
  48. package/android/react-native-reanimated-64-hermes.aar +0 -0
  49. package/android/react-native-reanimated-64-jsc.aar +0 -0
  50. package/android/react-native-reanimated-65-hermes.aar +0 -0
  51. package/android/react-native-reanimated-65-jsc.aar +0 -0
  52. package/android/react-native-reanimated-66-hermes.aar +0 -0
  53. package/android/react-native-reanimated-66-jsc.aar +0 -0
  54. package/ios/LayoutReanimation/REAAnimationsManager.h +19 -10
  55. package/ios/LayoutReanimation/REAAnimationsManager.m +195 -200
  56. package/ios/LayoutReanimation/REASnapshot.h +13 -0
  57. package/ios/LayoutReanimation/REASnapshot.m +29 -0
  58. package/ios/LayoutReanimation/REAUIManager.h +16 -0
  59. package/ios/LayoutReanimation/REAUIManager.mm +348 -0
  60. package/ios/Nodes/REAAlwaysNode.m +14 -15
  61. package/ios/Nodes/REABezierNode.m +8 -7
  62. package/ios/Nodes/REABlockNode.m +1 -1
  63. package/ios/Nodes/REACallFuncNode.h +0 -1
  64. package/ios/Nodes/REACallFuncNode.m +10 -8
  65. package/ios/Nodes/REAClockNodes.m +22 -20
  66. package/ios/Nodes/REAConcatNode.h +0 -1
  67. package/ios/Nodes/REAConcatNode.m +2 -2
  68. package/ios/Nodes/REACondNode.m +7 -5
  69. package/ios/Nodes/READebugNode.m +5 -4
  70. package/ios/Nodes/REAEventNode.m +1 -1
  71. package/ios/Nodes/REAFunctionNode.h +0 -1
  72. package/ios/Nodes/REAFunctionNode.m +2 -2
  73. package/ios/Nodes/REAJSCallNode.m +4 -5
  74. package/ios/Nodes/REANode.h +3 -4
  75. package/ios/Nodes/REANode.m +9 -11
  76. package/ios/Nodes/REAOperatorNode.m +68 -67
  77. package/ios/Nodes/REAParamNode.h +1 -3
  78. package/ios/Nodes/REAParamNode.m +15 -17
  79. package/ios/Nodes/REAPropsNode.h +1 -3
  80. package/ios/Nodes/REAPropsNode.m +19 -22
  81. package/ios/Nodes/REASetNode.h +0 -1
  82. package/ios/Nodes/REASetNode.m +7 -5
  83. package/ios/Nodes/REAStyleNode.h +0 -1
  84. package/ios/Nodes/REAStyleNode.m +2 -4
  85. package/ios/Nodes/REATransformNode.h +0 -1
  86. package/ios/Nodes/REATransformNode.m +3 -5
  87. package/ios/Nodes/REAValueNode.m +5 -7
  88. package/ios/REAEventDispatcher.m +3 -3
  89. package/ios/REAModule.h +0 -2
  90. package/ios/REAModule.m +29 -40
  91. package/ios/REANodesManager.h +11 -19
  92. package/ios/REANodesManager.m +105 -130
  93. package/ios/REAUtils.h +5 -3
  94. package/ios/Transitioning/RCTConvert+REATransition.m +45 -29
  95. package/ios/Transitioning/REAAllTransitions.h +2 -2
  96. package/ios/Transitioning/REAAllTransitions.m +14 -25
  97. package/ios/Transitioning/REATransition.h +8 -7
  98. package/ios/Transitioning/REATransition.m +19 -16
  99. package/ios/Transitioning/REATransitionAnimation.h +1 -1
  100. package/ios/Transitioning/REATransitionAnimation.m +2 -3
  101. package/ios/Transitioning/REATransitionManager.m +3 -3
  102. package/ios/native/NativeMethods.h +15 -5
  103. package/ios/native/NativeProxy.h +4 -3
  104. package/ios/native/NativeProxy.mm +19 -5
  105. package/ios/native/REAIOSErrorHandler.h +13 -10
  106. package/ios/native/REAIOSLogger.h +8 -8
  107. package/ios/native/REAIOSScheduler.h +5 -5
  108. package/ios/native/REAIOSScheduler.mm +7 -5
  109. package/ios/native/REAInitializer.h +37 -0
  110. package/ios/native/REAInitializer.mm +63 -0
  111. package/ios/native/UIResponder+Reanimated.mm +9 -48
  112. package/lib/ConfigHelper.js +1 -0
  113. package/lib/ReanimatedModule.native.js +10 -2
  114. package/lib/createAnimatedComponent.js +64 -30
  115. package/lib/reanimated1/core/AnimatedAlways.js +1 -1
  116. package/lib/reanimated1/core/AnimatedBezier.js +1 -1
  117. package/lib/reanimated1/core/AnimatedBlock.js +1 -1
  118. package/lib/reanimated1/core/AnimatedCall.js +1 -1
  119. package/lib/reanimated1/core/AnimatedCallFunc.js +1 -1
  120. package/lib/reanimated1/core/AnimatedConcat.js +1 -1
  121. package/lib/reanimated1/core/AnimatedCond.js +1 -1
  122. package/lib/reanimated1/core/AnimatedDebug.js +1 -1
  123. package/lib/reanimated1/core/AnimatedEvent.js +1 -1
  124. package/lib/reanimated1/core/AnimatedFunction.js +1 -1
  125. package/lib/reanimated1/core/AnimatedOperator.js +1 -1
  126. package/lib/reanimated1/core/AnimatedParam.js +1 -1
  127. package/lib/reanimated1/core/AnimatedProps.js +2 -2
  128. package/lib/reanimated1/core/AnimatedSet.js +1 -1
  129. package/lib/reanimated1/core/AnimatedStartClock.js +1 -1
  130. package/lib/reanimated1/core/AnimatedStopClock.js +1 -1
  131. package/lib/reanimated1/core/AnimatedStyle.js +1 -1
  132. package/lib/reanimated1/core/AnimatedTransform.js +1 -1
  133. package/lib/reanimated1/core/Core.test.js +30 -0
  134. package/lib/reanimated1/core/InternalAnimatedValue.js +1 -1
  135. package/lib/reanimated1/core/__mocks__/AnimatedProps.js +1 -1
  136. package/lib/reanimated1/derived/interpolate.js +1 -1
  137. package/lib/reanimated2/Colors.js +16 -12
  138. package/lib/reanimated2/NativeMethods.js +3 -14
  139. package/lib/reanimated2/{NativeReanimated.native.js → NativeReanimated/NativeReanimated.js} +19 -24
  140. package/lib/reanimated2/NativeReanimated/index.js +15 -0
  141. package/lib/reanimated2/PlatformChecker.js +16 -0
  142. package/lib/reanimated2/PropAdapters.js +14 -4
  143. package/lib/reanimated2/UpdateProps.js +14 -11
  144. package/lib/reanimated2/ViewDescriptorsSet.js +73 -0
  145. package/lib/reanimated2/WorkletEventHandler.js +15 -13
  146. package/lib/reanimated2/animation/commonTypes.js +1 -0
  147. package/lib/reanimated2/animation/decay.js +71 -0
  148. package/lib/reanimated2/animation/delay.js +64 -0
  149. package/lib/reanimated2/animation/index.js +8 -0
  150. package/lib/reanimated2/animation/repeat.js +69 -0
  151. package/lib/reanimated2/animation/sequence.js +72 -0
  152. package/lib/reanimated2/animation/spring.js +101 -0
  153. package/lib/reanimated2/animation/styleAnimation.js +166 -0
  154. package/lib/reanimated2/animation/timing.js +64 -0
  155. package/lib/reanimated2/animation/util.js +157 -0
  156. package/lib/reanimated2/commonTypes.js +1 -0
  157. package/lib/reanimated2/core.js +35 -39
  158. package/lib/reanimated2/globals.d.ts +47 -1
  159. package/lib/reanimated2/hook/Hooks.js +9 -0
  160. package/lib/reanimated2/hook/commonTypes.js +1 -0
  161. package/lib/reanimated2/hook/index.js +8 -0
  162. package/lib/reanimated2/hook/useAnimatedGestureHandler.js +50 -0
  163. package/lib/reanimated2/hook/useAnimatedReaction.js +37 -0
  164. package/lib/reanimated2/hook/useAnimatedRef.js +25 -0
  165. package/lib/reanimated2/hook/useAnimatedScrollHandler.js +41 -0
  166. package/lib/reanimated2/hook/useAnimatedStyle.js +376 -0
  167. package/lib/reanimated2/hook/useDerivedValue.js +36 -0
  168. package/lib/reanimated2/hook/useSharedValue.js +17 -0
  169. package/lib/reanimated2/hook/utils.js +175 -0
  170. package/lib/reanimated2/index.js +3 -2
  171. package/lib/reanimated2/interpolation.js +95 -86
  172. package/lib/reanimated2/jestUtils.js +0 -12
  173. package/lib/reanimated2/js-reanimated/JSReanimated.js +9 -10
  174. package/lib/reanimated2/js-reanimated/index.js +57 -1
  175. package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +58 -0
  176. package/lib/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +69 -0
  177. package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +125 -0
  178. package/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +193 -0
  179. package/lib/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +1 -0
  180. package/lib/reanimated2/layoutReanimation/animationBuilder/index.js +3 -0
  181. package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +325 -207
  182. package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +36 -0
  183. package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +235 -187
  184. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +327 -269
  185. package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +146 -0
  186. package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +85 -0
  187. package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +119 -0
  188. package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +289 -0
  189. package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +159 -121
  190. package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +83 -65
  191. package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +371 -277
  192. package/lib/reanimated2/layoutReanimation/defaultAnimations/index.js +4 -0
  193. package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +78 -0
  194. package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +128 -0
  195. package/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +37 -0
  196. package/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +41 -0
  197. package/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +34 -0
  198. package/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +46 -0
  199. package/lib/reanimated2/layoutReanimation/defaultTransitions/index.js +6 -0
  200. package/lib/reanimated2/layoutReanimation/index.js +3 -2
  201. package/lib/reanimated2/platform-specific/RNRenderer.web.js +2 -0
  202. package/lib/reanimated2/utils.js +9 -0
  203. package/libSo/fbjni/jni/arm64-v8a/libfbjni.so +0 -0
  204. package/libSo/fbjni/jni/armeabi-v7a/libfbjni.so +0 -0
  205. package/libSo/fbjni/jni/x86/libfbjni.so +0 -0
  206. package/libSo/fbjni/jni/x86_64/libfbjni.so +0 -0
  207. package/package.json +21 -10
  208. package/plugin.js +244 -85
  209. package/react-native-reanimated.d.ts +531 -453
  210. package/src/ConfigHelper.js +1 -0
  211. package/src/ReanimatedModule.native.js +10 -2
  212. package/src/createAnimatedComponent.js +64 -30
  213. package/src/reanimated1/core/AnimatedAlways.js +1 -1
  214. package/src/reanimated1/core/AnimatedBezier.js +1 -1
  215. package/src/reanimated1/core/AnimatedBlock.js +1 -1
  216. package/src/reanimated1/core/AnimatedCall.js +1 -1
  217. package/src/reanimated1/core/AnimatedCallFunc.js +1 -1
  218. package/src/reanimated1/core/AnimatedConcat.js +1 -1
  219. package/src/reanimated1/core/AnimatedCond.js +1 -1
  220. package/src/reanimated1/core/AnimatedDebug.js +1 -1
  221. package/src/reanimated1/core/AnimatedEvent.js +1 -1
  222. package/src/reanimated1/core/AnimatedFunction.js +1 -1
  223. package/src/reanimated1/core/AnimatedOperator.js +1 -1
  224. package/src/reanimated1/core/AnimatedParam.js +1 -1
  225. package/src/reanimated1/core/AnimatedProps.js +2 -2
  226. package/src/reanimated1/core/AnimatedSet.js +1 -1
  227. package/src/reanimated1/core/AnimatedStartClock.js +1 -1
  228. package/src/reanimated1/core/AnimatedStopClock.js +1 -1
  229. package/src/reanimated1/core/AnimatedStyle.js +1 -1
  230. package/src/reanimated1/core/AnimatedTransform.js +1 -1
  231. package/src/reanimated1/core/Core.test.js +30 -0
  232. package/src/reanimated1/core/InternalAnimatedValue.js +1 -1
  233. package/src/reanimated1/core/__mocks__/AnimatedProps.js +1 -1
  234. package/src/reanimated1/derived/interpolate.js +1 -1
  235. package/src/reanimated2/Colors.ts +30 -27
  236. package/src/reanimated2/Easing.ts +3 -1
  237. package/src/reanimated2/NativeMethods.ts +26 -16
  238. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +78 -0
  239. package/src/reanimated2/NativeReanimated/index.ts +18 -0
  240. package/src/reanimated2/PlatformChecker.ts +21 -0
  241. package/src/reanimated2/PropAdapters.ts +52 -34
  242. package/src/reanimated2/UpdateProps.ts +40 -20
  243. package/src/reanimated2/ViewDescriptorsSet.ts +108 -0
  244. package/src/reanimated2/WorkletEventHandler.ts +41 -23
  245. package/src/reanimated2/animation/commonTypes.ts +48 -0
  246. package/src/reanimated2/animation/decay.ts +141 -0
  247. package/src/reanimated2/animation/delay.ts +103 -0
  248. package/src/reanimated2/animation/index.ts +16 -0
  249. package/src/reanimated2/animation/repeat.ts +128 -0
  250. package/src/reanimated2/animation/sequence.ts +110 -0
  251. package/src/reanimated2/animation/spring.ts +165 -0
  252. package/src/reanimated2/animation/styleAnimation.ts +253 -0
  253. package/src/reanimated2/animation/timing.ts +109 -0
  254. package/src/reanimated2/animation/util.ts +242 -0
  255. package/src/reanimated2/commonTypes.ts +81 -0
  256. package/src/reanimated2/core.ts +128 -82
  257. package/src/reanimated2/globals.d.ts +47 -1
  258. package/src/reanimated2/hook/Hooks.ts +16 -0
  259. package/src/reanimated2/hook/commonTypes.ts +12 -0
  260. package/src/reanimated2/hook/index.ts +25 -0
  261. package/src/reanimated2/hook/useAnimatedGestureHandler.ts +110 -0
  262. package/src/reanimated2/hook/useAnimatedReaction.ts +49 -0
  263. package/src/reanimated2/hook/useAnimatedRef.ts +34 -0
  264. package/src/reanimated2/hook/useAnimatedScrollHandler.ts +83 -0
  265. package/src/reanimated2/hook/useAnimatedStyle.ts +538 -0
  266. package/src/reanimated2/hook/useDerivedValue.ts +48 -0
  267. package/src/reanimated2/hook/useSharedValue.ts +22 -0
  268. package/src/reanimated2/hook/utils.ts +259 -0
  269. package/src/reanimated2/index.ts +3 -2
  270. package/src/reanimated2/interpolation.ts +170 -101
  271. package/src/reanimated2/jestUtils.ts +0 -12
  272. package/src/reanimated2/js-reanimated/JSReanimated.ts +47 -22
  273. package/src/reanimated2/js-reanimated/Mapper.ts +1 -1
  274. package/src/reanimated2/js-reanimated/index.ts +71 -0
  275. package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.tsx +62 -0
  276. package/src/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.ts +91 -0
  277. package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +169 -0
  278. package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +263 -0
  279. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +78 -0
  280. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +16 -0
  281. package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +243 -121
  282. package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +43 -0
  283. package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +95 -53
  284. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +114 -64
  285. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +179 -0
  286. package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +93 -0
  287. package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +132 -0
  288. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +333 -0
  289. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +84 -50
  290. package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +41 -23
  291. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +234 -154
  292. package/src/reanimated2/layoutReanimation/defaultAnimations/index.ts +4 -0
  293. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +104 -0
  294. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +213 -0
  295. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +60 -0
  296. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +58 -0
  297. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +41 -0
  298. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +78 -0
  299. package/src/reanimated2/layoutReanimation/defaultTransitions/index.ts +6 -0
  300. package/src/reanimated2/layoutReanimation/index.ts +3 -2
  301. package/src/reanimated2/platform-specific/RNRenderer.web.ts +2 -0
  302. package/src/reanimated2/utils.ts +21 -0
  303. package/android/react-native-reanimated-62-hermes.aar +0 -0
  304. package/android/react-native-reanimated-62-jsc.aar +0 -0
  305. package/ios/LayoutReanimation/REAAnimationRootView.h +0 -12
  306. package/ios/LayoutReanimation/REAAnimationRootView.m +0 -16
  307. package/ios/LayoutReanimation/REAAnimationRootViewManager.h +0 -9
  308. package/ios/LayoutReanimation/REAAnimationRootViewManager.m +0 -49
  309. package/ios/LayoutReanimation/REAReactBatchObserver.h +0 -20
  310. package/ios/LayoutReanimation/REAReactBatchObserver.m +0 -125
  311. package/ios/LayoutReanimation/REASnapshooter.h +0 -19
  312. package/ios/LayoutReanimation/REASnapshooter.m +0 -64
  313. package/ios/LayoutReanimation/REAViewTraverser.h +0 -13
  314. package/ios/LayoutReanimation/REAViewTraverser.m +0 -40
  315. package/lib/reanimated2/Hooks.js +0 -732
  316. package/lib/reanimated2/NativeReanimated.js +0 -4
  317. package/lib/reanimated2/animations.js +0 -713
  318. package/lib/reanimated2/js-reanimated/index.web.js +0 -20
  319. package/lib/reanimated2/layoutReanimation/AnimatedRoot.js +0 -55
  320. package/lib/reanimated2/layoutReanimation/defaultAnimationsBuilder.js +0 -374
  321. package/src/reanimated2/Hooks.ts +0 -918
  322. package/src/reanimated2/NativeReanimated.native.ts +0 -61
  323. package/src/reanimated2/NativeReanimated.ts +0 -5
  324. package/src/reanimated2/animations.ts +0 -868
  325. package/src/reanimated2/js-reanimated/index.js +0 -0
  326. package/src/reanimated2/js-reanimated/index.web.ts +0 -29
  327. package/src/reanimated2/layoutReanimation/AnimatedRoot.tsx +0 -68
  328. package/src/reanimated2/layoutReanimation/defaultAnimationsBuilder.ts +0 -440
@@ -1,16 +1,16 @@
1
- #include "ShareableValue.h"
2
- #include "SharedParent.h"
3
- #include "RuntimeManager.h"
1
+ #include <cxxabi.h>
2
+ #include "FrozenObject.h"
4
3
  #include "MutableValue.h"
5
4
  #include "MutableValueSetterProxy.h"
6
5
  #include "RemoteObject.h"
7
- #include "FrozenObject.h"
8
6
  #include "RuntimeDecorator.h"
7
+ #include "RuntimeManager.h"
8
+ #include "SharedParent.h"
9
9
 
10
10
  namespace reanimated {
11
-
11
+ class ShareableValue;
12
12
  const char *HIDDEN_HOST_OBJECT_PROP = "__reanimatedHostObjectRef";
13
- const char *ALREADY_CONVERTED= "__alreadyConverted";
13
+ const char *ALREADY_CONVERTED = "__alreadyConverted";
14
14
  const char *CALL_ASYNC = "__callAsync";
15
15
  const char *PRIMAL_FUNCTION = "__primalFunction";
16
16
  std::string CALLBACK_ERROR_SUFFIX = R"(
@@ -19,12 +19,14 @@ Possible solutions are:
19
19
  a) If you want to synchronously execute this method, mark it as a Worklet
20
20
  b) If you want to execute this method on the JS thread, wrap it using runOnJS )";
21
21
 
22
- void addHiddenProperty(jsi::Runtime &rt,
23
- jsi::Value &&value,
24
- jsi::Object &obj,
25
- const char *name) {
22
+ void addHiddenProperty(
23
+ jsi::Runtime &rt,
24
+ jsi::Value &&value,
25
+ jsi::Object &obj,
26
+ const char *name) {
26
27
  jsi::Object globalObject = rt.global().getPropertyAsObject(rt, "Object");
27
- jsi::Function defineProperty = globalObject.getPropertyAsFunction(rt, "defineProperty");
28
+ jsi::Function defineProperty =
29
+ globalObject.getPropertyAsFunction(rt, "defineProperty");
28
30
  jsi::String internalPropName = jsi::String::createFromUtf8(rt, name);
29
31
  jsi::Object paramForDefineProperty(rt);
30
32
  paramForDefineProperty.setProperty(rt, "enumerable", false);
@@ -39,8 +41,9 @@ void freeze(jsi::Runtime &rt, jsi::Object &obj) {
39
41
  }
40
42
 
41
43
  void ShareableValue::adaptCache(jsi::Runtime &rt, const jsi::Value &value) {
42
- // when adapting from host object we can assign cached value immediately such that we avoid
43
- // running `toJSValue` in the future when given object is accessed
44
+ // when adapting from host object we can assign cached value immediately such
45
+ // that we avoid running `toJSValue` in the future when given object is
46
+ // accessed
44
47
  if (RuntimeDecorator::isWorkletRuntime(rt)) {
45
48
  if (remoteValue.expired()) {
46
49
  remoteValue = getWeakRef(rt);
@@ -51,7 +54,10 @@ void ShareableValue::adaptCache(jsi::Runtime &rt, const jsi::Value &value) {
51
54
  }
52
55
  }
53
56
 
54
- void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType objectType) {
57
+ void ShareableValue::adapt(
58
+ jsi::Runtime &rt,
59
+ const jsi::Value &value,
60
+ ValueType objectType) {
55
61
  if (value.isObject()) {
56
62
  jsi::Object object = value.asObject(rt);
57
63
  jsi::Value hiddenValue = object.getProperty(rt, HIDDEN_HOST_OBJECT_PROP);
@@ -63,8 +69,7 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType
63
69
  type = ValueType::WorkletFunctionType;
64
70
  }
65
71
  valueContainer = std::make_unique<FrozenObjectWrapper>(
66
- hiddenProperty.getHostObject<FrozenObject>(rt)
67
- );
72
+ hiddenProperty.getHostObject<FrozenObject>(rt));
68
73
  if (object.hasProperty(rt, ALREADY_CONVERTED)) {
69
74
  adaptCache(rt, value);
70
75
  }
@@ -75,9 +80,9 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType
75
80
 
76
81
  if (objectType == ValueType::MutableValueType) {
77
82
  type = ValueType::MutableValueType;
78
- valueContainer = std::make_unique<MutableValueWrapper>(
79
- std::make_shared<MutableValue>(rt, value, runtimeManager, runtimeManager->scheduler)
80
- );
83
+ valueContainer =
84
+ std::make_unique<MutableValueWrapper>(std::make_shared<MutableValue>(
85
+ rt, value, runtimeManager, runtimeManager->scheduler));
81
86
  } else if (value.isUndefined()) {
82
87
  type = ValueType::UndefinedType;
83
88
  } else if (value.isNull()) {
@@ -90,7 +95,8 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType
90
95
  valueContainer = std::make_unique<NumberValueWrapper>(value.asNumber());
91
96
  } else if (value.isString()) {
92
97
  type = ValueType::StringType;
93
- valueContainer = std::make_unique<StringValueWrapper>(value.asString(rt).utf8(rt));
98
+ valueContainer =
99
+ std::make_unique<StringValueWrapper>(value.asString(rt).utf8(rt));
94
100
  } else if (value.isObject()) {
95
101
  auto object = value.asObject(rt);
96
102
  if (object.isFunction(rt)) {
@@ -99,32 +105,39 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType
99
105
  type = ValueType::HostFunctionType;
100
106
  containsHostFunction = true;
101
107
 
102
- //Check if it's a hostFunction wrapper
108
+ // Check if it's a hostFunction wrapper
103
109
  jsi::Value primalFunction = object.getProperty(rt, PRIMAL_FUNCTION);
104
110
  if (!primalFunction.isUndefined()) {
105
- jsi::Object handlerAsObject = primalFunction.asObject(rt);
106
- std::shared_ptr<HostFunctionHandler> handler = handlerAsObject.getHostObject<HostFunctionHandler>(rt);
107
- valueContainer = std::make_unique<HostFunctionWrapper>(handler);
111
+ jsi::Object handlerAsObject = primalFunction.asObject(rt);
112
+ std::shared_ptr<HostFunctionHandler> handler =
113
+ handlerAsObject.getHostObject<HostFunctionHandler>(rt);
114
+ valueContainer = std::make_unique<HostFunctionWrapper>(handler);
108
115
  } else {
109
- valueContainer = std::make_unique<HostFunctionWrapper>(
110
- std::make_shared<HostFunctionHandler>(std::make_shared<jsi::Function>(object.asFunction(rt)), rt));
116
+ valueContainer = std::make_unique<HostFunctionWrapper>(
117
+ std::make_shared<HostFunctionHandler>(
118
+ std::make_shared<jsi::Function>(object.asFunction(rt)), rt));
111
119
  }
112
120
 
113
121
  } else {
114
122
  // a worklet
115
123
  type = ValueType::WorkletFunctionType;
116
- valueContainer = std::make_unique<FrozenObjectWrapper>(std::make_shared<FrozenObject>(rt, object, runtimeManager));
117
- auto& frozenObject = ValueWrapper::asFrozenObject(valueContainer);
124
+ valueContainer = std::make_unique<FrozenObjectWrapper>(
125
+ std::make_shared<FrozenObject>(rt, object, runtimeManager));
126
+ auto &frozenObject = ValueWrapper::asFrozenObject(valueContainer);
118
127
  containsHostFunction |= frozenObject->containsHostFunction;
119
128
  if (RuntimeDecorator::isReactRuntime(rt) && !containsHostFunction) {
120
- addHiddenProperty(rt, createHost(rt, frozenObject), object, HIDDEN_HOST_OBJECT_PROP);
129
+ addHiddenProperty(
130
+ rt,
131
+ createHost(rt, frozenObject),
132
+ object,
133
+ HIDDEN_HOST_OBJECT_PROP);
121
134
  }
122
135
  }
123
136
  } else if (object.isArray(rt)) {
124
137
  type = ValueType::FrozenArrayType;
125
138
  auto array = object.asArray(rt);
126
139
  valueContainer = std::make_unique<FrozenArrayWrapper>();
127
- auto& frozenArray = ValueWrapper::asFrozenArray(valueContainer);
140
+ auto &frozenArray = ValueWrapper::asFrozenArray(valueContainer);
128
141
  for (size_t i = 0, size = array.size(rt); i < size; i++) {
129
142
  auto sv = adapt(rt, array.getValueAtIndex(rt, i), runtimeManager);
130
143
  containsHostFunction |= sv->containsHostFunction;
@@ -132,51 +145,63 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType
132
145
  }
133
146
  } else if (object.isHostObject<MutableValue>(rt)) {
134
147
  type = ValueType::MutableValueType;
135
- valueContainer = std::make_unique<MutableValueWrapper>(object.getHostObject<MutableValue>(rt));
148
+ valueContainer = std::make_unique<MutableValueWrapper>(
149
+ object.getHostObject<MutableValue>(rt));
136
150
  adaptCache(rt, value);
137
151
  } else if (object.isHostObject<RemoteObject>(rt)) {
138
152
  type = ValueType::RemoteObjectType;
139
153
  valueContainer = std::make_unique<RemoteObjectWrapper>(
140
- object.getHostObject<RemoteObject>(rt)
141
- );
154
+ object.getHostObject<RemoteObject>(rt));
142
155
  adaptCache(rt, value);
143
156
  } else if (objectType == ValueType::RemoteObjectType) {
144
157
  type = ValueType::RemoteObjectType;
145
- valueContainer = std::make_unique<RemoteObjectWrapper>(
146
- std::make_shared<RemoteObject>(rt, object, runtimeManager, runtimeManager->scheduler)
147
- );
158
+ valueContainer =
159
+ std::make_unique<RemoteObjectWrapper>(std::make_shared<RemoteObject>(
160
+ rt, object, runtimeManager, runtimeManager->scheduler));
148
161
  } else {
149
162
  // create frozen object based on a copy of a given object
150
163
  type = ValueType::FrozenObjectType;
151
164
  valueContainer = std::make_unique<FrozenObjectWrapper>(
152
- std::make_shared<FrozenObject>(rt, object, runtimeManager)
153
- );
154
- auto& frozenObject = ValueWrapper::asFrozenObject(valueContainer);
165
+ std::make_shared<FrozenObject>(rt, object, runtimeManager));
166
+ auto &frozenObject = ValueWrapper::asFrozenObject(valueContainer);
155
167
  containsHostFunction |= frozenObject->containsHostFunction;
156
168
  if (RuntimeDecorator::isReactRuntime(rt)) {
157
169
  if (!containsHostFunction) {
158
- addHiddenProperty(rt, createHost(rt, frozenObject), object, HIDDEN_HOST_OBJECT_PROP);
170
+ addHiddenProperty(
171
+ rt,
172
+ createHost(rt, frozenObject),
173
+ object,
174
+ HIDDEN_HOST_OBJECT_PROP);
159
175
  }
160
176
  freeze(rt, object);
161
177
  }
162
178
  }
163
179
  } else if (value.isSymbol()) {
164
180
  type = ValueType::StringType;
165
- valueContainer = std::make_unique<StringValueWrapper>(value.asSymbol(rt).toString(rt));
181
+ valueContainer =
182
+ std::make_unique<StringValueWrapper>(value.asSymbol(rt).toString(rt));
166
183
  } else {
167
184
  throw "Invalid value type";
168
185
  }
169
186
  }
170
187
 
171
- std::shared_ptr<ShareableValue> ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, RuntimeManager *runtimeManager, ValueType valueType) {
172
- auto sv = std::shared_ptr<ShareableValue>(new ShareableValue(runtimeManager, runtimeManager->scheduler));
188
+ std::shared_ptr<ShareableValue> ShareableValue::adapt(
189
+ jsi::Runtime &rt,
190
+ const jsi::Value &value,
191
+ RuntimeManager *runtimeManager,
192
+ ValueType valueType) {
193
+ auto sv = std::shared_ptr<ShareableValue>(
194
+ new ShareableValue(runtimeManager, runtimeManager->scheduler));
173
195
  sv->adapt(rt, value, valueType);
174
196
  return sv;
175
197
  }
176
198
 
177
199
  jsi::Value ShareableValue::getValue(jsi::Runtime &rt) {
178
- // TODO: maybe we can cache toJSValue results on a per-runtime basis, need to avoid ref loops
179
- if (RuntimeDecorator::isWorkletRuntime(rt)) {
200
+ // TODO: maybe we can cache toJSValue results on a per-runtime basis, need to
201
+ // avoid ref loops
202
+ if (&rt == runtimeManager->runtime.get()) {
203
+ // Getting value on the same runtime where it was created, prepare
204
+ // remoteValue
180
205
  if (remoteValue.expired()) {
181
206
  remoteValue = getWeakRef(rt);
182
207
  }
@@ -186,6 +211,8 @@ jsi::Value ShareableValue::getValue(jsi::Runtime &rt) {
186
211
  }
187
212
  return jsi::Value(rt, *remoteValue.lock());
188
213
  } else {
214
+ // Getting value on a different runtime than where it was created from,
215
+ // prepare hostValue
189
216
  if (hostValue.get() == nullptr) {
190
217
  hostValue = std::make_unique<jsi::Value>(toJSValue(rt));
191
218
  }
@@ -193,17 +220,23 @@ jsi::Value ShareableValue::getValue(jsi::Runtime &rt) {
193
220
  }
194
221
  }
195
222
 
196
- jsi::Object ShareableValue::createHost(jsi::Runtime &rt, std::shared_ptr<jsi::HostObject> host) {
223
+ jsi::Object ShareableValue::createHost(
224
+ jsi::Runtime &rt,
225
+ std::shared_ptr<jsi::HostObject> host) {
197
226
  return jsi::Object::createFromHostObject(rt, host);
198
227
  }
199
228
 
200
- jsi::Value createFrozenWrapper(jsi::Runtime &rt, std::shared_ptr<FrozenObject> frozenObject) {
201
- jsi::Object __reanimatedHiddenHost = jsi::Object::createFromHostObject(rt, frozenObject);
229
+ jsi::Value createFrozenWrapper(
230
+ jsi::Runtime &rt,
231
+ std::shared_ptr<FrozenObject> frozenObject) {
232
+ jsi::Object __reanimatedHiddenHost =
233
+ jsi::Object::createFromHostObject(rt, frozenObject);
202
234
  jsi::Object obj = frozenObject->shallowClone(rt);
203
235
  jsi::Object globalObject = rt.global().getPropertyAsObject(rt, "Object");
204
236
  jsi::Function freeze = globalObject.getPropertyAsFunction(rt, "freeze");
205
237
  if (!frozenObject->containsHostFunction) {
206
- addHiddenProperty(rt, std::move(__reanimatedHiddenHost), obj, HIDDEN_HOST_OBJECT_PROP);
238
+ addHiddenProperty(
239
+ rt, std::move(__reanimatedHiddenHost), obj, HIDDEN_HOST_OBJECT_PROP);
207
240
  addHiddenProperty(rt, true, obj, ALREADY_CONVERTED);
208
241
  }
209
242
  return freeze.call(rt, obj);
@@ -220,15 +253,15 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
220
253
  case ValueType::NumberType:
221
254
  return jsi::Value(ValueWrapper::asNumber(valueContainer));
222
255
  case ValueType::StringType: {
223
- auto& stringValue = ValueWrapper::asString(valueContainer);
256
+ auto &stringValue = ValueWrapper::asString(valueContainer);
224
257
  return jsi::Value(rt, jsi::String::createFromUtf8(rt, stringValue));
225
258
  }
226
259
  case ValueType::FrozenObjectType: {
227
- auto& frozenObject = ValueWrapper::asFrozenObject(valueContainer);
260
+ auto &frozenObject = ValueWrapper::asFrozenObject(valueContainer);
228
261
  return createFrozenWrapper(rt, frozenObject);
229
262
  }
230
263
  case ValueType::FrozenArrayType: {
231
- auto& frozenArray = ValueWrapper::asFrozenArray(valueContainer);
264
+ auto &frozenArray = ValueWrapper::asFrozenArray(valueContainer);
232
265
  jsi::Array array(rt, frozenArray.size());
233
266
  for (size_t i = 0; i < frozenArray.size(); i++) {
234
267
  array.setValueAtIndex(rt, i, frozenArray[i]->toJSValue(rt));
@@ -236,45 +269,50 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
236
269
  return array;
237
270
  }
238
271
  case ValueType::RemoteObjectType: {
239
- auto& remoteObject = ValueWrapper::asRemoteObject(valueContainer);
272
+ auto &remoteObject = ValueWrapper::asRemoteObject(valueContainer);
240
273
  if (RuntimeDecorator::isWorkletRuntime(rt)) {
241
274
  remoteObject->maybeInitializeOnWorkletRuntime(rt);
242
275
  }
243
276
  return createHost(rt, remoteObject);
244
277
  }
245
278
  case ValueType::MutableValueType: {
246
- auto& mutableObject = ValueWrapper::asMutableValue(valueContainer);
279
+ auto &mutableObject = ValueWrapper::asMutableValue(valueContainer);
247
280
  return createHost(rt, mutableObject);
248
281
  }
249
282
  case ValueType::HostFunctionType: {
250
- auto hostFunctionWrapper = ValueWrapper::asHostFunctionWrapper(valueContainer);
251
- auto& hostRuntime = hostFunctionWrapper->value->hostRuntime;
283
+ auto hostFunctionWrapper =
284
+ ValueWrapper::asHostFunctionWrapper(valueContainer);
285
+ auto &hostRuntime = hostFunctionWrapper->value->hostRuntime;
252
286
  if (hostRuntime == &rt) {
253
- // function is accessed from the same runtime it was crated, we just return same function obj
254
- return jsi::Value(rt, *hostFunctionWrapper->value->getPureFunction().get());
287
+ // function is accessed from the same runtime it was crated, we just
288
+ // return same function obj
289
+ return jsi::Value(
290
+ rt, *hostFunctionWrapper->value->getPureFunction().get());
255
291
  } else {
256
- // function is accessed from a different runtime, we wrap function in host func that'd enqueue
257
- // call on an appropriate thread
292
+ // function is accessed from a different runtime, we wrap function in
293
+ // host func that'd enqueue call on an appropriate thread
258
294
 
259
295
  auto runtimeManager = this->runtimeManager;
260
296
  auto hostFunction = hostFunctionWrapper->value;
261
297
 
262
298
  auto warnFunction = [runtimeManager, hostFunction](
263
- jsi::Runtime &rt,
264
- const jsi::Value &thisValue,
265
- const jsi::Value *args,
266
- size_t count
267
- ) -> jsi::Value {
268
-
299
+ jsi::Runtime &rt,
300
+ const jsi::Value &thisValue,
301
+ const jsi::Value *args,
302
+ size_t count) -> jsi::Value {
269
303
  jsi::Value jsThis = rt.global().getProperty(rt, "jsThis");
270
- std::string workletLocation = jsThis.asObject(rt).getProperty(rt, "__location").toString(rt).utf8(rt);
304
+ std::string workletLocation = jsThis.asObject(rt)
305
+ .getProperty(rt, "__location")
306
+ .toString(rt)
307
+ .utf8(rt);
271
308
  std::string exceptionMessage = "Tried to synchronously call ";
272
- if(hostFunction->functionName.empty()) {
309
+ if (hostFunction->functionName.empty()) {
273
310
  exceptionMessage += "anonymous function";
274
311
  } else {
275
312
  exceptionMessage += "function {" + hostFunction->functionName + "}";
276
313
  }
277
- exceptionMessage += " from a different thread.\n\nOccurred in worklet location: ";
314
+ exceptionMessage +=
315
+ " from a different thread.\n\nOccurred in worklet location: ";
278
316
  exceptionMessage += workletLocation;
279
317
  exceptionMessage += CALLBACK_ERROR_SUFFIX;
280
318
  runtimeManager->errorHandler->setError(exceptionMessage);
@@ -284,129 +322,151 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
284
322
  };
285
323
 
286
324
  auto clb = [runtimeManager, hostFunction, hostRuntime](
287
- jsi::Runtime &rt,
288
- const jsi::Value &thisValue,
289
- const jsi::Value *args,
290
- size_t count
291
- ) -> jsi::Value {
292
- // TODO: we should find thread based on runtime such that we could also call UI methods
293
- // from RN and not only RN methods from UI
325
+ jsi::Runtime &rt,
326
+ const jsi::Value &thisValue,
327
+ const jsi::Value *args,
328
+ size_t count) -> jsi::Value {
329
+ // TODO: we should find thread based on runtime such that we could
330
+ // also call UI methods from RN and not only RN methods from UI
294
331
 
295
332
  std::vector<std::shared_ptr<ShareableValue>> params;
296
333
  for (int i = 0; i < count; ++i) {
297
- params.push_back(ShareableValue::adapt(rt, args[i], runtimeManager));
334
+ params.push_back(
335
+ ShareableValue::adapt(rt, args[i], runtimeManager));
298
336
  }
299
337
 
300
338
  std::function<void()> job = [hostFunction, hostRuntime, params] {
301
- jsi::Value * args = new jsi::Value[params.size()];
339
+ jsi::Value *args = new jsi::Value[params.size()];
302
340
  for (int i = 0; i < params.size(); ++i) {
303
341
  args[i] = params[i]->getValue(*hostRuntime);
304
342
  }
305
- jsi::Value returnedValue = hostFunction->getPureFunction().get()->call(*hostRuntime,
306
- static_cast<const jsi::Value*>(args),
307
- (size_t)params.size());
343
+ jsi::Value returnedValue =
344
+ hostFunction->getPureFunction().get()->call(
345
+ *hostRuntime,
346
+ static_cast<const jsi::Value *>(args),
347
+ (size_t)params.size());
308
348
 
309
- delete [] args;
349
+ delete[] args;
310
350
  // ToDo use returned value to return promise
311
351
  };
312
352
 
313
353
  runtimeManager->scheduler->scheduleOnJS(job);
314
354
  return jsi::Value::undefined();
315
355
  };
316
- jsi::Function wrapperFunction = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "hostFunction"), 0, warnFunction);
317
- jsi::Function res = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "hostFunction"), 0, clb);
356
+ jsi::Function wrapperFunction = jsi::Function::createFromHostFunction(
357
+ rt, jsi::PropNameID::forAscii(rt, "hostFunction"), 0, warnFunction);
358
+ jsi::Function res = jsi::Function::createFromHostFunction(
359
+ rt, jsi::PropNameID::forAscii(rt, "hostFunction"), 0, clb);
318
360
  addHiddenProperty(rt, std::move(res), wrapperFunction, CALL_ASYNC);
319
- jsi::Object functionHandler = createHost(rt, hostFunctionWrapper->value);
320
- addHiddenProperty(rt, std::move(functionHandler), wrapperFunction, PRIMAL_FUNCTION);
361
+ jsi::Object functionHandler =
362
+ createHost(rt, hostFunctionWrapper->value);
363
+ addHiddenProperty(
364
+ rt, std::move(functionHandler), wrapperFunction, PRIMAL_FUNCTION);
321
365
  return wrapperFunction;
322
366
  }
323
367
  }
324
368
  case ValueType::WorkletFunctionType: {
325
369
  auto runtimeManager = this->runtimeManager;
326
- auto& frozenObject = ValueWrapper::asFrozenObject(this->valueContainer);
370
+ auto &frozenObject = ValueWrapper::asFrozenObject(this->valueContainer);
327
371
  if (RuntimeDecorator::isWorkletRuntime(rt)) {
328
372
  // when running on worklet thread we prep a function
329
373
 
330
- auto jsThis = std::make_shared<jsi::Object>(frozenObject->shallowClone(*runtimeManager->runtime));
331
- std::shared_ptr<jsi::Function> funPtr(runtimeManager->workletsCache->getFunction(rt, frozenObject));
374
+ auto jsThis = std::make_shared<jsi::Object>(
375
+ frozenObject->shallowClone(*runtimeManager->runtime));
376
+ std::shared_ptr<jsi::Function> funPtr(
377
+ runtimeManager->workletsCache->getFunction(rt, frozenObject));
332
378
  auto name = funPtr->getProperty(rt, "name").asString(rt).utf8(rt);
333
379
 
334
- auto clb = [=](
335
- jsi::Runtime &rt,
336
- const jsi::Value &thisValue,
337
- const jsi::Value *args,
338
- size_t count
339
- ) mutable -> jsi::Value {
340
- const jsi::String jsThisName = jsi::String::createFromAscii(rt, "jsThis");
341
- jsi::Object global = rt.global();
342
- jsi::Value oldJSThis = global.getProperty(rt, jsThisName);
343
- global.setProperty(rt, jsThisName, *jsThis); //set jsThis
344
-
345
- jsi::Value res = jsi::Value::undefined();
346
- try {
347
- if (thisValue.isObject()) {
348
- res = funPtr->callWithThis(rt, thisValue.asObject(rt), args, count);
349
- } else {
350
- res = funPtr->call(rt, args, count);
351
- }
352
- } catch(jsi::JSError &e) {
353
- throw e;
354
- } catch(...) {
355
- // TODO find out a way to get the error's message on hermes
356
- jsi::Value location = jsThis->getProperty(rt, "__location");
357
- std::string str = "Javascript worklet error";
358
- if (location.isString()) {
359
- str += "\nIn file: " + location.asString(rt).utf8(rt);
360
- }
361
- runtimeManager->errorHandler->setError(str);
362
- runtimeManager->errorHandler->raise();
380
+ auto clb = [=](jsi::Runtime &rt,
381
+ const jsi::Value &thisValue,
382
+ const jsi::Value *args,
383
+ size_t count) mutable -> jsi::Value {
384
+ const jsi::String jsThisName =
385
+ jsi::String::createFromAscii(rt, "jsThis");
386
+ jsi::Object global = rt.global();
387
+ jsi::Value oldJSThis = global.getProperty(rt, jsThisName);
388
+ global.setProperty(rt, jsThisName, *jsThis); // set jsThis
389
+
390
+ jsi::Value res = jsi::Value::undefined();
391
+ try {
392
+ if (thisValue.isObject()) {
393
+ res =
394
+ funPtr->callWithThis(rt, thisValue.asObject(rt), args, count);
395
+ } else {
396
+ res = funPtr->call(rt, args, count);
363
397
  }
364
- global.setProperty(rt, jsThisName, oldJSThis); //clean jsThis
365
- return res;
398
+ } catch (jsi::JSError &e) {
399
+ throw e;
400
+ } catch (...) {
401
+ if (demangleExceptionName(
402
+ abi::__cxa_current_exception_type()->name()) ==
403
+ "facebook::jsi::JSError") {
404
+ throw jsi::JSError(rt, "Javascript worklet error");
405
+ }
406
+ // TODO find out a way to get the error's message on hermes
407
+ jsi::Value location = jsThis->getProperty(rt, "__location");
408
+ std::string str = "Javascript worklet error";
409
+ if (location.isString()) {
410
+ str += "\nIn file: " + location.asString(rt).utf8(rt);
411
+ }
412
+ runtimeManager->errorHandler->setError(str);
413
+ runtimeManager->errorHandler->raise();
414
+ }
415
+ global.setProperty(rt, jsThisName, oldJSThis); // clean jsThis
416
+ return res;
366
417
  };
367
- return jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, name.c_str()), 0, clb);
418
+ return jsi::Function::createFromHostFunction(
419
+ rt, jsi::PropNameID::forAscii(rt, name.c_str()), 0, clb);
368
420
  } else {
369
421
  // when run outside of UI thread we enqueue a call on the UI thread
370
- auto clb = [=](
371
- jsi::Runtime &rt,
372
- const jsi::Value &thisValue,
373
- const jsi::Value *args,
374
- size_t count
375
- ) -> jsi::Value {
376
- // TODO: we should find thread based on runtime such that we could also call UI methods
377
- // from RN and not only RN methods from UI
422
+ auto clb = [=](jsi::Runtime &rt,
423
+ const jsi::Value &thisValue,
424
+ const jsi::Value *args,
425
+ size_t count) -> jsi::Value {
426
+ // TODO: we should find thread based on runtime such that we could
427
+ // also call UI methods from RN and not only RN methods from UI
378
428
 
379
429
  std::vector<std::shared_ptr<ShareableValue>> params;
380
430
  for (int i = 0; i < count; ++i) {
381
- params.push_back(ShareableValue::adapt(rt, args[i], runtimeManager));
431
+ params.push_back(
432
+ ShareableValue::adapt(rt, args[i], runtimeManager));
382
433
  }
383
434
 
384
435
  runtimeManager->scheduler->scheduleOnUI([=] {
385
436
  jsi::Runtime &rt = *runtimeManager->runtime.get();
386
437
  auto jsThis = createFrozenWrapper(rt, frozenObject).getObject(rt);
387
- auto code = jsThis.getProperty(rt, "asString").asString(rt).utf8(rt);
388
- std::shared_ptr<jsi::Function> funPtr(runtimeManager->workletsCache->getFunction(rt, frozenObject));
438
+ auto code =
439
+ jsThis.getProperty(rt, "asString").asString(rt).utf8(rt);
440
+ std::shared_ptr<jsi::Function> funPtr(
441
+ runtimeManager->workletsCache->getFunction(rt, frozenObject));
389
442
 
390
- jsi::Value * args = new jsi::Value[params.size()];
443
+ jsi::Value *args = new jsi::Value[params.size()];
391
444
  for (int i = 0; i < params.size(); ++i) {
392
445
  args[i] = params[i]->getValue(rt);
393
446
  }
394
447
 
395
448
  jsi::Value returnedValue;
396
- const jsi::String jsThisName = jsi::String::createFromAscii(rt, "jsThis");
449
+ const jsi::String jsThisName =
450
+ jsi::String::createFromAscii(rt, "jsThis");
397
451
  jsi::Object global = rt.global();
398
452
  jsi::Value oldJSThis = global.getProperty(rt, jsThisName);
399
- global.setProperty(rt, jsThisName, jsThis); //set jsThis
453
+ global.setProperty(rt, jsThisName, jsThis); // set jsThis
400
454
  try {
401
- returnedValue = funPtr->call(rt,
402
- static_cast<const jsi::Value*>(args),
403
- (size_t)params.size());
455
+ returnedValue = funPtr->call(
456
+ rt,
457
+ static_cast<const jsi::Value *>(args),
458
+ (size_t)params.size());
404
459
 
405
- } catch(std::exception &e) {
460
+ } catch (std::exception &e) {
406
461
  std::string str = e.what();
407
462
  runtimeManager->errorHandler->setError(str);
408
463
  runtimeManager->errorHandler->raise();
409
- } catch(...) {
464
+ } catch (...) {
465
+ if (demangleExceptionName(
466
+ abi::__cxa_current_exception_type()->name()) ==
467
+ "facebook::jsi::JSError") {
468
+ throw jsi::JSError(rt, "Javascript worklet error");
469
+ }
410
470
  // TODO find out a way to get the error's message on hermes
411
471
  jsi::Value location = jsThis.getProperty(rt, "__location");
412
472
  std::string str = "Javascript worklet error";
@@ -416,14 +476,15 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
416
476
  runtimeManager->errorHandler->setError(str);
417
477
  runtimeManager->errorHandler->raise();
418
478
  }
419
- global.setProperty(rt, jsThisName, oldJSThis); //clean jsThis
479
+ global.setProperty(rt, jsThisName, oldJSThis); // clean jsThis
420
480
 
421
- delete [] args;
481
+ delete[] args;
422
482
  // ToDo use returned value to return promise
423
483
  });
424
484
  return jsi::Value::undefined();
425
485
  };
426
- return jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "_workletFunction"), 0, clb);
486
+ return jsi::Function::createFromHostFunction(
487
+ rt, jsi::PropNameID::forAscii(rt, "_workletFunction"), 0, clb);
427
488
  }
428
489
  }
429
490
  default: {
@@ -433,4 +494,16 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
433
494
  throw "convert error";
434
495
  }
435
496
 
497
+ std::string ShareableValue::demangleExceptionName(std::string toDemangle) {
498
+ int status = 0;
499
+ char *buff =
500
+ __cxxabiv1::__cxa_demangle(toDemangle.c_str(), nullptr, nullptr, &status);
501
+ if (!buff) {
502
+ return toDemangle;
503
+ }
504
+ std::string demangled = buff;
505
+ std::free(buff);
506
+ return demangled;
436
507
  }
508
+
509
+ } // namespace reanimated