react-native-reanimated 2.3.0-beta.2 → 2.3.1

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 (168) hide show
  1. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +12 -3
  2. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +13 -0
  3. package/Common/cpp/Registries/EventHandlerRegistry.cpp +2 -2
  4. package/Common/cpp/Registries/MapperRegistry.cpp +5 -5
  5. package/Common/cpp/SharedItems/FrozenObject.cpp +1 -3
  6. package/Common/cpp/SharedItems/ShareableValue.cpp +8 -10
  7. package/Common/cpp/Tools/FeaturesConfig.cpp +5 -0
  8. package/Common/cpp/Tools/JSIStoreValueUser.cpp +8 -8
  9. package/Common/cpp/Tools/Mapper.cpp +1 -1
  10. package/Common/cpp/Tools/RuntimeDecorator.cpp +40 -4
  11. package/Common/cpp/Tools/WorkletEventHandler.cpp +3 -1
  12. package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +5 -0
  13. package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +6 -1
  14. package/Common/cpp/headers/Registries/EventHandlerRegistry.h +1 -0
  15. package/Common/cpp/headers/Registries/MapperRegistry.h +1 -0
  16. package/Common/cpp/headers/SharedItems/FrozenObject.h +4 -0
  17. package/Common/cpp/headers/SharedItems/HostFunctionHandler.h +2 -0
  18. package/Common/cpp/headers/SharedItems/MutableValue.h +2 -0
  19. package/Common/cpp/headers/SharedItems/MutableValueSetterProxy.h +3 -1
  20. package/Common/cpp/headers/SharedItems/RemoteObject.h +4 -1
  21. package/Common/cpp/headers/SharedItems/ShareableValue.h +2 -0
  22. package/Common/cpp/headers/SharedItems/SharedParent.h +9 -9
  23. package/Common/cpp/headers/SharedItems/ValueWrapper.h +32 -28
  24. package/Common/cpp/headers/SpecTools/ErrorHandler.h +1 -0
  25. package/Common/cpp/headers/Tools/FeaturesConfig.h +19 -0
  26. package/Common/cpp/headers/Tools/JSIStoreValueUser.h +2 -5
  27. package/Common/cpp/headers/Tools/Mapper.h +2 -0
  28. package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +5 -0
  29. package/Common/cpp/headers/Tools/ReanimatedHiddenHeaders.h +1 -5
  30. package/Common/cpp/headers/Tools/RuntimeDecorator.h +10 -7
  31. package/Common/cpp/headers/Tools/Scheduler.h +2 -0
  32. package/Common/cpp/headers/Tools/WorkletEventHandler.h +2 -1
  33. package/Common/cpp/hidden_headers/Logger.h +2 -2
  34. package/Common/cpp/hidden_headers/LoggerInterface.h +1 -1
  35. package/README.md +1 -1
  36. package/RNReanimated.podspec +21 -3
  37. package/android/build.gradle +33 -13
  38. package/android/expo/linking.gradle +46 -0
  39. package/android/expo/src/main/java/com/swmansion/reanimated/EXReanimatedAdapter.java +12 -0
  40. package/android/expo/src/main/java/expo/modules/adapters/reanimated/EXReanimatedPackage.java +26 -0
  41. package/android/react-native-reanimated-63-hermes.aar +0 -0
  42. package/android/react-native-reanimated-63-jsc.aar +0 -0
  43. package/android/react-native-reanimated-64-hermes.aar +0 -0
  44. package/android/react-native-reanimated-64-jsc.aar +0 -0
  45. package/android/react-native-reanimated-65-hermes.aar +0 -0
  46. package/android/react-native-reanimated-65-jsc.aar +0 -0
  47. package/android/react-native-reanimated-66-hermes.aar +0 -0
  48. package/android/react-native-reanimated-66-jsc.aar +0 -0
  49. package/android/react-native-reanimated-67-hermes.aar +0 -0
  50. package/android/react-native-reanimated-67-jsc.aar +0 -0
  51. package/expo-module.config.json +3 -0
  52. package/ios/LayoutReanimation/REAAnimationsManager.m +65 -19
  53. package/ios/LayoutReanimation/REAUIManager.mm +101 -61
  54. package/ios/Nodes/REAPropsNode.m +1 -1
  55. package/ios/REAEventDispatcher.m +1 -1
  56. package/ios/REAModule.h +0 -2
  57. package/ios/REAModule.m +0 -3
  58. package/ios/REANodesManager.m +1 -0
  59. package/ios/RNGestureHandlerStateManager.h +5 -0
  60. package/ios/native/NativeMethods.h +5 -0
  61. package/ios/native/NativeMethods.mm +14 -6
  62. package/ios/native/NativeProxy.h +1 -0
  63. package/ios/native/NativeProxy.mm +84 -63
  64. package/ios/native/REAIOSErrorHandler.mm +19 -15
  65. package/ios/native/REAIOSLogger.mm +10 -6
  66. package/ios/native/REAIOSScheduler.mm +17 -10
  67. package/ios/native/REAInitializer.mm +39 -37
  68. package/ios/native/UIResponder+Reanimated.mm +2 -2
  69. package/lib/Animated.js +11 -5
  70. package/lib/ConfigHelper.js +121 -138
  71. package/lib/ReanimatedEventEmitter.js +0 -1
  72. package/lib/ReanimatedModule.js +0 -1
  73. package/lib/ReanimatedModule.macos.js +0 -1
  74. package/lib/ReanimatedModule.native.js +5 -6
  75. package/lib/ReanimatedModule.windows.js +0 -1
  76. package/lib/ReanimatedModuleCompat.js +64 -35
  77. package/lib/createAnimatedComponent.js +469 -499
  78. package/lib/index.js +11 -5
  79. package/lib/reanimated1/core/Core.test.js +1 -1
  80. package/lib/reanimated2/NativeMethods.js +7 -0
  81. package/lib/reanimated2/NativeReanimated/NativeReanimated.js +3 -0
  82. package/lib/reanimated2/PropAdapters.js +0 -1
  83. package/lib/reanimated2/UpdateProps.js +1 -1
  84. package/lib/reanimated2/ViewDescriptorsSet.js +4 -2
  85. package/lib/reanimated2/animation/spring.js +2 -0
  86. package/lib/reanimated2/animation/styleAnimation.js +5 -1
  87. package/lib/reanimated2/animation/util.js +23 -0
  88. package/lib/reanimated2/component/FlatList.js +30 -0
  89. package/lib/reanimated2/component/WrappedComponents.js +9 -0
  90. package/lib/reanimated2/component/index.js +4 -0
  91. package/lib/reanimated2/core.js +34 -6
  92. package/lib/reanimated2/globals.d.ts +8 -0
  93. package/lib/reanimated2/js-reanimated/JSReanimated.js +4 -0
  94. package/lib/reanimated2/js-reanimated/Mapper.js +4 -3
  95. package/lib/reanimated2/js-reanimated/MapperRegistry.js +3 -6
  96. package/lib/reanimated2/js-reanimated/MutableValue.js +0 -2
  97. package/lib/reanimated2/js-reanimated/index.js +10 -8
  98. package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +14 -5
  99. package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +14 -14
  100. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +8 -8
  101. package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +16 -16
  102. package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +16 -16
  103. package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +4 -4
  104. package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +20 -8
  105. package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +3 -3
  106. package/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +8 -8
  107. package/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +10 -10
  108. package/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +8 -8
  109. package/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +8 -8
  110. package/lib/reanimated2/mock.js +3 -1
  111. package/lib/setAndForwardRef.js +14 -48
  112. package/mock.js +1 -1
  113. package/package.json +27 -23
  114. package/plugin.js +111 -110
  115. package/react-native-reanimated.d.ts +56 -27
  116. package/src/Animated.js +11 -5
  117. package/src/{ConfigHelper.js → ConfigHelper.ts} +15 -7
  118. package/src/{ReanimatedEventEmitter.js → ReanimatedEventEmitter.ts} +0 -0
  119. package/src/{ReanimatedModule.js → ReanimatedModule.macos.ts} +0 -0
  120. package/src/{ReanimatedModule.native.js → ReanimatedModule.native.ts} +0 -0
  121. package/src/{ReanimatedModule.macos.js → ReanimatedModule.ts} +0 -0
  122. package/src/{ReanimatedModule.windows.js → ReanimatedModule.windows.ts} +0 -0
  123. package/src/ReanimatedModuleCompat.ts +51 -0
  124. package/src/{createAnimatedComponent.js → createAnimatedComponent.tsx} +278 -124
  125. package/src/reanimated1/core/Core.test.js +1 -1
  126. package/src/reanimated2/NativeMethods.ts +13 -1
  127. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +5 -11
  128. package/src/reanimated2/PropAdapters.ts +0 -1
  129. package/src/reanimated2/UpdateProps.ts +1 -1
  130. package/src/reanimated2/ViewDescriptorsSet.ts +6 -2
  131. package/src/reanimated2/animation/commonTypes.ts +4 -4
  132. package/src/reanimated2/animation/decay.ts +2 -2
  133. package/src/reanimated2/animation/delay.ts +3 -3
  134. package/src/reanimated2/animation/index.ts +7 -7
  135. package/src/reanimated2/animation/repeat.ts +4 -4
  136. package/src/reanimated2/animation/sequence.ts +2 -2
  137. package/src/reanimated2/animation/spring.ts +6 -5
  138. package/src/reanimated2/animation/styleAnimation.ts +24 -12
  139. package/src/reanimated2/animation/timing.ts +5 -5
  140. package/src/reanimated2/animation/util.ts +45 -6
  141. package/src/reanimated2/component/FlatList.tsx +44 -0
  142. package/src/reanimated2/component/WrappedComponents.ts +11 -0
  143. package/src/reanimated2/component/index.ts +9 -0
  144. package/src/reanimated2/core.ts +62 -17
  145. package/src/reanimated2/globals.d.ts +8 -0
  146. package/src/reanimated2/hook/useAnimatedStyle.ts +2 -2
  147. package/src/reanimated2/js-reanimated/JSReanimated.ts +15 -26
  148. package/src/reanimated2/js-reanimated/Mapper.ts +22 -9
  149. package/src/reanimated2/js-reanimated/MapperRegistry.ts +22 -19
  150. package/src/reanimated2/js-reanimated/MutableValue.ts +11 -11
  151. package/src/reanimated2/js-reanimated/index.ts +31 -14
  152. package/src/reanimated2/layoutReanimation/{LayoutAnimationRepository.tsx → LayoutAnimationRepository.ts} +18 -5
  153. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +39 -20
  154. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +5 -1
  155. package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +21 -15
  156. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +29 -24
  157. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +61 -34
  158. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +49 -34
  159. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +17 -12
  160. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +20 -8
  161. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +9 -9
  162. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +8 -8
  163. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +20 -14
  164. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +14 -8
  165. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +24 -12
  166. package/src/reanimated2/mock.ts +3 -1
  167. package/src/{setAndForwardRef.js → setAndForwardRef.ts} +12 -2
  168. package/src/ReanimatedModuleCompat.js +0 -37
