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,20 +1,28 @@
1
1
  #include "JSIStoreValueUser.h"
2
2
  #include "RuntimeManager.h"
3
+ #ifdef ONANDROID
4
+ #include <AndroidScheduler.h>
5
+ #endif
3
6
 
4
7
  namespace reanimated {
5
8
 
6
9
  std::weak_ptr<jsi::Value> StoreUser::getWeakRef(jsi::Runtime &rt) {
7
10
  const std::lock_guard<std::recursive_mutex> lock(storeUserData->storeMutex);
8
11
  if (storeUserData->store.count(identifier) == 0) {
9
- storeUserData->store[identifier] = std::vector<std::shared_ptr<jsi::Value>>();
12
+ storeUserData->store[identifier] =
13
+ std::vector<std::shared_ptr<jsi::Value>>();
10
14
  }
11
- std::shared_ptr<jsi::Value> sv = std::make_shared<jsi::Value>(rt, jsi::Value::undefined());
15
+ std::shared_ptr<jsi::Value> sv =
16
+ std::make_shared<jsi::Value>(rt, jsi::Value::undefined());
12
17
  storeUserData->store[identifier].push_back(sv);
13
-
18
+
14
19
  return sv;
15
20
  }
16
21
 
17
- StoreUser::StoreUser(std::shared_ptr<Scheduler> s, RuntimeManager &runtimeManager): scheduler(s) {
22
+ StoreUser::StoreUser(
23
+ std::shared_ptr<Scheduler> s,
24
+ const RuntimeManager &runtimeManager)
25
+ : scheduler(s) {
18
26
  storeUserData = runtimeManager.storeUserData;
19
27
  identifier = storeUserData->ctr++;
20
28
  }
@@ -24,13 +32,24 @@ StoreUser::~StoreUser() {
24
32
  std::shared_ptr<Scheduler> strongScheduler = scheduler.lock();
25
33
  if (strongScheduler != nullptr) {
26
34
  std::shared_ptr<StaticStoreUser> sud = storeUserData;
35
+ #ifdef ONANDROID
36
+ jni::ThreadScope::WithClassLoader([&] {
37
+ strongScheduler->scheduleOnUI([id, sud]() {
38
+ const std::lock_guard<std::recursive_mutex> lock(sud->storeMutex);
39
+ if (sud->store.count(id) > 0) {
40
+ sud->store.erase(id);
41
+ }
42
+ });
43
+ });
44
+ #else
27
45
  strongScheduler->scheduleOnUI([id, sud]() {
28
46
  const std::lock_guard<std::recursive_mutex> lock(sud->storeMutex);
29
47
  if (sud->store.count(id) > 0) {
30
- sud->store.erase(id);
48
+ sud->store.erase(id);
31
49
  }
32
50
  });
51
+ #endif
33
52
  }
34
53
  }
35
54
 
36
- }
55
+ } // namespace reanimated
@@ -1,20 +1,16 @@
1
1
  #include "Mapper.h"
2
- #include "SharedParent.h"
3
2
  #include "MutableValue.h"
3
+ #include "SharedParent.h"
4
4
 
