react-native-reanimated 2.3.0-alpha.3 → 2.3.0-beta.4

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