@@ -3,6 +3,7 @@
3
3
  #include <memory>
4
4
  #include <thread>
5
5
  #include "EventHandlerRegistry.h"
6
+ #include "FeaturesConfig.h"
6
7
  #include "FrozenObject.h"
7
8
  #include "JSIStoreValueUser.h"
8
9
  #include "Mapper.h"
@@ -84,6 +85,7 @@ NativeReanimatedModule::NativeReanimatedModule(
84
85
  platformDepMethodsHolder.scrollToFunction,
85
86
  platformDepMethodsHolder.measuringFunction,
86
87
  platformDepMethodsHolder.getCurrentTime,
88
+ platformDepMethodsHolder.setGestureStateFunction,
87
89
  layoutAnimationsProxy);
88
90
  onRenderCallback = [this](double timestampMs) {
89
91
  this->renderRequested = false;
@@ -164,7 +166,7 @@ jsi::Value NativeReanimatedModule::startMapper(
164
166
  maybeRequestRender();
165
167
  });
166
168
 
167
- return jsi::Value((double)newMapperId);
169
+ return jsi::Value(static_cast<double>(newMapperId));
168
170
  }
169
171
 
170
172
  void NativeReanimatedModule::stopMapper(
@@ -196,7 +198,7 @@ jsi::Value NativeReanimatedModule::registerEventHandler(
196
198
  eventHandlerRegistry->registerEventHandler(handler);
197
199
  });