5
5
  namespace reanimated {
6
6
 
7
- Mapper::Mapper(NativeReanimatedModule *module,
8
- unsigned long id,
9
- std::shared_ptr<jsi::Function> mapper,
10
- std::vector<std::shared_ptr<MutableValue>> inputs,
11
- std::vector<std::shared_ptr<MutableValue>> outputs):
12
- id(id),
13
- module(module),
14
- mapper(mapper),
15
- inputs(inputs),
16
- outputs(outputs)
17
- {
7
+ Mapper::Mapper(
8
+ NativeReanimatedModule *module,
9
+ unsigned long id,
10
+ std::shared_ptr<jsi::Function> mapper,
11
+ std::vector<std::shared_ptr<MutableValue>> inputs,
12
+ std::vector<std::shared_ptr<MutableValue>> outputs)
13
+ : id(id), module(module), mapper(mapper), inputs(inputs), outputs(outputs) {
18
14
  auto markDirty = [this, module]() {
19
15
  this->dirty = true;
20
16
  module->maybeRequestRender();
@@ -26,36 +22,40 @@ outputs(outputs)
26
22
 
27
23
  void Mapper::execute(jsi::Runtime &rt) {
28
24
  dirty = false;
29
- if(optimalizationLvl == 0) {
25
+ if (optimalizationLvl == 0) {
30
26
  mapper->callWithThis(rt, *mapper); // call styleUpdater
31
- }
32
- else {
27
+ } else {
33
28
  jsi::Object newStyle = userUpdater->call(rt).asObject(rt);
34
29
  auto jsViewDescriptorArray = viewDescriptors->getValue(rt)
35
- .getObject(rt)
36
- .getProperty(rt, "value")
37
- .asObject(rt)
38
- .getArray(rt);
39
- for(int i = 0; i < jsViewDescriptorArray.length(rt); ++i) {
40
- auto jsViewDescriptor = jsViewDescriptorArray.getValueAtIndex(rt, i).getObject(rt);
41
- (*updateProps)(rt, (int)jsViewDescriptor.getProperty(rt, "tag").asNumber(), jsViewDescriptor.getProperty(rt, "name"), newStyle);
30
+ .getObject(rt)
31
+ .getProperty(rt, "value")
32
+ .asObject(rt)
33
+ .getArray(rt);
34
+ for (int i = 0; i < jsViewDescriptorArray.length(rt); ++i) {
35
+ auto jsViewDescriptor =
36
+ jsViewDescriptorArray.getValueAtIndex(rt, i).getObject(rt);
37
+ (*updateProps)(
38
+ rt,
39
+ static_cast<int>(jsViewDescriptor.getProperty(rt, "tag").asNumber()),
40
+ jsViewDescriptor.getProperty(rt, "name"),
41
+ newStyle);
42
42
  }
43
43
  }
44
44
  }
45
45
 
46
46
  void Mapper::enableFastMode(
47
- const int optimalizationLvl,
48
- const std::shared_ptr<ShareableValue>& updater,
49
- const std::shared_ptr<ShareableValue>& jsViewDescriptors
50
- ) {
51
- if(optimalizationLvl == 0) {
47
+ const int optimalizationLvl,
48
+ const std::shared_ptr<ShareableValue> &updater,
49
+ const std::shared_ptr<ShareableValue> &jsViewDescriptors) {
50
+ if (optimalizationLvl == 0) {
52
51
  return;
53
52
  }
54
53
  viewDescriptors = jsViewDescriptors;
55
54
  this->optimalizationLvl = optimalizationLvl;
56
55
  updateProps = &module->updaterFunction;
57
- jsi::Runtime* rt = module->runtime.get();
58
- userUpdater = std::make_shared<jsi::Function>(updater->getValue(*rt).asObject(*rt).asFunction(*rt));
56
+ jsi::Runtime *rt = module->runtime.get();
57
+ userUpdater = std::make_shared<jsi::Function>(
58
+ updater->getValue(*rt).asObject(*rt).asFunction(*rt));
59
59
  }
60
60
 
61
61
  Mapper::~Mapper() {
@@ -64,4 +64,4 @@ Mapper::~Mapper() {
64
64
  }
65
65
  }
66
66
 
67
- }
67
+ } // namespace reanimated
@@ -1,45 +1,57 @@
1
1
  #include "RuntimeDecorator.h"
2
- #include "ReanimatedHiddenHeaders.h"
3
- #include <unordered_map>
4
2
  #include <memory>
5
- #include "MutableValue.h"
3
+ #include <unordered_map>
6
4
  #include "LayoutAnimationsProxy.h"
5
+ #include "MutableValue.h"
6
+ #include "ReanimatedHiddenHeaders.h"
7
7
 
8
8
  namespace reanimated {
9
9
 
10
- std::unordered_map<RuntimePointer, RuntimeType> RuntimeDecorator::runtimeRegistry;
11
- void RuntimeDecorator::registerRuntime(jsi::Runtime *runtime, RuntimeType runtimeType) {
12
- runtimeRegistry.insert({ runtime, runtimeType });
10
+ std::unordered_map<RuntimePointer, RuntimeType>
11
+ &RuntimeDecorator::runtimeRegistry() {
12
+ static std::unordered_map<RuntimePointer, RuntimeType> runtimeRegistry;
13
+ return runtimeRegistry;
14
+ }
15
+
16
+ void RuntimeDecorator::registerRuntime(
17
+ jsi::Runtime *runtime,
18
+ RuntimeType runtimeType) {
19
+ runtimeRegistry().insert({runtime, runtimeType});
13
20
  }
14
21
 
15
- void RuntimeDecorator::decorateRuntime(jsi::Runtime &rt, const std::string &label) {
16
- // This property will be used to find out if a runtime is a custom worklet runtime (e.g. UI, VisionCamera frame processor, ...)
22
+ void RuntimeDecorator::decorateRuntime(
23
+ jsi::Runtime &rt,
24
+ const std::string &label) {
25
+ // This property will be used to find out if a runtime is a custom worklet
26
+ // runtime (e.g. UI, VisionCamera frame processor, ...)
17
27
  rt.global().setProperty(rt, "_WORKLET", jsi::Value(true));
18
28
  // This property will be used for debugging
19
- rt.global().setProperty(rt, "_LABEL", jsi::String::createFromAscii(rt, label));
29
+ rt.global().setProperty(
30
+ rt, "_LABEL", jsi::String::createFromAscii(rt, label));
20
31
 
21
32
  jsi::Object dummyGlobal(rt);
22
- auto dummyFunction = [](
23
- jsi::Runtime &rt,
33
+ auto dummyFunction = [](jsi::Runtime &rt,
24
34
  const jsi::Value &thisValue,
25
35
  const jsi::Value *args,
26
- size_t count
27
- ) -> jsi::Value {
36
+ size_t count) -> jsi::Value {
28
37
  return jsi::Value::undefined();
29
38
  };
30
- jsi::Function __reanimatedWorkletInit = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "__reanimatedWorkletInit"), 1, dummyFunction);
31
-
32
- dummyGlobal.setProperty(rt, "__reanimatedWorkletInit", __reanimatedWorkletInit);
39
+ jsi::Function __reanimatedWorkletInit = jsi::Function::createFromHostFunction(
40
+ rt,
41
+ jsi::PropNameID::forAscii(rt, "__reanimatedWorkletInit"),
42
+ 1,
43
+ dummyFunction);
44
+
45
+ dummyGlobal.setProperty(
46
+ rt, "__reanimatedWorkletInit", __reanimatedWorkletInit);
33
47
  rt.global().setProperty(rt, "global", dummyGlobal);
34
48
 
35
49
  rt.global().setProperty(rt, "jsThis", jsi::Value::undefined());
36
50
 
37
- auto callback = [](
38
- jsi::Runtime &rt,
51
+ auto callback = [](jsi::Runtime &rt,
39
52
  const jsi::Value &thisValue,
40
53
  const jsi::Value *args,
41
- size_t count
42
- ) -> jsi::Value {
54
+ size_t count) -> jsi::Value {
43
55
  const jsi::Value *value = &args[0];
44
56
  if (value->isString()) {
45
57
  Logger::log(value->getString(rt).utf8(rt).c_str());
@@ -52,133 +64,144 @@ void RuntimeDecorator::decorateRuntime(jsi::Runtime &rt, const std::string &labe
52
64
  }
53
65
  return jsi::Value::undefined();
54
66
  };
55
- jsi::Value log = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "_log"), 1, callback);
67
+ jsi::Value log = jsi::Function::createFromHostFunction(
68
+ rt, jsi::PropNameID::forAscii(rt, "_log"), 1, callback);
56
69
  rt.global().setProperty(rt, "_log", log);
57
70
 
58
- auto setGlobalConsole = [](
59
- jsi::Runtime &rt,
71
+ auto setGlobalConsole = [](jsi::Runtime &rt,
60
72
  const jsi::Value &thisValue,
61
73
  const jsi::Value *args,
62
- size_t count
63
- ) -> jsi::Value {
74
+ size_t count) -> jsi::Value {
64
75
  rt.global().setProperty(rt, "console", args[0]);
65
76
  return jsi::Value::undefined();
66
77
  };
67
- rt.global().setProperty(rt, "_setGlobalConsole", jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "_setGlobalConsole"), 1, setGlobalConsole));
78
+ rt.global().setProperty(
79
+ rt,
80
+ "_setGlobalConsole",
81
+ jsi::Function::createFromHostFunction(
82
+ rt,
83
+ jsi::PropNameID::forAscii(rt, "_setGlobalConsole"),
84
+ 1,
85
+ setGlobalConsole));
68
86
  }
69
87
 
70
- void RuntimeDecorator::decorateUIRuntime(jsi::Runtime &rt,
71
- const UpdaterFunction updater,
72
- const RequestFrameFunction requestFrame,
73
- const ScrollToFunction scrollTo,
74
- const MeasuringFunction measure,
75
- const TimeProviderFunction getCurrentTime,
76
- std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy) {
88
+ void RuntimeDecorator::decorateUIRuntime(
89
+ jsi::Runtime &rt,
90
+ const UpdaterFunction updater,
91
+ const RequestFrameFunction requestFrame,
92
+ const ScrollToFunction scrollTo,
93
+ const MeasuringFunction measure,
94
+ const TimeProviderFunction getCurrentTime,
95
+ const SetGestureStateFunction setGestureState,
96
+ std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy) {
77
97
  RuntimeDecorator::decorateRuntime(rt, "UI");
78
98
  rt.global().setProperty(rt, "_UI", jsi::Value(true));
79
99
 
80
100
  auto clb = [updater](
81
- jsi::Runtime &rt,
82
- const jsi::Value &thisValue,
83
- const jsi::Value *args,
84
- const size_t count
85
- ) -> jsi::Value {
101
+ jsi::Runtime &rt,
102
+ const jsi::Value &thisValue,
103
+ const jsi::Value *args,
104
+ const size_t count) -> jsi::Value {
86
105
  const auto viewTag = args[0].asNumber();
87
- const jsi::Value* viewName = &args[1];
106
+ const jsi::Value *viewName = &args[1];
88
107
  const auto params = args[2].asObject(rt);
89
108
  updater(rt, viewTag, *viewName, params);
90
109
  return jsi::Value::undefined();
91
110
  };
92
- jsi::Value updateProps = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "_updateProps"), 2, clb);
111
+ jsi::Value updateProps = jsi::Function::createFromHostFunction(
112
+ rt, jsi::PropNameID::forAscii(rt, "_updateProps"), 2, clb);
93
113
  rt.global().setProperty(rt, "_updateProps", updateProps);
94
114
 
95
-
96
115
  auto clb2 = [requestFrame](
97
- jsi::Runtime &rt,
98
- const jsi::Value &thisValue,
99
- const jsi::Value *args,
100
- const size_t count
101
- ) -> jsi::Value {
102
- auto fun = std::make_shared<jsi::Function>(args[0].asObject(rt).asFunction(rt));
116
+ jsi::Runtime &rt,
117
+ const jsi::Value &thisValue,
118
+ const jsi::Value *args,
119
+ const size_t count) -> jsi::Value {
120
+ auto fun =
121
+ std::make_shared<jsi::Function>(args[0].asObject(rt).asFunction(rt));
103
122
  requestFrame([&rt, fun](double timestampMs) {
104
123
  fun->call(rt, jsi::Value(timestampMs));
105
124
  });
106
125
  return jsi::Value::undefined();
107
126
  };
108
- jsi::Value requestAnimationFrame = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "requestAnimationFrame"), 1, clb2);
127
+ jsi::Value requestAnimationFrame = jsi::Function::createFromHostFunction(
128
+ rt, jsi::PropNameID::forAscii(rt, "requestAnimationFrame"), 1, clb2);
109
129
  rt.global().setProperty(rt, "requestAnimationFrame", requestAnimationFrame);
110
130
 
111
131
  auto clb3 = [scrollTo](
112
- jsi::Runtime &rt,
113
- const jsi::Value &thisValue,
114
- const jsi::Value *args,
115
- const size_t count
116
- ) -> jsi::Value {
117
- int viewTag = (int)args[0].asNumber();
132
+ jsi::Runtime &rt,
133
+ const jsi::Value &thisValue,
134
+ const jsi::Value *args,
135
+ const size_t count) -> jsi::Value {
136
+ int viewTag = static_cast<int>(args[0].asNumber());
118
137
  double x = args[1].asNumber();
119
138
  double y = args[2].asNumber();
120
139
  bool animated = args[3].getBool();
121
140
  scrollTo(viewTag, x, y, animated);
122
141
  return jsi::Value::undefined();
123
142
  };
124
- jsi::Value scrollToFunction = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "_scrollTo"), 4, clb3);
143
+ jsi::Value scrollToFunction = jsi::Function::createFromHostFunction(
144
+ rt, jsi::PropNameID::forAscii(rt, "_scrollTo"), 4, clb3);
125
145
  rt.global().setProperty(rt, "_scrollTo", scrollToFunction);
126
146
 
127
147
  auto clb4 = [measure](
128
- jsi::Runtime &rt,
129
- const jsi::Value &thisValue,
130
- const jsi::Value *args,
131
- const size_t count
132
- ) -> jsi::Value {
133
- int viewTag = (int)args[0].asNumber();
148
+ jsi::Runtime &rt,
149
+ const jsi::Value &thisValue,
150
+ const jsi::Value *args,
151
+ const size_t count) -> jsi::Value {
152
+ int viewTag = static_cast<int>(args[0].asNumber());
134
153
  auto result = measure(viewTag);
135
154
  jsi::Object resultObject(rt);
136
- for (auto &i:result) {
155
+ for (auto &i : result) {
137
156
  resultObject.setProperty(rt, i.first.c_str(), i.second);
138
157
  }
139
158
  return resultObject;
140
159
  };
141
- jsi::Value measureFunction = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "_measure"), 1, clb4);
160
+ jsi::Value measureFunction = jsi::Function::createFromHostFunction(
161
+ rt, jsi::PropNameID::forAscii(rt, "_measure"), 1, clb4);
142
162
  rt.global().setProperty(rt, "_measure", measureFunction);
143
163
 
144
164
  auto clb6 = [getCurrentTime](
145
- jsi::Runtime &rt,
146
- const jsi::Value &thisValue,
147
- const jsi::Value *args,
148
- const size_t count
149
- ) -> jsi::Value {
165
+ jsi::Runtime &rt,
166
+ const jsi::Value &thisValue,
167
+ const jsi::Value *args,
168
+ const size_t count) -> jsi::Value {
150
169
  return getCurrentTime();
151
170
  };
152
- jsi::Value timeFun = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "_getCurrentTime"), 0, clb6);
171
+ jsi::Value timeFun = jsi::Function::createFromHostFunction(
172
+ rt, jsi::PropNameID::forAscii(rt, "_getCurrentTime"), 0, clb6);
153
173
  rt.global().setProperty(rt, "_getCurrentTime", timeFun);
