react-native-reanimated 4.3.0-rc.0 → 4.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 (176) hide show
  1. package/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp +8 -5
  2. package/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h +3 -5
  3. package/Common/cpp/reanimated/CSS/common/values/CSSValueVariant.cpp +2 -3
  4. package/Common/cpp/reanimated/CSS/interpolation/PropertyInterpolator.cpp +2 -3
  5. package/Common/cpp/reanimated/CSS/registries/CSSAnimationsRegistry.cpp +7 -3
  6. package/Common/cpp/reanimated/CSS/registries/CSSAnimationsRegistry.h +9 -2
  7. package/Common/cpp/reanimated/CSS/registries/CSSTransitionsRegistry.cpp +6 -2
  8. package/Common/cpp/reanimated/CSS/registries/CSSTransitionsRegistry.h +8 -2
  9. package/Common/cpp/reanimated/CSS/utils/DelayedItemsManager.cpp +2 -2
  10. package/Common/cpp/reanimated/CSS/utils/DelayedItemsManager.h +2 -2
  11. package/Common/cpp/reanimated/Compat/WorkletsApi.h +13 -0
  12. package/Common/cpp/reanimated/Events/UIEventHandler.cpp +1 -1
  13. package/Common/cpp/reanimated/Events/UIEventHandler.h +3 -4
  14. package/Common/cpp/reanimated/Events/UIEventHandlerRegistry.cpp +3 -2
  15. package/Common/cpp/reanimated/Events/UIEventHandlerRegistry.h +1 -1
  16. package/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +2 -8
  17. package/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +2 -6
  18. package/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +1 -6
  19. package/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +1 -8
  20. package/Common/cpp/reanimated/Fabric/updates/AnimatedPropsRegistry.cpp +12 -7
  21. package/Common/cpp/reanimated/Fabric/updates/AnimatedPropsRegistry.h +6 -3
  22. package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.cpp +4 -6
  23. package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.h +25 -7
  24. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h +1 -2
  25. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.h +1 -1
  26. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.cpp +9 -9
  27. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.h +2 -3
  28. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.cpp +21 -21
  29. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.h +3 -3
  30. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +3 -3
  31. package/Common/cpp/reanimated/LayoutAnimations/SharedTransitions.cpp +24 -20
  32. package/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +35 -53
  33. package/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +1 -2
  34. package/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp +22 -22
  35. package/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h +10 -10
  36. package/Common/cpp/reanimated/Tools/ReaJSIUtils.h +5 -5
  37. package/README.md +1 -1
  38. package/android/build.gradle +0 -21
  39. package/android/src/main/cpp/reanimated/android/NativeProxy.cpp +6 -10
  40. package/android/src/main/cpp/reanimated/android/NativeProxy.h +1 -2
  41. package/android/src/main/java/com/swmansion/reanimated/CopiedEvent.java +66 -9
  42. package/android/src/main/java/com/swmansion/reanimated/NodesManager.java +16 -11
  43. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/EventHandler.java +34 -8
  44. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/NoopEventHandler.java +27 -6
  45. package/apple/reanimated/apple/REANodesManager.mm +0 -8
  46. package/apple/reanimated/apple/ReanimatedModule.mm +6 -12
  47. package/apple/reanimated/apple/native/NativeProxy.h +1 -2
  48. package/apple/reanimated/apple/native/NativeProxy.mm +1 -1
  49. package/compatibility.json +7 -29
  50. package/lib/module/PropsRegistryGarbageCollector.js +3 -0
  51. package/lib/module/PropsRegistryGarbageCollector.js.map +1 -1
  52. package/lib/module/common/style/processors/colors.js +31 -4
  53. package/lib/module/common/style/processors/colors.js.map +1 -1
  54. package/lib/module/common/style/processors/filter.js +103 -61
  55. package/lib/module/common/style/processors/filter.js.map +1 -1
  56. package/lib/module/common/style/processors/font.js +7 -1
  57. package/lib/module/common/style/processors/font.js.map +1 -1
  58. package/lib/module/common/style/processors/insets.js +26 -14
  59. package/lib/module/common/style/processors/insets.js.map +1 -1
  60. package/lib/module/common/style/processors/others.js +15 -5
  61. package/lib/module/common/style/processors/others.js.map +1 -1
  62. package/lib/module/common/style/processors/shadows.js +14 -3
  63. package/lib/module/common/style/processors/shadows.js.map +1 -1
  64. package/lib/module/common/style/processors/transform.js +30 -1
  65. package/lib/module/common/style/processors/transform.js.map +1 -1
  66. package/lib/module/common/style/processors/transformOrigin.js +20 -3
  67. package/lib/module/common/style/processors/transformOrigin.js.map +1 -1
  68. package/lib/module/common/utils/guards.js +27 -7
  69. package/lib/module/common/utils/guards.js.map +1 -1
  70. package/lib/module/common/utils/parsers.js +2 -1
  71. package/lib/module/common/utils/parsers.js.map +1 -1
  72. package/lib/module/createAnimatedComponent/AnimatedComponent.js +1 -7
  73. package/lib/module/createAnimatedComponent/AnimatedComponent.js.map +1 -1
  74. package/lib/module/css/native/managers/CSSManager.js +16 -15
  75. package/lib/module/css/native/managers/CSSManager.js.map +1 -1
  76. package/lib/module/css/native/managers/CSSTransitionsManager.js +47 -44
  77. package/lib/module/css/native/managers/CSSTransitionsManager.js.map +1 -1
  78. package/lib/module/css/native/normalization/transition/config.js +35 -17
  79. package/lib/module/css/native/normalization/transition/config.js.map +1 -1
  80. package/lib/module/css/utils/props.js +6 -0
  81. package/lib/module/css/utils/props.js.map +1 -1
  82. package/lib/module/featureFlags/index.js +1 -1
  83. package/lib/module/featureFlags/staticFlags.json +1 -1
  84. package/lib/module/hook/useAnimatedRef.js +2 -2
  85. package/lib/module/hook/useAnimatedRef.js.map +1 -1
  86. package/lib/module/hook/useAnimatedStyle.js +7 -1
  87. package/lib/module/hook/useAnimatedStyle.js.map +1 -1
  88. package/lib/module/hook/useHandler.js +82 -28
  89. package/lib/module/hook/useHandler.js.map +1 -1
  90. package/lib/module/hook/utils.js +1 -74
  91. package/lib/module/hook/utils.js.map +1 -1
  92. package/lib/module/initializers.js +2 -0
  93. package/lib/module/initializers.js.map +1 -1
  94. package/lib/module/jestUtils/common.js +10 -0
  95. package/lib/module/jestUtils/common.js.map +1 -1
  96. package/lib/module/jestUtils/index.js +2 -5
  97. package/lib/module/jestUtils/index.js.map +1 -1
  98. package/lib/module/jestUtils/index.web.js +1 -1
  99. package/lib/module/jestUtils/index.web.js.map +1 -1
  100. package/lib/module/mutables.js +5 -1
  101. package/lib/module/mutables.js.map +1 -1
  102. package/lib/module/platform-specific/jsVersion.js +1 -1
  103. package/lib/module/platform-specific/jsVersion.js.map +1 -1
  104. package/lib/typescript/PropsRegistryGarbageCollector.d.ts.map +1 -1
  105. package/lib/typescript/common/style/processors/colors.d.ts +3 -3
  106. package/lib/typescript/common/style/processors/colors.d.ts.map +1 -1
  107. package/lib/typescript/common/style/processors/filter.d.ts +0 -4
  108. package/lib/typescript/common/style/processors/filter.d.ts.map +1 -1
  109. package/lib/typescript/common/style/processors/font.d.ts +1 -1
  110. package/lib/typescript/common/style/processors/font.d.ts.map +1 -1
  111. package/lib/typescript/common/style/processors/insets.d.ts.map +1 -1
  112. package/lib/typescript/common/style/processors/others.d.ts +1 -1
  113. package/lib/typescript/common/style/processors/others.d.ts.map +1 -1
  114. package/lib/typescript/common/style/processors/shadows.d.ts.map +1 -1
  115. package/lib/typescript/common/style/processors/transform.d.ts.map +1 -1
  116. package/lib/typescript/common/style/processors/transformOrigin.d.ts +2 -2
  117. package/lib/typescript/common/style/processors/transformOrigin.d.ts.map +1 -1
  118. package/lib/typescript/common/utils/guards.d.ts +0 -1
  119. package/lib/typescript/common/utils/guards.d.ts.map +1 -1
  120. package/lib/typescript/common/utils/parsers.d.ts.map +1 -1
  121. package/lib/typescript/commonTypes.d.ts +1 -1
  122. package/lib/typescript/commonTypes.d.ts.map +1 -1
  123. package/lib/typescript/createAnimatedComponent/AnimatedComponent.d.ts.map +1 -1
  124. package/lib/typescript/css/native/managers/CSSManager.d.ts +7 -1
  125. package/lib/typescript/css/native/managers/CSSManager.d.ts.map +1 -1
  126. package/lib/typescript/css/native/managers/CSSTransitionsManager.d.ts +5 -4
  127. package/lib/typescript/css/native/managers/CSSTransitionsManager.d.ts.map +1 -1
  128. package/lib/typescript/css/native/normalization/transition/config.d.ts.map +1 -1
  129. package/lib/typescript/css/native/types/transition.d.ts +15 -1
  130. package/lib/typescript/css/native/types/transition.d.ts.map +1 -1
  131. package/lib/typescript/css/utils/props.d.ts.map +1 -1
  132. package/lib/typescript/featureFlags/index.d.ts +1 -1
  133. package/lib/typescript/hook/useAnimatedStyle.d.ts.map +1 -1
  134. package/lib/typescript/hook/useHandler.d.ts +8 -9
  135. package/lib/typescript/hook/useHandler.d.ts.map +1 -1
  136. package/lib/typescript/hook/utils.d.ts +0 -5
  137. package/lib/typescript/hook/utils.d.ts.map +1 -1
  138. package/lib/typescript/jestUtils/common.d.ts +2 -0
  139. package/lib/typescript/jestUtils/common.d.ts.map +1 -1
  140. package/lib/typescript/jestUtils/index.d.ts +4 -3
  141. package/lib/typescript/jestUtils/index.d.ts.map +1 -1
  142. package/lib/typescript/mutables.d.ts.map +1 -1
  143. package/lib/typescript/platform-specific/jsVersion.d.ts +1 -1
  144. package/lib/typescript/platform-specific/jsVersion.d.ts.map +1 -1
  145. package/package.json +13 -10
  146. package/src/PropsRegistryGarbageCollector.ts +3 -0
  147. package/src/common/style/processors/colors.ts +20 -7
  148. package/src/common/style/processors/filter.ts +95 -70
  149. package/src/common/style/processors/font.ts +5 -2
  150. package/src/common/style/processors/insets.ts +23 -14
  151. package/src/common/style/processors/others.ts +12 -6
  152. package/src/common/style/processors/shadows.ts +10 -6
  153. package/src/common/style/processors/transform.ts +15 -1
  154. package/src/common/style/processors/transformOrigin.ts +40 -11
  155. package/src/common/utils/guards.ts +21 -16
  156. package/src/common/utils/parsers.ts +1 -1
  157. package/src/commonTypes.ts +1 -1
  158. package/src/createAnimatedComponent/AnimatedComponent.tsx +1 -7
  159. package/src/css/native/managers/CSSManager.ts +29 -14
  160. package/src/css/native/managers/CSSTransitionsManager.ts +52 -54
  161. package/src/css/native/normalization/transition/config.ts +35 -27
  162. package/src/css/native/types/transition.ts +15 -1
  163. package/src/css/utils/props.ts +7 -0
  164. package/src/featureFlags/index.ts +1 -1
  165. package/src/featureFlags/staticFlags.json +1 -1
  166. package/src/hook/useAnimatedRef.ts +2 -2
  167. package/src/hook/useAnimatedStyle.ts +15 -6
  168. package/src/hook/useHandler.ts +150 -64
  169. package/src/hook/utils.ts +1 -127
  170. package/src/initializers.ts +1 -0
  171. package/src/jestUtils/common.ts +10 -0
  172. package/src/jestUtils/index.ts +5 -8
  173. package/src/jestUtils/index.web.ts +1 -1
  174. package/src/mutables.ts +5 -1
  175. package/src/platform-specific/jsVersion.ts +1 -1
  176. package/src/privateGlobals.d.ts +4 -0
