react-native-reanimated 3.0.0-rc.7 → 3.0.0-rc.9

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 (207) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +32 -37
  2. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.h +4 -3
  3. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp +76 -0
  4. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h +41 -0
  5. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +168 -167
  6. package/Common/cpp/NativeModules/NativeReanimatedModule.h +36 -34
  7. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +22 -34
  8. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +13 -14
  9. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp +30 -0
  10. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h +1 -1
  11. package/Common/cpp/SharedItems/RuntimeManager.h +1 -34
  12. package/Common/cpp/SharedItems/Shareables.cpp +144 -0
  13. package/Common/cpp/SharedItems/Shareables.h +470 -0
  14. package/Common/cpp/Tools/PlatformDepMethodsHolder.h +6 -0
  15. package/Common/cpp/Tools/RuntimeDecorator.cpp +79 -50
  16. package/Common/cpp/Tools/RuntimeDecorator.h +13 -3
  17. package/Common/cpp/Tools/Scheduler.cpp +10 -0
  18. package/Common/cpp/Tools/SingleInstanceChecker.h +1 -1
  19. package/android/src/main/cpp/LayoutAnimations.cpp +6 -16
  20. package/android/src/main/cpp/LayoutAnimations.h +4 -4
  21. package/android/src/main/cpp/NativeProxy.cpp +50 -63
  22. package/ios/LayoutReanimation/REAAnimationsManager.h +3 -1
  23. package/ios/LayoutReanimation/REAAnimationsManager.m +49 -16
  24. package/ios/LayoutReanimation/REAUIManager.mm +22 -62
  25. package/ios/native/NativeProxy.mm +26 -42
  26. package/lib/commonjs/createAnimatedComponent.js +7 -11
  27. package/lib/commonjs/createAnimatedComponent.js.map +1 -1
  28. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +24 -25
  29. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  30. package/lib/commonjs/reanimated2/ViewDescriptorsSet.js +27 -55
  31. package/lib/commonjs/reanimated2/ViewDescriptorsSet.js.map +1 -1
  32. package/lib/commonjs/reanimated2/WorkletEventHandler.js +5 -3
  33. package/lib/commonjs/reanimated2/WorkletEventHandler.js.map +1 -1
  34. package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
  35. package/lib/commonjs/reanimated2/commonTypes.js +7 -0
  36. package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
  37. package/lib/commonjs/reanimated2/component/FlatList.js +19 -3
  38. package/lib/commonjs/reanimated2/component/FlatList.js.map +1 -1
  39. package/lib/commonjs/reanimated2/core.js +74 -240
  40. package/lib/commonjs/reanimated2/core.js.map +1 -1
  41. package/lib/commonjs/reanimated2/errors.js +66 -0
  42. package/lib/commonjs/reanimated2/errors.js.map +1 -0
  43. package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
  44. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +15 -9
  45. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  46. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +18 -8
  47. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
  48. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +27 -36
  49. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  50. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +23 -59
  51. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  52. package/lib/commonjs/reanimated2/hook/useSharedValue.js +3 -2
  53. package/lib/commonjs/reanimated2/hook/useSharedValue.js.map +1 -1
  54. package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
  55. package/lib/commonjs/reanimated2/initializers.js +157 -0
  56. package/lib/commonjs/reanimated2/initializers.js.map +1 -0
  57. package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
  58. package/lib/commonjs/reanimated2/jestUtils.js +8 -33
  59. package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
  60. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +14 -103
  61. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  62. package/lib/commonjs/reanimated2/js-reanimated/global.js +4 -7
  63. package/lib/commonjs/reanimated2/js-reanimated/global.js.map +1 -1
  64. package/lib/commonjs/reanimated2/js-reanimated/index.js +5 -0
  65. package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
  66. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  67. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  68. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +87 -0
  69. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -0
  70. package/lib/commonjs/reanimated2/layoutReanimation/index.js +1 -1
  71. package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
  72. package/lib/commonjs/reanimated2/mappers.js +186 -0
  73. package/lib/commonjs/reanimated2/mappers.js.map +1 -0
  74. package/lib/commonjs/reanimated2/mock.js +26 -0
  75. package/lib/commonjs/reanimated2/mock.js.map +1 -1
  76. package/lib/commonjs/reanimated2/mutables.js +173 -0
  77. package/lib/commonjs/reanimated2/mutables.js.map +1 -0
  78. package/lib/commonjs/reanimated2/shareables.js +159 -0
  79. package/lib/commonjs/reanimated2/shareables.js.map +1 -0
  80. package/lib/commonjs/reanimated2/threads.js +58 -0
  81. package/lib/commonjs/reanimated2/threads.js.map +1 -0
  82. package/lib/commonjs/reanimated2/time.js +55 -0
  83. package/lib/commonjs/reanimated2/time.js.map +1 -0
  84. package/lib/commonjs/reanimated2/valueSetter.js +81 -0
  85. package/lib/commonjs/reanimated2/valueSetter.js.map +1 -0
  86. package/lib/module/createAnimatedComponent.js +7 -12
  87. package/lib/module/createAnimatedComponent.js.map +1 -1
  88. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +24 -25
  89. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  90. package/lib/module/reanimated2/ViewDescriptorsSet.js +27 -53
  91. package/lib/module/reanimated2/ViewDescriptorsSet.js.map +1 -1
  92. package/lib/module/reanimated2/WorkletEventHandler.js +4 -3
  93. package/lib/module/reanimated2/WorkletEventHandler.js.map +1 -1
  94. package/lib/module/reanimated2/animation/util.js.map +1 -1
  95. package/lib/module/reanimated2/commonTypes.js +7 -0
  96. package/lib/module/reanimated2/commonTypes.js.map +1 -1
  97. package/lib/module/reanimated2/component/FlatList.js +18 -4
  98. package/lib/module/reanimated2/component/FlatList.js.map +1 -1
  99. package/lib/module/reanimated2/core.js +33 -226
  100. package/lib/module/reanimated2/core.js.map +1 -1
  101. package/lib/module/reanimated2/errors.js +58 -0
  102. package/lib/module/reanimated2/errors.js.map +1 -0
  103. package/lib/module/reanimated2/globals.d.js.map +1 -1
  104. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +16 -6
  105. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  106. package/lib/module/reanimated2/hook/useAnimatedRef.js +17 -8
  107. package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
  108. package/lib/module/reanimated2/hook/useAnimatedSensor.js +29 -34
  109. package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  110. package/lib/module/reanimated2/hook/useAnimatedStyle.js +26 -62
  111. package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  112. package/lib/module/reanimated2/hook/useSharedValue.js +3 -2
  113. package/lib/module/reanimated2/hook/useSharedValue.js.map +1 -1
  114. package/lib/module/reanimated2/hook/utils.js.map +1 -1
  115. package/lib/module/reanimated2/initializers.js +143 -0
  116. package/lib/module/reanimated2/initializers.js.map +1 -0
  117. package/lib/module/reanimated2/interpolateColor.js.map +1 -1
  118. package/lib/module/reanimated2/jestUtils.js +8 -31
  119. package/lib/module/reanimated2/jestUtils.js.map +1 -1
  120. package/lib/module/reanimated2/js-reanimated/JSReanimated.js +14 -98
  121. package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  122. package/lib/module/reanimated2/js-reanimated/global.js +4 -7
  123. package/lib/module/reanimated2/js-reanimated/global.js.map +1 -1
  124. package/lib/module/reanimated2/js-reanimated/index.js +5 -0
  125. package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
  126. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  127. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  128. package/lib/module/reanimated2/layoutReanimation/animationsManager.js +82 -0
  129. package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -0
  130. package/lib/module/reanimated2/layoutReanimation/index.js +1 -1
  131. package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
  132. package/lib/module/reanimated2/mappers.js +173 -0
  133. package/lib/module/reanimated2/mappers.js.map +1 -0
  134. package/lib/module/reanimated2/mock.js +26 -0
  135. package/lib/module/reanimated2/mock.js.map +1 -1
  136. package/lib/module/reanimated2/mutables.js +149 -0
  137. package/lib/module/reanimated2/mutables.js.map +1 -0
  138. package/lib/module/reanimated2/shareables.js +138 -0
  139. package/lib/module/reanimated2/shareables.js.map +1 -0
  140. package/lib/module/reanimated2/threads.js +45 -0
  141. package/lib/module/reanimated2/threads.js.map +1 -0
  142. package/lib/module/reanimated2/time.js +37 -0
  143. package/lib/module/reanimated2/time.js.map +1 -0
  144. package/lib/module/reanimated2/valueSetter.js +66 -0
  145. package/lib/module/reanimated2/valueSetter.js.map +1 -0
  146. package/package.json +3 -2
  147. package/plugin.js +112 -30
  148. package/src/createAnimatedComponent.tsx +8 -24
  149. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +43 -53
  150. package/src/reanimated2/ViewDescriptorsSet.ts +30 -69
  151. package/src/reanimated2/WorkletEventHandler.ts +4 -11
  152. package/src/reanimated2/animation/util.ts +1 -0
  153. package/src/reanimated2/commonTypes.ts +29 -4
  154. package/src/reanimated2/component/FlatList.tsx +30 -5
  155. package/src/reanimated2/core.ts +68 -258
  156. package/src/reanimated2/errors.ts +57 -0
  157. package/src/reanimated2/globals.d.ts +48 -29
  158. package/src/reanimated2/hook/useAnimatedKeyboard.ts +18 -9
  159. package/src/reanimated2/hook/useAnimatedRef.ts +27 -9
  160. package/src/reanimated2/hook/useAnimatedSensor.ts +33 -31
  161. package/src/reanimated2/hook/useAnimatedStyle.ts +26 -74
  162. package/src/reanimated2/hook/useSharedValue.ts +6 -3
  163. package/src/reanimated2/hook/utils.ts +1 -1
  164. package/src/reanimated2/initializers.ts +143 -0
  165. package/src/reanimated2/interpolateColor.ts +2 -2
  166. package/src/reanimated2/jestUtils.ts +14 -29
  167. package/src/reanimated2/js-reanimated/JSReanimated.ts +24 -94
  168. package/src/reanimated2/js-reanimated/global.ts +4 -7
  169. package/src/reanimated2/js-reanimated/index.ts +4 -0
  170. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +7 -0
  171. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -0
  172. package/src/reanimated2/layoutReanimation/animationsManager.ts +91 -0
  173. package/src/reanimated2/layoutReanimation/index.ts +1 -1
  174. package/src/reanimated2/mappers.ts +179 -0
  175. package/src/reanimated2/mock.ts +105 -0
  176. package/src/reanimated2/mutables.ts +151 -0
  177. package/src/reanimated2/shareables.ts +128 -0
  178. package/src/reanimated2/threads.ts +46 -0
  179. package/src/reanimated2/time.ts +30 -0
  180. package/src/reanimated2/valueSetter.ts +64 -0
  181. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +0 -127
  182. package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.h +0 -56
  183. package/Common/cpp/Registries/MapperRegistry.cpp +0 -147
  184. package/Common/cpp/Registries/MapperRegistry.h +0 -29
  185. package/Common/cpp/Registries/WorkletsCache.cpp +0 -45
  186. package/Common/cpp/Registries/WorkletsCache.h +0 -24
  187. package/Common/cpp/SharedItems/FrozenObject.cpp +0 -35
  188. package/Common/cpp/SharedItems/FrozenObject.h +0 -36
  189. package/Common/cpp/SharedItems/HostFunctionHandler.h +0 -28
  190. package/Common/cpp/SharedItems/MutableValue.cpp +0 -134
  191. package/Common/cpp/SharedItems/MutableValue.h +0 -54
  192. package/Common/cpp/SharedItems/MutableValueSetterProxy.cpp +0 -47
  193. package/Common/cpp/SharedItems/MutableValueSetterProxy.h +0 -25
  194. package/Common/cpp/SharedItems/RemoteObject.cpp +0 -45
  195. package/Common/cpp/SharedItems/RemoteObject.h +0 -35
  196. package/Common/cpp/SharedItems/ShareableValue.cpp +0 -529
  197. package/Common/cpp/SharedItems/ShareableValue.h +0 -63
  198. package/Common/cpp/SharedItems/ValueWrapper.h +0 -183
  199. package/Common/cpp/Tools/JSIStoreValueUser.cpp +0 -55
  200. package/Common/cpp/Tools/JSIStoreValueUser.h +0 -37
  201. package/Common/cpp/Tools/Mapper.cpp +0 -86
  202. package/Common/cpp/Tools/Mapper.h +0 -51
  203. package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -58
  204. package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +0 -1
  205. package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -52
  206. package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +0 -1
  207. package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.ts +0 -49