154
174
 
155
175
  rt.global().setProperty(rt, "_frameTimestamp", jsi::Value::undefined());
156
176
  rt.global().setProperty(rt, "_eventTimestamp", jsi::Value::undefined());
157
-
177
+
158
178
  // layout animation
159
179
  std::weak_ptr<LayoutAnimationsProxy> layoutProxy = layoutAnimationsProxy;
160
180
  auto clb7 = [layoutProxy](
161
- jsi::Runtime &rt,
162
- const jsi::Value &thisValue,
163
- const jsi::Value *args,
164
- size_t count
165
- ) -> jsi::Value {
181
+ jsi::Runtime &rt,
182
+ const jsi::Value &thisValue,
183
+ const jsi::Value *args,
184
+ size_t count) -> jsi::Value {
166
185
  std::shared_ptr<LayoutAnimationsProxy> proxy = layoutProxy.lock();
167
186
  if (layoutProxy.expired()) {
168
187
  return jsi::Value::undefined();
169
188
  }
170
- proxy->startObserving(args[0].asNumber(), args[1].asObject(rt).getHostObject<MutableValue>(rt), rt);
189
+ proxy->startObserving(
190
+ args[0].asNumber(),
191
+ args[1].asObject(rt).getHostObject<MutableValue>(rt),
192
+ rt);
171
193
  return jsi::Value::undefined();
172
194
  };