198
200
 
199
- return jsi::Value((double)newRegistrationId);
201
+ return jsi::Value(static_cast<double>(newRegistrationId));
200
202
  }
201
203
 
202
204
  void NativeReanimatedModule::unregisterEventHandler(
@@ -212,7 +214,7 @@ jsi::Value NativeReanimatedModule::getViewProp(
212
214
  const jsi::Value &viewTag,
213
215
  const jsi::Value &propName,
214
216
  const jsi::Value &callback) {
215
- const int viewTagInt = (int)viewTag.asNumber();
217
+ const int viewTagInt = static_cast<int>(viewTag.asNumber());
216
218
  std::string propNameStr = propName.asString(rt).utf8(rt);
217
219
  jsi::Function fun = callback.getObject(rt).asFunction(rt);
218
220
  std::shared_ptr<jsi::Function> funPtr =
@@ -234,6 +236,13 @@ jsi::Value NativeReanimatedModule::getViewProp(
234
236
  return jsi::Value::undefined();
235
237
  }
236
238
 
239
+ jsi::Value NativeReanimatedModule::enableLayoutAnimations(
240
+ jsi::Runtime &rt,
241
+ const jsi::Value &config) {
242
+ FeaturesConfig::setLayoutAnimationEnabled(config.getBool());
243
+ return jsi::Value::undefined();
244
+ }
245
+
237
246
  void NativeReanimatedModule::onEvent(
238
247
  std::string eventName,
239
248
  std::string eventAsString) {
@@ -99,6 +99,17 @@ static jsi::Value __hostFunction_NativeReanimatedModuleSpec_getViewProp(
99
99
  return jsi::Value::undefined();
100
100
  }
101
101
 
102
+ static jsi::Value
103
+ __hostFunction_NativeReanimatedModuleSpec_enableLayoutAnimations(
104
+ jsi::Runtime &rt,
105
+ TurboModule &turboModule,
106
+ const jsi::Value *args,
107
+ size_t count) {
108
+ static_cast<NativeReanimatedModuleSpec *>(&turboModule)
109
+ ->enableLayoutAnimations(rt, std::move(args[0]));
110
+ return jsi::Value::undefined();
111
+ }
112
+
102
113
  NativeReanimatedModuleSpec::NativeReanimatedModuleSpec(
103
114
  std::shared_ptr<CallInvoker> jsInvoker)
104
115
  : TurboModule("NativeReanimated", jsInvoker) {
@@ -124,6 +135,8 @@ NativeReanimatedModuleSpec::NativeReanimatedModuleSpec(
124
135
 
125
136
  methodMap_["getViewProp"] =
126
137
  MethodMetadata{3, __hostFunction_NativeReanimatedModuleSpec_getViewProp};
138
+ methodMap_["enableLayoutAnimations"] = MethodMetadata{
139
+ 2, __hostFunction_NativeReanimatedModuleSpec_enableLayoutAnimations};
127
140
  }
128
141
 
129
142
  } // namespace reanimated
@@ -50,7 +50,7 @@ void EventHandlerRegistry::processEvent(
50
50
  }
51
51
 
52
52
  auto eventObject = jsi::Value::createFromJsonUtf8(
53
- rt, (uint8_t *)(&eventJSON[0]), eventJSON.size());
53
+ rt, reinterpret_cast<uint8_t *>(&eventJSON[0]), eventJSON.size());
54
54
 
55
55
  eventObject.asObject(rt).setProperty(
56
56
  rt, "eventName", jsi::String::createFromUtf8(rt, eventName));
@@ -62,7 +62,7 @@ void EventHandlerRegistry::processEvent(
62
62
  bool EventHandlerRegistry::isAnyHandlerWaitingForEvent(std::string eventName) {
63
63
  const std::lock_guard<std::mutex> lock(instanceMutex);
64
64
  auto it = eventMappings.find(eventName);
65
- return (it != eventMappings.end()) and (!(it->second).empty());
65
+ return (it != eventMappings.end()) && (!(it->second).empty());
66
66
  }
67
67
 
68
68
  } // namespace reanimated
@@ -39,7 +39,7 @@ void MapperRegistry::updateOrder() { // Topological sorting
39
39
  std::shared_ptr<Mapper> mapper;
40
40
  std::shared_ptr<MutableValue> mutableValue;
41
41
 
42
- NodeID(std::shared_ptr<Mapper> mapper) {
42
+ explicit NodeID(std::shared_ptr<Mapper> mapper) {
43
43
  if (mapper == nullptr) {
44
44
  throw std::runtime_error(
45
45
  "Graph couldn't be sorted (Mapper cannot be nullptr)");
@@ -47,7 +47,7 @@ void MapperRegistry::updateOrder() { // Topological sorting
47
47
  this->mapper = mapper;
48
48
  }
49
49
 
50
- NodeID(std::shared_ptr<MutableValue> mutableValue) {
50
+ explicit NodeID(std::shared_ptr<MutableValue> mutableValue) {
51
51
  if (mutableValue == nullptr) {
52
52
  throw std::runtime_error(
53
53
  "Graph couldn't be sorted (Mutable cannot be nullptr)");
@@ -97,7 +97,7 @@ void MapperRegistry::updateOrder() { // Topological sorting
97
97
  for (auto sharedValue : mapper->inputs) {
98
98
  auto sharedValueID = NodeID(sharedValue);
99
99
  mappersThatUseSharedValue[sharedValue].push_back(mapper);
100
- if (deg.count(sharedValue) == 0) {
100
+ if (deg.count(sharedValueID) == 0) {
101
101
  deg[sharedValueID] = 0;
102
102
  }
103
103
  }
@@ -114,7 +114,7 @@ void MapperRegistry::updateOrder() { // Topological sorting
114
114
  }
115
115
  }
116
116
 
117
- while (nodes.size() > 0 and nodes.begin()->first == 0) {
117
+ while (nodes.size() > 0 && nodes.begin()->first == 0) {
118
118
  auto entry = *nodes.begin();
119
119
  nodes.erase(entry);
120
120
 
@@ -123,7 +123,7 @@ void MapperRegistry::updateOrder() { // Topological sorting
123
123
 
124
124
  if (id.isMutable()) {
125
125
  for (auto id : mappersThatUseSharedValue[id.mutableValue]) {
126
- toUpdate.push_back(id);
126
+ toUpdate.push_back(NodeID(id));
127
127
  }
128
128
  } else {
129
129
  for (auto sharedValue : id.mapper->outputs) {
@@ -27,9 +27,7 @@ jsi::Object FrozenObject::shallowClone(jsi::Runtime &rt) {
27
27
  for (auto propName : namesOrder) {
28
28
  auto value = map[propName];
29
29
  object.setProperty(
30
- rt,
31
- jsi::String::createFromUtf8(rt, propName),
32
- value->getValue(rt));
30
+ rt, jsi::String::createFromUtf8(rt, propName), value->getValue(rt));
33
31
  }
34
32
  return object;
35
33
  }
@@ -13,16 +13,15 @@ const char *HIDDEN_HOST_OBJECT_PROP = "__reanimatedHostObjectRef";
13
13
  const char *ALREADY_CONVERTED = "__alreadyConverted";
14
14
  const char *CALL_ASYNC = "__callAsync";
15
15
  const char *PRIMAL_FUNCTION = "__primalFunction";
16
- std::string CALLBACK_ERROR_SUFFIX = R"(
17
-
18
- Possible solutions are:
19
- a) If you want to synchronously execute this method, mark it as a Worklet
20
- b) If you want to execute this method on the JS thread, wrap it using runOnJS )";
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";
21
20
 
22
21
  void addHiddenProperty(
23
22
  jsi::Runtime &rt,
24
23
  jsi::Value &&value,
25
- jsi::Object &obj,
24
+ const jsi::Object &obj,
26
25
  const char *name) {
27
26
  jsi::Object globalObject = rt.global().getPropertyAsObject(rt, "Object");
28
27
  jsi::Function defineProperty =
@@ -34,7 +33,7 @@ void addHiddenProperty(
34
33
  defineProperty.call(rt, obj, internalPropName, paramForDefineProperty);
35
34
  }
36
35
 
37
- void freeze(jsi::Runtime &rt, jsi::Object &obj) {
36
+ void freeze(jsi::Runtime &rt, const jsi::Object &obj) {
38
37
  jsi::Object globalObject = rt.global().getPropertyAsObject(rt, "Object");
39
38
  jsi::Function freeze = globalObject.getPropertyAsFunction(rt, "freeze");
40
39
  freeze.call(rt, obj);
@@ -344,7 +343,7 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
344
343
  hostFunction->getPureFunction().get()->call(
345
344
  *hostRuntime,
346
345
  static_cast<const jsi::Value *>(args),
347
- (size_t)params.size());
346
+ static_cast<size_t>(params.size()));
348
347
 
349
348
  delete[] args;
350
349
  // ToDo use returned value to return promise
@@ -455,8 +454,7 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
455
454
  returnedValue = funPtr->call(
456
455
  rt,
457
456
  static_cast<const jsi::Value *>(args),
458
- (size_t)params.size());
459
-
457
+ static_cast<size_t>(params.size()));
460
458
  } catch (std::exception &e) {
461
459
  std::string str = e.what();
462
460
  runtimeManager->errorHandler->setError(str);
@@ -0,0 +1,5 @@
1
+ #include "FeaturesConfig.h"
2
+
3
+ namespace reanimated {
4
+ bool FeaturesConfig::_isLayoutAnimationEnabled = false;
5
+ }
@@ -21,7 +21,7 @@ std::weak_ptr<jsi::Value> StoreUser::getWeakRef(jsi::Runtime &rt) {
21
21
 
22
22
  StoreUser::StoreUser(
23
23
  std::shared_ptr<Scheduler> s,
24
- RuntimeManager &runtimeManager)
24
+ const RuntimeManager &runtimeManager)
25
25
  : scheduler(s) {
26
26
  storeUserData = runtimeManager.storeUserData;
27
27
  identifier = storeUserData->ctr++;
@@ -32,7 +32,7 @@ StoreUser::~StoreUser() {
32
32
  std::shared_ptr<Scheduler> strongScheduler = scheduler.lock();
33
33
  if (strongScheduler != nullptr) {
34
34
  std::shared_ptr<StaticStoreUser> sud = storeUserData;
35
- #ifdef ONANDROID
35
+ #ifdef ONANDROID
36
36
  jni::ThreadScope::WithClassLoader([&] {
37
37
  strongScheduler->scheduleOnUI([id, sud]() {
38
38
  const std::lock_guard<std::recursive_mutex> lock(sud->storeMutex);
@@ -41,14 +41,14 @@ StoreUser::~StoreUser() {
41
41
  }
42
42
  });
43
43
  });
44
- #else
44
+ #else
45
45
  strongScheduler->scheduleOnUI([id, sud]() {
46
- const std::lock_guard<std::recursive_mutex> lock(sud->storeMutex);
47
- if (sud->store.count(id) > 0) {
48
- sud->store.erase(id);
49
- }
46
+ const std::lock_guard<std::recursive_mutex> lock(sud->storeMutex);
47
+ if (sud->store.count(id) > 0) {
48
+ sud->store.erase(id);
49
+ }
50
50
  });
51
- #endif
51
+ #endif
52
52
  }
53
53
  }
54
54
 
@@ -36,7 +36,7 @@ void Mapper::execute(jsi::Runtime &rt) {
36
36
  jsViewDescriptorArray.getValueAtIndex(rt, i).getObject(rt);
37
37
  (*updateProps)(
38
38
  rt,
39
- (int)jsViewDescriptor.getProperty(rt, "tag").asNumber(),
39
+ static_cast<int>(jsViewDescriptor.getProperty(rt, "tag").asNumber()),
40
40
  jsViewDescriptor.getProperty(rt, "name"),
41
41
  newStyle);
42
42
  }
@@ -1,4 +1,5 @@
1
1
  #include "RuntimeDecorator.h"
2
+ #include <chrono>
2
3
  #include <memory>
3
4
  #include <unordered_map>
4
5
  #include "LayoutAnimationsProxy.h"
@@ -8,11 +9,15 @@
8
9
  namespace reanimated {
9
10
 
10
11
  std::unordered_map<RuntimePointer, RuntimeType>
11
- RuntimeDecorator::runtimeRegistry;
12
+ &RuntimeDecorator::runtimeRegistry() {
13
+ static std::unordered_map<RuntimePointer, RuntimeType> runtimeRegistry;
14
+ return runtimeRegistry;
15
+ }
16
+
12
17
  void RuntimeDecorator::registerRuntime(
13
18
  jsi::Runtime *runtime,
14
19
  RuntimeType runtimeType) {
15
- runtimeRegistry.insert({runtime, runtimeType});
20
+ runtimeRegistry().insert({runtime, runtimeType});
16
21
  }
17
22
 
18
23
  void RuntimeDecorator::decorateRuntime(
@@ -79,6 +84,22 @@ void RuntimeDecorator::decorateRuntime(
79
84
  jsi::PropNameID::forAscii(rt, "_setGlobalConsole"),
80
85
  1,
81
86
  setGlobalConsole));
87
+
88
+ rt.global().setProperty(
89
+ rt,
90
+ "_chronoNow",
91
+ jsi::Function::createFromHostFunction(
92
+ rt,
93
+ jsi::PropNameID::forAscii(rt, "_chronoNow"),
94
+ 0,
95
+ [](jsi::Runtime &rt,
96
+ const jsi::Value &thisValue,
97
+ const jsi::Value *args,
98
+ size_t count) -> jsi::Value {
99
+ double now = std::chrono::system_clock::now().time_since_epoch() /
100
+ std::chrono::milliseconds(1);
101
+ return jsi::Value(now);
102
+ }));
82
103
  }
83
104
 
84
105
  void RuntimeDecorator::decorateUIRuntime(
@@ -88,6 +109,7 @@ void RuntimeDecorator::decorateUIRuntime(
88
109
  const ScrollToFunction scrollTo,
89
110
  const MeasuringFunction measure,
90
111
  const TimeProviderFunction getCurrentTime,
112
+ const SetGestureStateFunction setGestureState,
91
113
  std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy) {
92
114
  RuntimeDecorator::decorateRuntime(rt, "UI");
93
115
  rt.global().setProperty(rt, "_UI", jsi::Value(true));
@@ -128,7 +150,7 @@ void RuntimeDecorator::decorateUIRuntime(
128
150
  const jsi::Value &thisValue,
129
151
  const jsi::Value *args,
130
152
  const size_t count) -> jsi::Value {
131
- int viewTag = (int)args[0].asNumber();
153
+ int viewTag = static_cast<int>(args[0].asNumber());
132
154
  double x = args[1].asNumber();
133
155
  double y = args[2].asNumber();
134
156
  bool animated = args[3].getBool();
@@ -144,7 +166,7 @@ void RuntimeDecorator::decorateUIRuntime(
144
166
  const jsi::Value &thisValue,
145
167
  const jsi::Value *args,
146
168
  const size_t count) -> jsi::Value {
147
- int viewTag = (int)args[0].asNumber();
169
+ int viewTag = static_cast<int>(args[0].asNumber());
148
170
  auto result = measure(viewTag);
149
171
  jsi::Object resultObject(rt);
150
172
  for (auto &i : result) {
@@ -207,6 +229,20 @@ void RuntimeDecorator::decorateUIRuntime(
207
229
  jsi::Value _stopObservingProgress = jsi::Function::createFromHostFunction(
208
230
  rt, jsi::PropNameID::forAscii(rt, "_stopObservingProgress"), 0, clb8);
209
231
  rt.global().setProperty(rt, "_stopObservingProgress", _stopObservingProgress);
232
+
233
+ auto clb9 = [setGestureState](
234
+ jsi::Runtime &rt,
235
+ const jsi::Value &thisValue,
236
+ const jsi::Value *args,
237
+ size_t count) -> jsi::Value {
238
+ int handlerTag = static_cast<int>(args[0].asNumber());
239
+ int newState = static_cast<int>(args[1].asNumber());
240
+ setGestureState(handlerTag, newState);
241
+ return jsi::Value::undefined();
242
+ };
243
+ jsi::Value setGestureStateFunction = jsi::Function::createFromHostFunction(
244
+ rt, jsi::PropNameID::forAscii(rt, "_setGestureState"), 2, clb9);
245
+ rt.global().setProperty(rt, "_setGestureState", setGestureStateFunction);
210
246
  }
211
247
 
212
248
  } // namespace reanimated
@@ -2,7 +2,9 @@
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
 
@@ -2,7 +2,9 @@
2
2
 
3
3
  #include <unistd.h>
4
4
  #include <memory>
5
+ #include <string>
5
6
  #include <vector>
7
+
6
8
  #include "ErrorHandler.h"
7
9
  #include "LayoutAnimationsProxy.h"
8
10
  #include "NativeReanimatedModuleSpec.h"
@@ -66,6 +68,9 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec,
66
68
  const jsi::Value &propName,
67
69
  const jsi::Value &callback) override;
68
70
 
71
+ jsi::Value enableLayoutAnimations(jsi::Runtime &rt, const jsi::Value &config)
72
+ override;
73
+
69
74
  void onRender(double timestampMs);
70
75
  void onEvent(std::string eventName, std::string eventAsString);
71
76
  bool isAnyHandlerWaitingForEvent(std::string eventName);
@@ -19,7 +19,7 @@ namespace reanimated {
19
19
 
20
20
  class JSI_EXPORT NativeReanimatedModuleSpec : public TurboModule {
21
21
  protected:
22
- NativeReanimatedModuleSpec(std::shared_ptr<CallInvoker> jsInvoker);
22
+ explicit NativeReanimatedModuleSpec(std::shared_ptr<CallInvoker> jsInvoker);
23
23
 
24
24
  public:
25
25
  virtual void installCoreFunctions(
@@ -58,6 +58,11 @@ class JSI_EXPORT NativeReanimatedModuleSpec : public TurboModule {
58
58
  const jsi::Value &viewTag,
59
59
  const jsi::Value &propName,
60
60
  const jsi::Value &callback) = 0;
61
+
62
+ // other
63
+ virtual jsi::Value enableLayoutAnimations(
64
+ jsi::Runtime &rt,
65
+ const jsi::Value &config) = 0;
61
66
  };
62
67
 
63
68
  } // namespace reanimated
@@ -2,6 +2,7 @@
2
2
 
3
3
  #include <jsi/jsi.h>
4
4
  #include <map>
5
+ #include <memory>
5
6
  #include <mutex>
6
7
  #include <set>
7
8
  #include <string>
@@ -1,6 +1,7 @@
1
1
  #pragma once
2
2
 
3
3
  #include <jsi/jsi.h>
4
+ #include <memory>
4
5
  #include <unordered_map>
5
6
  #include <vector>
6
7
 
@@ -1,6 +1,10 @@
1
1
  #pragma once
2
2
 
3
3
  #include <jsi/jsi.h>
4
+ #include <memory>
5
+ #include <string>
6
+ #include <unordered_map>
7
+ #include <vector>
4
8
  #include "RuntimeManager.h"
5
9
  #include "SharedParent.h"
6
10
  #include "WorkletsCache.h"
@@ -1,6 +1,8 @@
1
1
  #pragma once
2
2
 
3
3
  #include <jsi/jsi.h>
4
+ #include <memory>
5
+ #include <string>
4
6
 
5
7
  using namespace facebook;
6
8
 
@@ -2,7 +2,9 @@
2
2
 
3
3
  #include <jsi/jsi.h>
4
4
  #include <map>
5
+ #include <memory>
5
6
  #include <mutex>
7
+ #include <vector>
6
8
  #include "JSIStoreValueUser.h"
7
9
  #include "LayoutAnimationsProxy.h"
8
10
  #include "MutableValueSetterProxy.h"
@@ -1,6 +1,8 @@
1
1
  #pragma once
2
2
 
3
3
  #include <jsi/jsi.h>
4
+ #include <memory>
5
+ #include <utility>
4
6
  #include "SharedParent.h"
5
7
 
6
8
  using namespace facebook;
@@ -13,7 +15,7 @@ class MutableValueSetterProxy : public jsi::HostObject {
13
15
  std::shared_ptr<MutableValue> mutableValue;
14
16
 
15
17
  public:
16
- MutableValueSetterProxy(std::shared_ptr<MutableValue> mutableValue)
18
+ explicit MutableValueSetterProxy(std::shared_ptr<MutableValue> mutableValue)
17
19
  : mutableValue(std::move(mutableValue)) {}
18
20
  void
19
21
  set(jsi::Runtime &rt, const jsi::PropNameID &name, const jsi::Value &value);
@@ -1,5 +1,8 @@
1
1
  #pragma once
2
2
 
3
+ #include <memory>
4
+ #include <vector>
5
+
3
6
  #include "FrozenObject.h"
4
7
  #include "JSIStoreValueUser.h"
5
8
  #include "SharedParent.h"
@@ -17,7 +20,7 @@ class RemoteObject : public jsi::HostObject, public StoreUser {
17
20
  void maybeInitializeOnWorkletRuntime(jsi::Runtime &rt);
18
21
  RemoteObject(
19
22
  jsi::Runtime &rt,
20
- jsi::Object &object,
23
+ const jsi::Object &object,
21
24
  RuntimeManager *runtimeManager,
22
25
  std::shared_ptr<Scheduler> s)
23
26
  : StoreUser(s, *runtimeManager),
@@ -1,9 +1,11 @@
1
1
  #pragma once
2
2
 
3
3
  #include <jsi/jsi.h>
4
+ #include <memory>
4
5
  #include <mutex>
5
6
  #include <string>
6
7
  #include <unordered_map>
8
+ #include <vector>
7
9
  #include "HostFunctionHandler.h"
8
10
  #include "JSIStoreValueUser.h"
9
11
  #include "LayoutAnimationsProxy.h"
@@ -8,15 +8,15 @@ enum class ValueType {
8
8
  BoolType,
9
9
  NumberType,
10
10
  StringType,
11
- RemoteObjectType, /* object that can be instantiated on host side and modified
12
- on the remote (worklet) side */
13
- MutableValueType, /* object with 'value' property that can be updated and read
14
- from any thread */
15
- HostFunctionType, /* function that will be executed asynchronously on the host
16
- runtime */
17
- WorkletFunctionType, /* function that gets run on the UI thread */
18
- FrozenObjectType, /* frozen object, can only be set and never modified */
19
- FrozenArrayType, /* frozen array, can only be set and never modified */
11
+ RemoteObjectType, // object that can be instantiated on host side and modified
12
+ // on the remote (worklet) side
13
+ MutableValueType, // object with 'value' property that can be updated and read
14
+ // from any thread
15
+ HostFunctionType, // function that will be executed asynchronously on the host
16
+ // runtime
17
+ WorkletFunctionType, // function that gets run on the UI thread
18
+ FrozenObjectType, // frozen object, can only be set and never modified
19
+ FrozenArrayType, // frozen array, can only be set and never modified
20
20
  };
21
21
 
22
22
  class ShareableValue;