@@ -1,19 +1,17 @@
1
1
  #include "AnimatedSensorModule.h"
2
- #include "MutableValue.h"
3
- #include "ValueWrapper.h"
4
2
 
5
3
  #include <memory>
6
4
  #include <utility>
7
5
 
6
+ #include "Shareables.h"
7
+
8
8
  namespace reanimated {
9
9
 
10
10
  AnimatedSensorModule::AnimatedSensorModule(
11
- const PlatformDepMethodsHolder &platformDepMethodsHolder,
12
- RuntimeManager *runtimeManager)
11
+ const PlatformDepMethodsHolder &platformDepMethodsHolder)
13
12
  : platformRegisterSensorFunction_(platformDepMethodsHolder.registerSensor),
14
13
  platformUnregisterSensorFunction_(
15
- platformDepMethodsHolder.unregisterSensor),
16
- runtimeManager_(runtimeManager) {}
14
+ platformDepMethodsHolder.unregisterSensor) {}
17
15
 
18
16
  AnimatedSensorModule::~AnimatedSensorModule() {
19
17
  // It is called during app reload because app reload doesn't call hooks
@@ -25,41 +23,38 @@ AnimatedSensorModule::~AnimatedSensorModule() {
25
23
 
26
24
  jsi::Value AnimatedSensorModule::registerSensor(
27
25
  jsi::Runtime &rt,
28
- const jsi::Value &sensorType,
26
+ const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
27
+ const jsi::Value &sensorTypeValue,
29
28
  const jsi::Value &interval,
30
- const jsi::Value &sensorDataContainer) {
31
- std::shared_ptr<ShareableValue> sensorsData = ShareableValue::adapt(
32
- rt, sensorDataContainer.getObject(rt), runtimeManager_);
33
- auto &mutableObject =
34
- ValueWrapper::asMutableValue(sensorsData->valueContainer);
29
+ const jsi::Value &sensorDataHandler) {
30
+ SensorType sensorType = static_cast<SensorType>(sensorTypeValue.asNumber());
35
31
 
36
- std::function<void(double[])> setter;
37
- if (sensorType.asNumber() == SensorType::ROTATION_VECTOR) {
38
- setter = [&, mutableObject](double newValues[]) {
39
- jsi::Runtime &runtime = *runtimeManager_->runtime.get();
40
- jsi::Object value(runtime);
41
- value.setProperty(runtime, "qx", newValues[0]);
42
- value.setProperty(runtime, "qy", newValues[1]);
43
- value.setProperty(runtime, "qz", newValues[2]);
44
- value.setProperty(runtime, "qw", newValues[3]);
45
- value.setProperty(runtime, "yaw", newValues[4]);
46
- value.setProperty(runtime, "pitch", newValues[5]);
47
- value.setProperty(runtime, "roll", newValues[6]);
48
- mutableObject->setValue(runtime, std::move(value));
49
- };
50
- } else {
51
- setter = [&, mutableObject](double newValues[]) {
52
- jsi::Runtime &runtime = *runtimeManager_->runtime.get();
53
- jsi::Object value(runtime);
54
- value.setProperty(runtime, "x", newValues[0]);
55
- value.setProperty(runtime, "y", newValues[1]);
56
- value.setProperty(runtime, "z", newValues[2]);
57
- mutableObject->setValue(runtime, std::move(value));
58
- };
59
- }
32
+ auto shareableHandler = extractShareableOrThrow(rt, sensorDataHandler);
33
+ auto uiRuntime = runtimeHelper->uiRuntime();
60
34
 
61
35
  int sensorId = platformRegisterSensorFunction_(
62
- sensorType.asNumber(), interval.asNumber(), setter);
36
+ sensorType, interval.asNumber(), [=](double newValues[]) {
37
+ jsi::Runtime &rt = *uiRuntime;
38
+ auto handler =
39
+ shareableHandler->getJSValue(rt).asObject(rt).asFunction(rt);
40
+ if (sensorType == SensorType::ROTATION_VECTOR) {
41
+ jsi::Object value(rt);
42
+ value.setProperty(rt, "qx", newValues[0]);
43
+ value.setProperty(rt, "qy", newValues[1]);
44
+ value.setProperty(rt, "qz", newValues[2]);
45
+ value.setProperty(rt, "qw", newValues[3]);
46
+ value.setProperty(rt, "yaw", newValues[4]);
47
+ value.setProperty(rt, "pitch", newValues[5]);
48
+ value.setProperty(rt, "roll", newValues[6]);
49
+ handler.call(rt, value);
50
+ } else {
51
+ jsi::Object value(rt);
52
+ value.setProperty(rt, "x", newValues[0]);
53
+ value.setProperty(rt, "y", newValues[1]);
54
+ value.setProperty(rt, "z", newValues[2]);
55
+ handler.call(rt, value);
56
+ }
57
+ });
63
58
  if (sensorId != -1) {
64
59
  sensorsIds_.insert(sensorId);
65
60
  }
@@ -1,10 +1,12 @@
1
1
  #pragma once
2
2
 
3
3
  #include <jsi/jsi.h>
4
+ #include <memory>
4
5
  #include <unordered_set>
5
6
 
6
7
  #include "PlatformDepMethodsHolder.h"
7
8
  #include "RuntimeManager.h"
9
+ #include "Shareables.h"
8
10
 
9
11
  namespace reanimated {
10
12
 
@@ -22,16 +24,15 @@ class AnimatedSensorModule {
22
24
  std::unordered_set<int> sensorsIds_;
23
25
  RegisterSensorFunction platformRegisterSensorFunction_;
24
26
  UnregisterSensorFunction platformUnregisterSensorFunction_;
25
- RuntimeManager *runtimeManager_;
26
27
 
27
28
  public:
28
29
  AnimatedSensorModule(
29
- const PlatformDepMethodsHolder &platformDepMethodsHolder,
30
- RuntimeManager *runtimeManager);
30
+ const PlatformDepMethodsHolder &platformDepMethodsHolder);
31
31
  ~AnimatedSensorModule();
32
32
 
33
33
  jsi::Value registerSensor(
34
34
  jsi::Runtime &rt,
35
+ const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
35
36
  const jsi::Value &sensorType,
36
37
  const jsi::Value &interval,
37
38
  const jsi::Value &sensorDataContainer);
@@ -0,0 +1,76 @@
1
+ #include "LayoutAnimationsManager.h"
2
+ #include "Shareables.h"
3
+
4
+ #include <utility>
5
+
6
+ namespace reanimated {
7
+
8
+ void LayoutAnimationsManager::configureAnimation(
9
+ int tag,
10
+ const std::string &type,
11
+ std::shared_ptr<Shareable> config) {
12
+ auto lock = std::unique_lock<std::mutex>(animationsMutex_);
13
+ if (type == "entering") {
14
+ enteringAnimations_[tag] = config;
15
+ } else if (type == "exiting") {
16
+ exitingAnimations_[tag] = config;
17
+ } else if (type == "layout") {
18
+ layoutAnimations_[tag] = config;
19
+ }
20
+ }
21
+
22
+ bool LayoutAnimationsManager::hasLayoutAnimation(
23
+ int tag,
24
+ const std::string &type) {
25
+ auto lock = std::unique_lock<std::mutex>(animationsMutex_);
26
+ if (type == "entering") {
27
+ return enteringAnimations_.find(tag) != enteringAnimations_.end();
28
+ } else if (type == "exiting") {
29
+ return exitingAnimations_.find(tag) != exitingAnimations_.end();
30
+ } else if (type == "layout") {
31
+ return layoutAnimations_.find(tag) != layoutAnimations_.end();
32
+ }
33
+ return false;
34
+ }
35
+
36
+ void LayoutAnimationsManager::clearLayoutAnimationConfig(int tag) {
37
+ auto lock = std::unique_lock<std::mutex>(animationsMutex_);
38
+ enteringAnimations_.erase(tag);
39
+ exitingAnimations_.erase(tag);
40
+ layoutAnimations_.erase(tag);
41
+ }
42
+
43
+ void LayoutAnimationsManager::startLayoutAnimation(
44
+ jsi::Runtime &rt,
45
+ int tag,
46
+ const std::string &type,
47
+ const jsi::Object &values) {
48
+ std::shared_ptr<Shareable> config, viewShareable;
49
+ {
50
+ auto lock = std::unique_lock<std::mutex>(animationsMutex_);
51
+ if (type == "entering") {
52
+ config = enteringAnimations_[tag];
53
+ } else if (type == "exiting") {
54
+ config = exitingAnimations_[tag];
55
+ } else if (type == "layout") {
56
+ config = layoutAnimations_[tag];
57
+ }
58
+ }
59
+
60
+ // TODO: cache the following!!
61
+ jsi::Value layoutAnimationRepositoryAsValue =
62
+ rt.global()
63
+ .getPropertyAsObject(rt, "global")
64
+ .getProperty(rt, "LayoutAnimationsManager");
65
+ jsi::Function startAnimationForTag =
66
+ layoutAnimationRepositoryAsValue.getObject(rt).getPropertyAsFunction(
67
+ rt, "start");
68
+ startAnimationForTag.call(
69
+ rt,
70
+ jsi::Value(tag),
71
+ jsi::String::createFromAscii(rt, type),
72
+ values,
73
+ config->getJSValue(rt));
74
+ }
75
+
76
+ } // namespace reanimated
@@ -0,0 +1,41 @@
1
+ #pragma once
2
+
3
+ #include "ErrorHandler.h"
4
+ #include "Shareables.h"
5
+
6
+ #include <jsi/jsi.h>
7
+ #include <stdio.h>
8
+ #include <functional>
9
+ #include <memory>
10
+ #include <mutex>
11
+ #include <string>
12
+ #include <unordered_map>
13
+
14
+ namespace reanimated {
15
+
16
+ using namespace facebook;
17
+
18
+ class LayoutAnimationsManager {
19
+ public:
20
+ void configureAnimation(
21
+ int tag,
22
+ const std::string &type,
23
+ std::shared_ptr<Shareable> config);
24
+ bool hasLayoutAnimation(int tag, const std::string &type);
25
+ void startLayoutAnimation(
26
+ jsi::Runtime &rt,
27
+ int tag,
28
+ const std::string &type,
29
+ const jsi::Object &values);
30
+ void clearLayoutAnimationConfig(int tag);
31
+
32
+ private:
33
+ std::unordered_map<int, std::shared_ptr<Shareable>> enteringAnimations_;
34
+ std::unordered_map<int, std::shared_ptr<Shareable>> exitingAnimations_;
35
+ std::unordered_map<int, std::shared_ptr<Shareable>> layoutAnimations_;
36
+ mutable std::mutex
37
+ animationsMutex_; // Protects `enteringAnimations_`, `exitingAnimations_`,
38
+ // `layoutAnimations_` and `viewSharedValues_`.
39
+ };
40
+
41
+ } // namespace reanimated