173
- jsi::Value _startObservingProgress = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "_startObservingProgress"), 0, clb7);
174
- rt.global().setProperty(rt, "_startObservingProgress", _startObservingProgress);
175
-
195
+ jsi::Value _startObservingProgress = jsi::Function::createFromHostFunction(
196
+ rt, jsi::PropNameID::forAscii(rt, "_startObservingProgress"), 0, clb7);
197
+ rt.global().setProperty(
198
+ rt, "_startObservingProgress", _startObservingProgress);
199
+
176
200
  auto clb8 = [layoutProxy](
177
- jsi::Runtime &rt,
178
- const jsi::Value &thisValue,
179
- const jsi::Value *args,
180
- size_t count
181
- ) -> jsi::Value {
201
+ jsi::Runtime &rt,
202
+ const jsi::Value &thisValue,
203
+ const jsi::Value *args,
204
+ size_t count) -> jsi::Value {
182
205
  std::shared_ptr<LayoutAnimationsProxy> proxy = layoutProxy.lock();
183
206
  if (layoutProxy.expired()) {
184
207
  return jsi::Value::undefined();
@@ -186,8 +209,23 @@ void RuntimeDecorator::decorateUIRuntime(jsi::Runtime &rt,
186
209
  proxy->stopObserving(args[0].asNumber(), args[1].getBool());
187
210
  return jsi::Value::undefined();
188
211
  };
189
- jsi::Value _stopObservingProgress = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, "_stopObservingProgress"), 0, clb8);
212
+ jsi::Value _stopObservingProgress = jsi::Function::createFromHostFunction(
213
+ rt, jsi::PropNameID::forAscii(rt, "_stopObservingProgress"), 0, clb8);
190
214
  rt.global().setProperty(rt, "_stopObservingProgress", _stopObservingProgress);