@@ -11,7 +11,7 @@ AnimatedSensorModule::AnimatedSensorModule(const PlatformDepMethodsHolder &platf
11
11
  platformUnregisterSensorFunction_(platformDepMethodsHolder.unregisterSensor) {}
12
12
 
13
13
  jsi::Value AnimatedSensorModule::registerSensor(
14
- jsi::Runtime &rt,
14
+ jsi::Runtime &rnRuntime,
15
15
  const std::shared_ptr<WorkletRuntime> &uiWorkletRuntime,
16
16
  const jsi::Value &sensorTypeValue,
17
17
  const jsi::Value &interval,
@@ -19,8 +19,11 @@ jsi::Value AnimatedSensorModule::registerSensor(
19
19
  const jsi::Value &sensorDataHandler) {
20
20
  SensorType sensorType = static_cast<SensorType>(sensorTypeValue.asNumber());
21
21
 
22
- auto serializableHandler = extractSerializableOrThrow<SerializableWorklet>(
23
- rt, sensorDataHandler, "[Reanimated] Sensor event handler must be a worklet.");
22
+ auto serializableHandler = extractSerializable(
23
+ rnRuntime,
24
+ sensorDataHandler,
25
+ "[Reanimated] Sensor event handler must be a worklet.",
26
+ Serializable::ValueType::WorkletType);
24
27
 
25
28
  int sensorId = platformRegisterSensorFunction_(
26
29
  static_cast<int>(sensorType),
@@ -33,7 +36,7 @@ jsi::Value AnimatedSensorModule::registerSensor(
33
36
  return;
34
37
  }
35
38
 
36
- jsi::Runtime &uiRuntime = uiWorkletRuntime->getJSIRuntime();
39
+ jsi::Runtime &uiRuntime = getJSIRuntimeFromWorkletRuntime(uiWorkletRuntime);
37
40
  jsi::Object value(uiRuntime);
38
41
  if (sensorType == SensorType::ROTATION_VECTOR) {
39
42
  // TODO: timestamp should be provided by the platform implementation
@@ -53,7 +56,7 @@ jsi::Value AnimatedSensorModule::registerSensor(
53
56
  }
54
57
  value.setProperty(uiRuntime, "interfaceOrientation", orientationDegrees);
55
58
 
56
- uiWorkletRuntime->runSync(serializableHandler, value);
59
+ runSyncOnRuntime(uiWorkletRuntime, serializableHandler, jsi::Value(uiRuntime, value));
57
60
  });
58
61
  if (sensorId != -1) {
59
62
  sensorsIds_.insert(sensorId);
@@ -1,10 +1,8 @@
1
1
  #pragma once
2
2
 
3
+ #include <reanimated/Compat/WorkletsApi.h>
3
4
  #include <reanimated/Tools/PlatformDepMethodsHolder.h>
4
5
 
5
- #include <worklets/SharedItems/Serializable.h>
6
- #include <worklets/WorkletRuntime/WorkletRuntime.h>
7
-
8
6
  #include <jsi/jsi.h>
9
7
 
10
8
  #include <memory>
@@ -32,8 +30,8 @@ class AnimatedSensorModule {
32
30
  explicit AnimatedSensorModule(const PlatformDepMethodsHolder &platformDepMethodsHolder);
33
31
 
34
32
  jsi::Value registerSensor(
35
- jsi::Runtime &rt,
36
- const std::shared_ptr<WorkletRuntime> &uiWorkletRuntime,
33
+ jsi::Runtime &rnRuntime,
34
+ const std::shared_ptr<WorkletRuntime> &uiRuntime,
37
35
  const jsi::Value &sensorType,
38
36
  const jsi::Value &interval,
39
37
  const jsi::Value &iosReferenceFrame,
@@ -12,8 +12,7 @@
12
12
  #include <reanimated/CSS/svg/values/SVGPath.h>
13
13
  #include <reanimated/CSS/svg/values/SVGStops.h>
14
14
  #include <reanimated/CSS/svg/values/SVGStrokeDashArray.h>
15
-
16
- #include <worklets/Tools/JSISerializer.h>
15
+ #include <reanimated/Compat/WorkletsApi.h>
17
16
 
18
17
  #include <string>
19
18
  #include <utility>
@@ -41,7 +40,7 @@ CSSValueVariant<AllowedTypes...>::CSSValueVariant(jsi::Runtime &rt, const jsi::V
41
40
  // Try constructing with each allowed type until one succeeds
42
41
  if (!(tryOne.template operator()<AllowedTypes>() || ...)) {
43
42
  throw std::runtime_error(
44
- "[Reanimated] No compatible type found for construction from: " + worklets::stringifyJSIValue(rt, jsiValue));
43
+ "[Reanimated] No compatible type found for construction from: " + worklets::JSIValueToStdString(rt, jsiValue));
45
44
  }
46
45
  }
47
46
 
@@ -1,6 +1,5 @@
1
1
  #include <reanimated/CSS/interpolation/PropertyInterpolator.h>
2
-
3
- #include <worklets/Tools/JSISerializer.h>
2
+ #include <reanimated/Compat/WorkletsApi.h>
4
3
 
5
4
  #include <memory>
6
5
  #include <utility>
@@ -35,7 +34,7 @@ std::vector<std::pair<double, jsi::Value>> PropertyInterpolator::parseJSIKeyfram
35
34
  throw std::invalid_argument(
36
35
  "[Reanimated] Received invalid keyframes object for property: " + getPropertyPathString() +
37
36
  ".\n\nExpected an array of objects with 'offset' and 'value' properties, got: " +
38
- worklets::stringifyJSIValue(rt, keyframes));
37
+ worklets::JSIValueToStdString(rt, keyframes));
39
38
  }
40
39
 
41
40
  const auto keyframeArray = keyframes.asObject(rt).asArray(rt);
@@ -9,12 +9,14 @@
9
9
  namespace reanimated::css {
10
10
 
11
11
  bool CSSAnimationsRegistry::isEmpty() const {
12
+ std::lock_guard<std::mutex> lock{mutex_};
12
13
  // The registry is empty if has no registered animations and no updates
13
14
  // stored in the updates registry
14
- return UpdatesRegistry::isEmpty() && registry_.empty();
15
+ return updatesRegistry_.empty() && registry_.empty();
15
16
  }
16
17
 
17
18
  bool CSSAnimationsRegistry::hasUpdates() const {
19
+ std::lock_guard<std::mutex> lock{mutex_};
18
20
  return !runningAnimationIndicesMap_.empty() || !delayedAnimationsManager_.empty() || !animationsToRevertMap_.empty();
19
21
  }
20
22
 
@@ -25,11 +27,13 @@ void CSSAnimationsRegistry::apply(
25
27
  const CSSAnimationsMap &newAnimations,
26
28
  const CSSAnimationSettingsUpdatesMap &settingsUpdates,
27
29
  double timestamp) {
30
+ std::lock_guard<std::mutex> lock{mutex_};
31
+
28
32
  auto animationsVector = buildAnimationsVector(rt, shadowNode, animationNames, newAnimations);
29
33
 
30
34
  const auto viewTag = shadowNode->getTag();
31
35
  if (animationsVector.empty()) {
32
- remove(viewTag);
36
+ removeTag(viewTag);
33
37
  return;
34
38
  }
35
39
 
@@ -56,7 +60,7 @@ void CSSAnimationsRegistry::apply(
56
60
  applyViewAnimationsStyle(viewTag, timestamp);
57
61
  }
58
62
 
59
- void CSSAnimationsRegistry::remove(const Tag viewTag) {
63
+ void CSSAnimationsRegistry::removeTag(const Tag viewTag) {
60
64
  removeViewAnimations(viewTag);
61
65
  removeFromUpdatesRegistry(viewTag);
62
66
  registry_.erase(viewTag);
@@ -7,6 +7,7 @@
7
7
  #include <reanimated/Fabric/updates/UpdatesRegistry.h>
8
8
 
9
9
  #include <memory>
10
+ #include <mutex>
10
11
  #include <set>
11
12
  #include <string>
12
13
  #include <unordered_map>
@@ -33,9 +34,12 @@ class CSSAnimationsRegistry : public UpdatesRegistry, std::enable_shared_from_th
33
34
  const CSSAnimationsMap &newAnimations,
34
35
  const CSSAnimationSettingsUpdatesMap &settingsUpdates,
35
36
  double timestamp);
36
- void remove(Tag viewTag) override;
37
37
 
38
- void update(double timestamp);
38
+ void updateAndFlush(double timestamp, UpdatesBatch &updatesBatch) {
39
+ std::lock_guard<std::mutex> lock{mutex_};
40
+ update(timestamp);
41
+ flush(updatesBatch);
42
+ }
39
43
 
40
44
  private:
41
45
  using AnimationToIndexMap = std::unordered_map<std::shared_ptr<CSSAnimation>, size_t>;
@@ -54,6 +58,9 @@ class CSSAnimationsRegistry : public UpdatesRegistry, std::enable_shared_from_th
54
58
  AnimationsToRevertMap animationsToRevertMap_;
55
59
  DelayedItemsManager<std::shared_ptr<CSSAnimation>> delayedAnimationsManager_;
56
60
 
61
+ void removeTag(Tag viewTag) override;
62
+ void update(double timestamp);
63
+
57
64
  CSSAnimationsVector buildAnimationsVector(
58
65
  jsi::Runtime &rt,
59
66
  const std::shared_ptr<const ShadowNode> &shadowNode,
@@ -11,12 +11,14 @@ CSSTransitionsRegistry::CSSTransitionsRegistry(
11
11
  : getCurrentTimestamp_(getCurrentTimestamp), viewStylesRepository_(viewStylesRepository) {}
12
12
 
13
13
  bool CSSTransitionsRegistry::isEmpty() const {
14
+ std::lock_guard<std::mutex> lock{mutex_};
14
15
  // The registry is empty if has no registered animations and no updates
15
16
  // stored in the updates registry
16
- return UpdatesRegistry::isEmpty() && registry_.empty();
17
+ return updatesRegistry_.empty() && registry_.empty();
17
18
  }
18
19
 
19
20
  bool CSSTransitionsRegistry::hasUpdates() const {
21
+ std::lock_guard<std::mutex> lock{mutex_};
20
22
  return !runningTransitionTags_.empty() || !delayedTransitionsManager_.empty();
21
23
  }
22
24
 
@@ -24,6 +26,8 @@ void CSSTransitionsRegistry::run(
24
26
  jsi::Runtime &rt,
25
27
  const std::shared_ptr<const ShadowNode> &shadowNode,
26
28
  const CSSTransitionConfig &config) {
29
+ std::lock_guard<std::mutex> lock{mutex_};
30
+
27
31
  const auto viewTag = shadowNode->getTag();
28
32
 
29
33
  if (!registry_.contains(viewTag)) {
@@ -42,7 +46,7 @@ void CSSTransitionsRegistry::run(
42
46
  updateInUpdatesRegistry(transition, initialUpdate);
43
47
  }
44
48
 
45
- void CSSTransitionsRegistry::remove(const Tag viewTag) {
49
+ void CSSTransitionsRegistry::removeTag(const Tag viewTag) {
46
50
  removeFromUpdatesRegistry(viewTag);
47
51
  delayedTransitionsManager_.remove(viewTag);
48
52
  runningTransitionTags_.erase(viewTag);
@@ -8,6 +8,7 @@
8
8
  #include <reanimated/Tools/PlatformDepMethodsHolder.h>
9
9
 
10
10
  #include <memory>
11
+ #include <mutex>
11
12
  #include <set>
12
13
  #include <unordered_map>
13
14
  #include <unordered_set>
@@ -26,9 +27,12 @@ class CSSTransitionsRegistry : public UpdatesRegistry, public std::enable_shared
26
27
  bool hasUpdates() const;
27
28
 
28
29
  void run(jsi::Runtime &rt, const std::shared_ptr<const ShadowNode> &shadowNode, const CSSTransitionConfig &config);
29
- void remove(Tag viewTag) override;
30
30
 
31
- void update(double timestamp);
31
+ void updateAndFlush(double timestamp, UpdatesBatch &updatesBatch) {
32
+ std::lock_guard<std::mutex> lock{mutex_};
33
+ update(timestamp);
34
+ flush(updatesBatch);
35
+ }
32
36
 
33
37
  private:
34
38
  using Registry = std::unordered_map<Tag, std::shared_ptr<CSSTransition>>;
@@ -41,6 +45,8 @@ class CSSTransitionsRegistry : public UpdatesRegistry, public std::enable_shared
41
45
  std::unordered_set<Tag> runningTransitionTags_;
42
46
  DelayedItemsManager<Tag> delayedTransitionsManager_;
43
47
 
48
+ void removeTag(Tag viewTag) override;
49
+ void update(double timestamp);
44
50
  void activateDelayedTransitions(double timestamp);
45
51
  void scheduleOrActivateTransition(const std::shared_ptr<CSSTransition> &transition);
46
52
  void updateInUpdatesRegistry(const std::shared_ptr<CSSTransition> &transition, const folly::dynamic &updates);
@@ -18,7 +18,7 @@ bool DelayedItemComparator<TValue>::operator()(const DelayedItem<TValue> &lhs, c
18
18
  }
19
19
 
20
20
  template <typename TValue>
21
- void DelayedItemsManager<TValue>::add(const double timestamp, const TValue value) {
21
+ void DelayedItemsManager<TValue>::add(const double timestamp, const TValue &value) {
22
22
  auto result = itemsSet_.emplace(timestamp, value);
23
23
  if (result.second) {
24
24
  itemsMap_[result.first->value] = result.first;
@@ -38,7 +38,7 @@ typename DelayedItemsManager<TValue>::Item DelayedItemsManager<TValue>::pop() {
38
38
  }
39
39
 
40
40
  template <typename TValue>
41
- bool DelayedItemsManager<TValue>::remove(const TValue value) {
41
+ bool DelayedItemsManager<TValue>::remove(const TValue &value) {
42
42
  auto it = itemsMap_.find(value);
43
43
 
44
44
  if (it == itemsMap_.end()) {
@@ -34,9 +34,9 @@ class DelayedItemsManager {
34
34
  ItemMap itemsMap_;
35
35
 
36
36
  public:
37
- void add(double timestamp, TValue value);
37
+ void add(double timestamp, const TValue &value);
38
38
  Item pop();
39
- bool remove(TValue value);
39
+ bool remove(const TValue &value);
40
40
  const Item &top() const;
41
41
  bool empty() const;
42
42
  size_t size() const;
@@ -0,0 +1,13 @@
1
+ #pragma once
2
+
3
+ #include <worklets/Compat/StableApi.h>
4
+ #include <string>
5
+
6
+ #define EXPECTED_WORKLETS_STABLE_API_VERSION "0.8.0"
7
+
8
+ static_assert(
9
+ std::string(WORKLETS_STABLE_API_VERSION) == EXPECTED_WORKLETS_STABLE_API_VERSION,
10
+ "Incompatible worklets stable API version. Expected " EXPECTED_WORKLETS_STABLE_API_VERSION
11
+ ", but got " WORKLETS_STABLE_API_VERSION ".");
12
+
13
+ #undef EXPECTED_WORKLETS_STABLE_API_VERSION
@@ -11,7 +11,7 @@ void UIEventHandler::process(
11
11
  const std::shared_ptr<WorkletRuntime> &uiRuntime,
12
12
  const double eventTimestamp,
13
13
  const jsi::Value &eventValue) const {
14
- uiRuntime->runSync(handlerFunction_, jsi::Value(eventTimestamp), eventValue);
14
+ runSyncOnRuntime(uiRuntime, handlerFunction_, jsi::Value(eventTimestamp), eventValue);
15
15
  }
16
16
 
17
17
  uint64_t UIEventHandler::getHandlerId() const {
@@ -1,8 +1,7 @@
1
1
  #pragma once
2
2
 
3
3
  #include <jsi/jsi.h>
4
- #include <worklets/SharedItems/Serializable.h>
5
- #include <worklets/WorkletRuntime/WorkletRuntime.h>
4
+ #include <reanimated/Compat/WorkletsApi.h>
6
5
 
7
6
  #include <memory>
8
7
  #include <string>
@@ -15,14 +14,14 @@ class UIEventHandler {
15
14
  const uint64_t handlerId_;
16
15
  const uint64_t emitterReactTag_;
17
16
  const std::string eventName_;
18
- const std::shared_ptr<worklets::SerializableWorklet> handlerFunction_;
17
+ const std::shared_ptr<worklets::Serializable> handlerFunction_;
19
18
 
20
19
  public:
21
20
  UIEventHandler(
22
21
  const uint64_t handlerId,
23
22
  const std::string &eventName,
24
23
  const uint64_t emitterReactTag,
25
- const std::shared_ptr<worklets::SerializableWorklet> &handlerFunction)
24
+ const std::shared_ptr<worklets::Serializable> &handlerFunction)
26
25
  : handlerId_(handlerId),
27
26
  emitterReactTag_(emitterReactTag),
28
27
  eventName_(eventName),
@@ -77,8 +77,9 @@ void UIEventHandlerRegistry::processEvent(
77
77
  }
78
78
  }
79
79
 
80
- jsi::Runtime &rt = uiWorkletRuntime->getJSIRuntime();
81
- eventPayload.asObject(rt).setProperty(rt, "eventName", jsi::String::createFromUtf8(rt, eventName));
80
+ jsi::Runtime &uiRuntime = getJSIRuntimeFromWorkletRuntime(uiWorkletRuntime);
81
+ eventPayload.asObject(uiRuntime).setProperty(
82
+ uiRuntime, "eventName", jsi::String::createFromUtf8(uiRuntime, eventName));
82
83
  for (const auto &handler : handlersForEvent) {
83
84
  handler->process(uiWorkletRuntime, eventTimestamp, eventPayload);
84
85
  }
@@ -1,7 +1,7 @@
1
1
  #pragma once
2
2
 
3
3
  #include <jsi/jsi.h>
4
- #include <worklets/WorkletRuntime/WorkletRuntime.h>
4
+ #include <reanimated/Compat/WorkletsApi.h>
5
5
 
6
6
  #include <map>
7
7
  #include <memory>
@@ -53,12 +53,8 @@ void ReanimatedCommitHook::maybeInitializeLayoutAnimations(SurfaceId surfaceId)
53
53
  RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit(
54
54
  ShadowTree const &,
55
55
  RootShadowNode::Shared const &,
56
- RootShadowNode::Unshared const &newRootShadowNode
57
- #if REACT_NATIVE_MINOR_VERSION >= 80
58
- ,
59
- const ShadowTreeCommitOptions &commitOptions
60
- #endif
61
- ) noexcept {
56
+ RootShadowNode::Unshared const &newRootShadowNode,
57
+ const ShadowTreeCommitOptions &commitOptions) noexcept {
62
58
  ReanimatedSystraceSection s("ReanimatedCommitHook::shadowTreeWillCommit");
63
59
 
64
60
  maybeInitializeLayoutAnimations(newRootShadowNode->getSurfaceId());
@@ -73,7 +69,6 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit(
73
69
  return newRootShadowNode;
74
70
  }
75
71
 
76
- #if REACT_NATIVE_MINOR_VERSION >= 80
77
72
  if constexpr (StaticFeatureFlags::getFlag("USE_COMMIT_HOOK_ONLY_FOR_REACT_COMMITS")) {
78
73
  // State updates are based on the currently committed ShadowTree,
79
74
  // which means that all animation changes are already included.
@@ -82,7 +77,6 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit(
82
77
  return newRootShadowNode;
83
78
  }
84
79
  }
85
- #endif
86
80
 
87
81
  // ShadowTree not commited by Reanimated, apply updates from the updates
88
82
  // registry manager
@@ -29,12 +29,8 @@ class ReanimatedCommitHook : public UIManagerCommitHook, public std::enable_shar
29
29
  RootShadowNode::Unshared shadowTreeWillCommit(
30
30
  ShadowTree const &shadowTree,
31
31
  RootShadowNode::Shared const &oldRootShadowNode,
32
- RootShadowNode::Unshared const &newRootShadowNode
33
- #if REACT_NATIVE_MINOR_VERSION >= 80
34
- ,
35
- const ShadowTreeCommitOptions &commitOptions
36
- #endif
37
- ) noexcept override;
32
+ RootShadowNode::Unshared const &newRootShadowNode,
33
+ const ShadowTreeCommitOptions &commitOptions) noexcept override;
38
34
 
39
35
  private:
40
36
  std::shared_ptr<UIManager> uiManager_;
@@ -20,12 +20,7 @@ ReanimatedMountHook::~ReanimatedMountHook() noexcept {
20
20
 
21
21
  void ReanimatedMountHook::shadowTreeDidMount(
22
22
  const RootShadowNode::Shared &rootShadowNode,
23
- #if REACT_NATIVE_MINOR_VERSION >= 81
24
- HighResTimeStamp
25
- #else
26
- double
27
- #endif // REACT_NATIVE_MINOR_VERSION >= 81
28
- ) noexcept {
23
+ HighResTimeStamp mountTime) noexcept {
29
24
  ReanimatedSystraceSection s("ReanimatedMountHook::shadowTreeDidMount");
30
25
 
31
26
  auto reaShadowNode = std::reinterpret_pointer_cast<ReanimatedCommitShadowNode>(
@@ -19,14 +19,7 @@ class ReanimatedMountHook : public UIManagerMountHook {
19
19
  const std::function<void()> &requestFlush);
20
20
  ~ReanimatedMountHook() noexcept override;
21
21
 
22
- void shadowTreeDidMount(
23
- RootShadowNode::Shared const &rootShadowNode,
24
- #if REACT_NATIVE_MINOR_VERSION >= 81
25
- HighResTimeStamp mountTime
26
- #else
27
- double mountTime
28
- #endif // REACT_NATIVE_MINOR_VERSION >= 81
29
- ) noexcept override;
22
+ void shadowTreeDidMount(RootShadowNode::Shared const &rootShadowNode, HighResTimeStamp mountTime) noexcept override;
30
23
 
31
24
  private:
32
25
  const std::shared_ptr<UIManager> uiManager_;
@@ -6,17 +6,16 @@
6
6
 
7
7
  namespace reanimated {
8
8
 
9
- #if REACT_NATIVE_MINOR_VERSION >= 81
10
9
  static inline std::shared_ptr<const ShadowNode> shadowNodeFromValue(
11
10
  jsi::Runtime &rt,
12
11
  const jsi::Value &shadowNodeWrapper) {
13
12
  return Bridging<std::shared_ptr<const ShadowNode>>::fromJs(rt, shadowNodeWrapper);
14
13
  }
15
- #endif
16
14
 
17
15
  void AnimatedPropsRegistry::update(jsi::Runtime &rt, const jsi::Value &operations, const double timestamp) {
18
16
  auto operationsArray = operations.asObject(rt).asArray(rt);
19
17
 
18
+ std::lock_guard<std::mutex> lock{mutex_};
20
19
  for (size_t i = 0, length = operationsArray.size(rt); i < length; ++i) {
21
20
  auto item = operationsArray.getValueAtIndex(rt, i).asObject(rt);
22
21
  auto shadowNodeWrapper = item.getProperty(rt, "shadowNodeWrapper");
@@ -31,12 +30,13 @@ void AnimatedPropsRegistry::update(jsi::Runtime &rt, const jsi::Value &operation
31
30
  }
32
31
  }
33
32
 
34
- void AnimatedPropsRegistry::remove(const Tag tag) {
35
- updatesRegistry_.erase(tag);
36
- timestampMap_.erase(tag);
37
- }
33
+ jsi::Value AnimatedPropsRegistry::getUpdatesOlderThanTimestamp(
34
+ jsi::Runtime &rt,
35
+ const double timestamp,
36
+ const double cleanupTimestamp) {
37
+ std::lock_guard<std::mutex> lock{mutex_};
38
+ removeUpdatesOlderThanTimestamp(cleanupTimestamp);
38
39
 
39
- jsi::Value AnimatedPropsRegistry::getUpdatesOlderThanTimestamp(jsi::Runtime &rt, const double timestamp) {
40
40
  std::vector<std::pair<Tag, std::reference_wrapper<const folly::dynamic>>> updates;
41
41
 
42
42
  for (const auto &[viewTag, pair] : updatesRegistry_) {
@@ -71,4 +71,9 @@ void AnimatedPropsRegistry::removeUpdatesOlderThanTimestamp(const double timesta
71
71
  }
72
72
  }
73
73
 
74
+ void AnimatedPropsRegistry::removeTag(const Tag tag) {
75
+ updatesRegistry_.erase(tag);
76
+ timestampMap_.erase(tag);
77
+ }
78
+
74
79
  } // namespace reanimated
@@ -14,12 +14,15 @@ namespace reanimated {
14
14
  class AnimatedPropsRegistry : public UpdatesRegistry {
15
15
  public:
16
16
  void update(jsi::Runtime &rt, const jsi::Value &operations, double timestamp);
17
- void remove(Tag tag) override;
18
- jsi::Value getUpdatesOlderThanTimestamp(jsi::Runtime &rt, double timestamp);
19
- void removeUpdatesOlderThanTimestamp(double timestamp);
17
+
18
+ /// Also removes updates older than `cleanupTimestamp` from the registry.
19
+ jsi::Value getUpdatesOlderThanTimestamp(jsi::Runtime &rt, double timestamp, double cleanupTimestamp);
20
20
 
21
21
  private:
22
22
  std::unordered_map<Tag, double> timestampMap_; // viewTag -> timestamp, protected by `mutex_`
23
+
24
+ void removeUpdatesOlderThanTimestamp(double timestamp);
25
+ void removeTag(Tag tag) override;
23
26
  };
24
27
 
25
28
  } // namespace reanimated
@@ -8,11 +8,8 @@
8
8
 
9
9
  namespace reanimated {
10
10
 
11
- std::lock_guard<std::mutex> UpdatesRegistry::lock() const {
12
- return std::lock_guard<std::mutex>{mutex_};
13
- }
14
-
15
11
  bool UpdatesRegistry::isEmpty() const {
12
+ std::lock_guard<std::mutex> lock{mutex_};
16
13
  return updatesRegistry_.empty();
17
14
  }
18
15
 
@@ -26,7 +23,7 @@ folly::dynamic UpdatesRegistry::get(const Tag tag) const {
26
23
  return it->second.second;
27
24
  }
28
25
 
29
- void UpdatesRegistry::flushUpdates(UpdatesBatch &updatesBatch) {
26
+ void UpdatesRegistry::flush(UpdatesBatch &updatesBatch) {
30
27
  auto copiedUpdatesBatch = std::move(updatesBatch_);
31
28
  updatesBatch_.clear();
32
29
 
@@ -39,7 +36,7 @@ void UpdatesRegistry::flushUpdates(UpdatesBatch &updatesBatch) {
39
36
  }
40
37
 
41
38
  UpdatesBatch UpdatesRegistry::getPendingUpdates() {
42
- auto lock = std::lock_guard<std::mutex>{mutex_};
39
+ std::lock_guard<std::mutex> lock{mutex_};
43
40
  flushUpdatesToRegistry(updatesBatch_);
44
41
 
45
42
  UpdatesBatch updatesBatch;
@@ -116,6 +113,7 @@ void UpdatesRegistry::flushUpdatesToRegistry(const UpdatesBatch &updatesBatch) {
116
113
  #ifdef ANDROID
117
114
 
118
115
  bool UpdatesRegistry::hasPropsToRevert() const {
116
+ std::lock_guard<std::mutex> lock{mutex_};
119
117
  return !propsToRevertMap_.empty();
120
118
  }
121
119
 
@@ -1,11 +1,11 @@
1
1
  #pragma once
2
2
 
3
- #include <reanimated/Fabric/ShadowTreeCloner.h>
4
-
3
+ #include <jsi/jsi.h>
5
4
  #include <react/renderer/core/ShadowNode.h>
5
+ #include <reanimated/Fabric/ShadowTreeCloner.h>
6
6
 
7
- #include <jsi/jsi.h>
8
7
  #include <memory>
8
+ #include <mutex>
9
9
  #include <string>
10
10
  #include <unordered_map>
11
11
  #include <unordered_set>
@@ -33,18 +33,23 @@ class UpdatesRegistry {
33
33
  public:
34
34
  virtual ~UpdatesRegistry() {}
35
35
 
36
- std::lock_guard<std::mutex> lock() const;
37
-
38
36
  virtual bool isEmpty() const;
39
37
  folly::dynamic get(Tag tag) const;
40
- virtual void remove(Tag tag) = 0;
38
+ void remove(Tag tag) {
39
+ std::lock_guard<std::mutex> lock{mutex_};
40
+ removeTag(tag);
41
+ }
41
42
 
42
43
  #ifdef ANDROID
43
44
  bool hasPropsToRevert() const;
44
45
  void collectPropsToRevert(PropsToRevertMap &propsToRevertMap);
45
46
  #endif
46
47
 
47
- void flushUpdates(UpdatesBatch &updatesBatch);
48
+ void flushUpdates(UpdatesBatch &updatesBatch) {
49
+ std::lock_guard<std::mutex> lock{mutex_};
50
+ flush(updatesBatch);
51
+ }
52
+
48
53
  void collectProps(PropsMap &propsMap);
49
54
  UpdatesBatch getPendingUpdates();
50
55
 
@@ -52,9 +57,22 @@ class UpdatesRegistry {
52
57
  mutable std::mutex mutex_;
53
58
  RegistryMap updatesRegistry_;
54
59
 
60
+ /// Assumes the caller already locked the registry.
61
+ void flush(UpdatesBatch &updatesBatch);
62
+
63
+ /// Assumes the caller already locked the registry.
64
+ virtual void removeTag(Tag tag) = 0;
65
+
66
+ /// Assumes the caller already locked the registry.
55
67
  void addUpdatesToBatch(const std::shared_ptr<const ShadowNode> &shadowNode, const folly::dynamic &props);
68
+
69
+ /// Assumes the caller already locked the registry.
56
70
  folly::dynamic getUpdatesFromRegistry(const Tag tag) const;
71
+
72
+ /// Assumes the caller already locked the registry.
57
73
  void setInUpdatesRegistry(const std::shared_ptr<const ShadowNode> &shadowNode, const folly::dynamic &props);
74
+
75
+ /// Assumes the caller already locked the registry.
58
76
  void removeFromUpdatesRegistry(Tag tag);
59
77
 
60
78
  private:
@@ -2,10 +2,9 @@
2
2
 
3
3
  #include <react/renderer/graphics/Transform.h>
4
4
  #include <react/renderer/mounting/ShadowView.h>
5
+ #include <reanimated/Compat/WorkletsApi.h>
5
6
  #include <reanimated/LayoutAnimations/LayoutAnimationType.h>
6
7
 
7
- #include <worklets/SharedItems/Serializable.h>
8
-
9
8
  #include <jsi/jsi.h>
10
9
  #include <stdio.h>
11
10
  #include <functional>
@@ -4,9 +4,9 @@
4
4
  #include <react/renderer/componentregistry/ComponentDescriptorFactory.h>
5
5
  #include <react/renderer/mounting/MountingOverrideDelegate.h>
6
6
  #include <react/renderer/uimanager/UIManager.h>
7
+ #include <reanimated/Compat/WorkletsApi.h>
7
8
  #include <reanimated/LayoutAnimations/LayoutAnimationsManager.h>
8
9
  #include <reanimated/Tools/PlatformDepMethodsHolder.h>
9
- #include <worklets/Tools/UIScheduler.h>
10
10
 
11
11
  #include <memory>
12
12
  #include <optional>