191
- }
192
215
 
216
+ auto clb9 = [setGestureState](
217
+ jsi::Runtime &rt,
218
+ const jsi::Value &thisValue,
219
+ const jsi::Value *args,
220
+ size_t count) -> jsi::Value {
221
+ int handlerTag = static_cast<int>(args[0].asNumber());
222
+ int newState = static_cast<int>(args[1].asNumber());
223
+ setGestureState(handlerTag, newState);
224
+ return jsi::Value::undefined();
225
+ };
226
+ jsi::Value setGestureStateFunction = jsi::Function::createFromHostFunction(
227
+ rt, jsi::PropNameID::forAscii(rt, "_setGestureState"), 2, clb9);
228
+ rt.global().setProperty(rt, "_setGestureState", setGestureStateFunction);
193
229
  }
230
+
231
+ } // namespace reanimated
@@ -1,7 +1,6 @@
1
1
  #include "Scheduler.h"
2
2
 
3
- namespace reanimated
4
- {
3
+ namespace reanimated {
5
4
 
6
5
  void Scheduler::scheduleOnUI(std::function<void()> job) {
7
6
  uiJobs.push(std::move(job));
@@ -19,11 +18,13 @@ void Scheduler::triggerUI() {
19
18
  }
20
19
  }
21
20
 
22
- void Scheduler::setJSCallInvoker(std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker) {
21
+ void Scheduler::setJSCallInvoker(
22
+ std::shared_ptr<facebook::react::CallInvoker> jsCallInvoker) {
23
23
  jsCallInvoker_ = jsCallInvoker;
24
24
  }
25
25
 
26
- void Scheduler::setRuntimeManager(std::shared_ptr<RuntimeManager> runtimeManager) {
26
+ void Scheduler::setRuntimeManager(
27
+ std::shared_ptr<RuntimeManager> runtimeManager) {
27
28
  this->runtimeManager = runtimeManager;
28
29
  }
29
30
 
@@ -33,4 +34,4 @@ Scheduler::Scheduler() {
33
34
  this->scheduledOnUI = false;
34
35
  }
35
36
 
36
- }
37
+ } // namespace reanimated
@@ -2,8 +2,10 @@
2
2
 
3
3
  namespace reanimated {
4
4
 
5
- void WorkletEventHandler::process(jsi::Runtime &rt, jsi::Value &eventValue) {
5
+ void WorkletEventHandler::process(
6
+ jsi::Runtime &rt,
7
+ const jsi::Value &eventValue) {
6
8
  handler.callWithThis(rt, handler, eventValue);
7
9
  }
8
10
 
9
- }
11
+ } // namespace reanimated
@@ -1,10 +1,10 @@
1
1
  #pragma once
2
2
 
3
+ #include <jsi/jsi.h>
3
4
  #include <stdio.h>
4
- #include <memory>
5
5
  #include <functional>
6
6
  #include <map>
7
- #include <jsi/jsi.h>
7
+ #include <memory>
8
8
 
9
9
  namespace reanimated {
10
10
 
@@ -13,19 +13,20 @@ using namespace facebook;
13
13
  class MutableValue;
14
14
 
15
15
  class LayoutAnimationsProxy {
16
-
17
- public:
18
- LayoutAnimationsProxy(std::function<void(int, jsi::Object newProps)> _notifyAboutProgress, std::function<void(int, bool)> _notifyAboutEnd);
19
-
20
- void startObserving(int tag, std::shared_ptr<MutableValue> sv, jsi::Runtime &rt);
16
+ public:
17
+ LayoutAnimationsProxy(
18
+ std::function<void(int, jsi::Object newProps)> _notifyAboutProgress,
19
+ std::function<void(int, bool)> _notifyAboutEnd);
20
+
21
+ void
22
+ startObserving(int tag, std::shared_ptr<MutableValue> sv, jsi::Runtime &rt);
21
23
  void stopObserving(int tag, bool finished);
22
24
  void notifyAboutCancellation(int tag);
23
-
24
- private:
25
+
26
+ private:
25
27
  std::function<void(int, jsi::Object newProps)> notifyAboutProgress;
26
28
  std::function<void(int, bool)> notifyAboutEnd;
27
29
  std::map<int, std::shared_ptr<MutableValue>> observedValues;
28
30
  };
29
31
 
30
- }
31
-
32
+ } // namespace reanimated