@react-native-ohos/react-native-reanimated 3.18.1-rc.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 (113) hide show
  1. package/harmony/reanimated/BuildProfile.ets +17 -0
  2. package/harmony/reanimated/build-profile.json5 +12 -0
  3. package/harmony/reanimated/hvigorfile.ts +5 -0
  4. package/harmony/reanimated/index.ets +5 -0
  5. package/harmony/reanimated/oh-package.json5 +12 -0
  6. package/harmony/reanimated/src/main/cpp/CMakeLists.txt +72 -0
  7. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp +86 -0
  8. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h +47 -0
  9. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.cpp +68 -0
  10. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.h +68 -0
  11. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +101 -0
  12. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +51 -0
  13. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitShadowNode.h +49 -0
  14. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +87 -0
  15. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +33 -0
  16. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.cpp +95 -0
  17. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h +29 -0
  18. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationType.h +9 -0
  19. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp +232 -0
  20. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h +90 -0
  21. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp +870 -0
  22. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +147 -0
  23. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp +91 -0
  24. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +176 -0
  25. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +971 -0
  26. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +252 -0
  27. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.cpp +231 -0
  28. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.h +109 -0
  29. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.cpp +56 -0
  30. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.h +20 -0
  31. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp +70 -0
  32. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h +35 -0
  33. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/CollectionUtils.h +14 -0
  34. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.cpp +5 -0
  35. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.h +19 -0
  36. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +98 -0
  37. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedSystraceSection.h +135 -0
  38. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +47 -0
  39. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +59 -0
  40. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.cpp +27 -0
  41. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.h +25 -0
  42. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +94 -0
  43. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.h +49 -0
  44. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +8 -0
  45. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +39 -0
  46. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.cpp +326 -0
  47. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.h +345 -0
  48. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.cpp +52 -0
  49. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.h +35 -0
  50. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/Defs.h +10 -0
  51. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.cpp +342 -0
  52. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.h +47 -0
  53. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.cpp +16 -0
  54. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.h +20 -0
  55. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.cpp +20 -0
  56. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.h +29 -0
  57. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/PlatformLogger.h +16 -0
  58. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.cpp +26 -0
  59. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.h +199 -0
  60. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.cpp +95 -0
  61. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.h +19 -0
  62. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/SingleInstanceChecker.h +72 -0
  63. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -0
  64. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.cpp +20 -0
  65. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.h +22 -0
  66. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +29 -0
  67. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.h +41 -0
  68. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +16 -0
  69. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +19 -0
  70. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.cpp +112 -0
  71. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.h +127 -0
  72. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.cpp +53 -0
  73. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.h +22 -0
  74. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RuntimeInitialization.md +191 -0
  75. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +155 -0
  76. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +90 -0
  77. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -0
  78. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +182 -0
  79. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +22 -0
  80. package/harmony/reanimated/src/main/cpp/ReanimatedLogger.cpp +33 -0
  81. package/harmony/reanimated/src/main/cpp/ReanimatedModule.cpp +222 -0
  82. package/harmony/reanimated/src/main/cpp/ReanimatedModule.h +24 -0
  83. package/harmony/reanimated/src/main/cpp/ReanimatedNodesManager.cpp +56 -0
  84. package/harmony/reanimated/src/main/cpp/ReanimatedNodesManager.h +31 -0
  85. package/harmony/reanimated/src/main/cpp/ReanimatedPackage.cpp +47 -0
  86. package/harmony/reanimated/src/main/cpp/ReanimatedPackage.h +16 -0
  87. package/harmony/reanimated/src/main/cpp/ReanimatedUIScheduler.cpp +23 -0
  88. package/harmony/reanimated/src/main/cpp/ReanimatedUIScheduler.h +20 -0
  89. package/harmony/reanimated/src/main/cpp/TransformParser.h +94 -0
  90. package/harmony/reanimated/src/main/cpp/WorkletsModule.cpp +58 -0
  91. package/harmony/reanimated/src/main/cpp/WorkletsModule.h +22 -0
  92. package/harmony/reanimated/src/main/cpp/patches/AnimatedSensor/AnimatedSensorModule.cpp +89 -0
  93. package/harmony/reanimated/src/main/cpp/patches/Fabric/ShadowTreeCloner.cpp +95 -0
  94. package/harmony/reanimated/src/main/cpp/patches/NativeModules/ReanimatedModuleProxy.cpp +961 -0
  95. package/harmony/reanimated/src/main/ets/AnimationManager.ts +61 -0
  96. package/harmony/reanimated/src/main/ets/ReanimatedModule.ts +41 -0
  97. package/harmony/reanimated/src/main/ets/ReanimatedPackage.ts +29 -0
  98. package/harmony/reanimated/src/main/ets/WorkletsModule.ts +15 -0
  99. package/harmony/reanimated/src/main/module.json5 +13 -0
  100. package/harmony/reanimated/src/main/resources/base/element/color.json +8 -0
  101. package/harmony/reanimated/src/main/resources/base/element/string.json +16 -0
  102. package/harmony/reanimated/src/main/resources/base/media/icon.png +0 -0
  103. package/harmony/reanimated/src/main/resources/base/media/startIcon.png +0 -0
  104. package/harmony/reanimated/src/main/resources/base/profile/main_pages.json +5 -0
  105. package/harmony/reanimated/src/main/resources/en_US/element/string.json +16 -0
  106. package/harmony/reanimated/src/main/resources/zh_CN/element/string.json +16 -0
  107. package/harmony/reanimated/ts.ts +6 -0
  108. package/harmony/reanimated.har +0 -0
  109. package/lib/index.d.ts +4 -0
  110. package/lib/index.d.ts.map +1 -0
  111. package/lib/index.js +7 -0
  112. package/package.json +50 -0
  113. package/src/index.ts +10 -0
@@ -0,0 +1,87 @@
1
+ #ifdef RCT_NEW_ARCH_ENABLED
2
+
3
+ #include <reanimated/Fabric/ReanimatedCommitShadowNode.h>
4
+ #include <reanimated/Fabric/ReanimatedMountHook.h>
5
+
6
+ namespace reanimated {
7
+
8
+ ReanimatedMountHook::ReanimatedMountHook(
9
+ const std::shared_ptr<PropsRegistry> &propsRegistry,
10
+ const std::shared_ptr<UIManager> &uiManager)
11
+ : propsRegistry_(propsRegistry), uiManager_(uiManager) {
12
+ uiManager_->registerMountHook(*this);
13
+ }
14
+
15
+ ReanimatedMountHook::~ReanimatedMountHook() noexcept {
16
+ uiManager_->unregisterMountHook(*this);
17
+ }
18
+
19
+ void ReanimatedMountHook::shadowTreeDidMount(
20
+ const RootShadowNode::Shared &rootShadowNode,
21
+ double) noexcept {
22
+ auto reaShadowNode =
23
+ std::reinterpret_pointer_cast<ReanimatedCommitShadowNode>(
24
+ std::const_pointer_cast<RootShadowNode>(rootShadowNode));
25
+
26
+ if (reaShadowNode->hasReanimatedMountTrait()) {
27
+ // We mark reanimated commits with ReanimatedMountTrait. We don't want other
28
+ // shadow nodes to use this trait, but since this rootShadowNode is Shared,
29
+ // we don't have that guarantee. That's why we also unset this trait in the
30
+ // commit hook. We remove it here mainly for the sake of cleanliness.
31
+ reaShadowNode->unsetReanimatedMountTrait();
32
+ return;
33
+ }
34
+
35
+ {
36
+ auto lock = propsRegistry_->createLock();
37
+ propsRegistry_->handleNodeRemovals(*rootShadowNode);
38
+
39
+ // When commit from React Native has finished, we reset the skip commit flag
40
+ // in order to allow Reanimated to commit its tree
41
+ propsRegistry_->unpauseReanimatedCommits();
42
+ if (!propsRegistry_->shouldCommitAfterPause()) {
43
+ return;
44
+ }
45
+ }
46
+
47
+ const auto &shadowTreeRegistry = uiManager_->getShadowTreeRegistry();
48
+ shadowTreeRegistry.visit(
49
+ rootShadowNode->getSurfaceId(), [&](ShadowTree const &shadowTree) {
50
+ shadowTree.commit(
51
+ [&](RootShadowNode const &oldRootShadowNode)
52
+ -> RootShadowNode::Unshared {
53
+ PropsMap propsMap;
54
+
55
+ RootShadowNode::Unshared rootNode =
56
+ std::static_pointer_cast<RootShadowNode>(
57
+ oldRootShadowNode.ShadowNode::clone({}));
58
+ {
59
+ auto lock = propsRegistry_->createLock();
60
+
61
+ propsRegistry_->for_each([&](const ShadowNodeFamily &family,
62
+ const folly::dynamic &props) {
63
+ propsMap[&family].emplace_back(props);
64
+ });
65
+
66
+ rootNode =
67
+ cloneShadowTreeWithNewProps(oldRootShadowNode, propsMap);
68
+ }
69
+
70
+ // Mark the commit as Reanimated commit so that we can
71
+ // distinguish it in ReanimatedCommitHook.
72
+ auto reaShadowNode =
73
+ std::reinterpret_pointer_cast<ReanimatedCommitShadowNode>(
74
+ rootNode);
75
+ reaShadowNode->setReanimatedCommitTrait();
76
+
77
+ return rootNode;
78
+ },
79
+ {/* .enableStateReconciliation = */
80
+ false,
81
+ /* .mountSynchronously = */ true});
82
+ });
83
+ }
84
+
85
+ } // namespace reanimated
86
+
87
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -0,0 +1,33 @@
1
+ #pragma once
2
+ #ifdef RCT_NEW_ARCH_ENABLED
3
+
4
+ #include <reanimated/Fabric/PropsRegistry.h>
5
+ #include <reanimated/Fabric/ShadowTreeCloner.h>
6
+
7
+ #include <react/renderer/uimanager/UIManagerMountHook.h>
8
+
9
+ #include <memory>
10
+
11
+ namespace reanimated {
12
+
13
+ using namespace facebook::react;
14
+
15
+ class ReanimatedMountHook : public UIManagerMountHook {
16
+ public:
17
+ ReanimatedMountHook(
18
+ const std::shared_ptr<PropsRegistry> &propsRegistry,
19
+ const std::shared_ptr<UIManager> &uiManager);
20
+ ~ReanimatedMountHook() noexcept override;
21
+
22
+ void shadowTreeDidMount(
23
+ RootShadowNode::Shared const &rootShadowNode,
24
+ double mountTime) noexcept override;
25
+
26
+ private:
27
+ const std::shared_ptr<PropsRegistry> propsRegistry_;
28
+ const std::shared_ptr<UIManager> uiManager_;
29
+ };
30
+
31
+ } // namespace reanimated
32
+
33
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -0,0 +1,95 @@
1
+ #ifdef RCT_NEW_ARCH_ENABLED
2
+
3
+ #include <reanimated/Fabric/ShadowTreeCloner.h>
4
+
5
+ #include <ranges>
6
+ #include <utility>
7
+
8
+ namespace reanimated {
9
+
10
+ Props::Shared mergeProps(
11
+ const ShadowNode &shadowNode,
12
+ const PropsMap &propsMap,
13
+ const ShadowNodeFamily &family) {
14
+ const auto it = propsMap.find(&family);
15
+
16
+ if (it == propsMap.end()) {
17
+ return ShadowNodeFragment::propsPlaceholder();
18
+ }
19
+
20
+ PropsParserContext propsParserContext{
21
+ shadowNode.getSurfaceId(), *shadowNode.getContextContainer()};
22
+ const auto &propsVector = it->second;
23
+ auto newProps = shadowNode.getProps();
24
+
25
+ #ifdef ANDROID
26
+ if (propsVector.size() > 1) {
27
+ folly::dynamic newPropsDynamic = folly::dynamic::object;
28
+ for (const auto &props : propsVector) {
29
+ newPropsDynamic = folly::dynamic::merge(
30
+ props.operator folly::dynamic(), newPropsDynamic);
31
+ }
32
+ return shadowNode.getComponentDescriptor().cloneProps(
33
+ propsParserContext, newProps, RawProps(newPropsDynamic));
34
+ }
35
+ #endif
36
+
37
+ for (const auto &props : propsVector) {
38
+ newProps = shadowNode.getComponentDescriptor().cloneProps(
39
+ propsParserContext, newProps, RawProps(props));
40
+ }
41
+
42
+ return newProps;
43
+ }
44
+
45
+ ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive(
46
+ const ShadowNode &shadowNode,
47
+ const ChildrenMap &childrenMap,
48
+ const PropsMap &propsMap) {
49
+ const auto family = &shadowNode.getFamily();
50
+ const auto affectedChildrenIt = childrenMap.find(family);
51
+ auto children = shadowNode.getChildren();
52
+
53
+ if (affectedChildrenIt != childrenMap.end()) {
54
+ for (const auto index : affectedChildrenIt->second) {
55
+ children[index] = cloneShadowTreeWithNewPropsRecursive(
56
+ *children[index], childrenMap, propsMap);
57
+ }
58
+ }
59
+
60
+ return shadowNode.clone(
61
+ {mergeProps(shadowNode, propsMap, *family),
62
+ std::make_shared<ShadowNode::ListOfShared>(children),
63
+ shadowNode.getState()});
64
+ }
65
+
66
+ RootShadowNode::Unshared cloneShadowTreeWithNewProps(
67
+ const RootShadowNode &oldRootNode,
68
+ const PropsMap &propsMap) {
69
+ ChildrenMap childrenMap;
70
+
71
+ for (auto &[family, _] : propsMap) {
72
+ const auto ancestors = family->getAncestors(oldRootNode);
73
+
74
+ for (const auto &[parentNode, index] :
75
+ std::ranges::reverse_view(ancestors)) {
76
+ const auto parentFamily = &parentNode.get().getFamily();
77
+ auto &affectedChildren = childrenMap[parentFamily];
78
+
79
+ if (affectedChildren.contains(index)) {
80
+ continue;
81
+ }
82
+
83
+ affectedChildren.insert(index);
84
+ }
85
+ }
86
+
87
+ // This cast is safe, because this function returns a clone
88
+ // of the oldRootNode, which is an instance of RootShadowNode
89
+ return std::static_pointer_cast<RootShadowNode>(
90
+ cloneShadowTreeWithNewPropsRecursive(oldRootNode, childrenMap, propsMap));
91
+ }
92
+
93
+ } // namespace reanimated
94
+
95
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -0,0 +1,29 @@
1
+ #pragma once
2
+ #ifdef RCT_NEW_ARCH_ENABLED
3
+
4
+ #include <react/renderer/core/PropsParserContext.h>
5
+ #include <react/renderer/uimanager/UIManager.h>
6
+
7
+ #include <memory>
8
+ #include <type_traits>
9
+ #include <unordered_map>
10
+ #include <unordered_set>
11
+ #include <vector>
12
+
13
+ using namespace facebook;
14
+ using namespace react;
15
+
16
+ namespace reanimated {
17
+
18
+ using PropsMap =
19
+ std::unordered_map<const ShadowNodeFamily *, std::vector<RawProps>>;
20
+ using ChildrenMap =
21
+ std::unordered_map<const ShadowNodeFamily *, std::unordered_set<int>>;
22
+
23
+ RootShadowNode::Unshared cloneShadowTreeWithNewProps(
24
+ const RootShadowNode &oldRootNode,
25
+ const PropsMap &propsMap);
26
+
27
+ } // namespace reanimated
28
+
29
+ #endif // RCT_NEW_ARCH_ENABLED
@@ -0,0 +1,9 @@
1
+ #pragma once
2
+
3
+ typedef enum LayoutAnimationType {
4
+ ENTERING = 1,
5
+ EXITING = 2,
6
+ LAYOUT = 3,
7
+ SHARED_ELEMENT_TRANSITION = 4,
8
+ SHARED_ELEMENT_TRANSITION_PROGRESS = 5,
9
+ } LayoutAnimationType;
@@ -0,0 +1,232 @@
1
+ #include <reanimated/LayoutAnimations/LayoutAnimationsManager.h>
2
+ #include <reanimated/Tools/CollectionUtils.h>
3
+
4
+ #ifndef NDEBUG
5
+ #include <utility>
6
+ #endif
7
+
8
+ namespace reanimated {
9
+
10
+ void LayoutAnimationsManager::configureAnimationBatch(
11
+ const std::vector<LayoutAnimationConfig> &layoutAnimationsBatch) {
12
+ auto lock = std::unique_lock<std::recursive_mutex>(animationsMutex_);
13
+ std::vector<LayoutAnimationConfig> sharedTransitionConfigs;
14
+ for (auto layoutAnimationConfig : layoutAnimationsBatch) {
15
+ const auto &[tag, type, config, sharedTransitionTag] =
16
+ layoutAnimationConfig;
17
+ if (type == SHARED_ELEMENT_TRANSITION ||
18
+ type == SHARED_ELEMENT_TRANSITION_PROGRESS) {
19
+ clearSharedTransitionConfig(tag);
20
+ sharedTransitionConfigs.push_back(std::move(layoutAnimationConfig));
21
+ } else {
22
+ #ifdef RCT_NEW_ARCH_ENABLED
23
+ if (type == ENTERING) {
24
+ enteringAnimationsForNativeID_[tag] = config;
25
+ continue;
26
+ }
27
+ #endif
28
+ if (config == nullptr) {
29
+ getConfigsForType(type).erase(tag);
30
+ } else {
31
+ getConfigsForType(type)[tag] = config;
32
+ }
33
+ }
34
+ }
35
+ for (const auto &[tag, type, config, sharedTransitionTag] :
36
+ sharedTransitionConfigs) {
37
+ if (config == nullptr) {
38
+ continue;
39
+ }
40
+ sharedTransitionGroups_[sharedTransitionTag].push_back(tag);
41
+ viewTagToSharedTag_[tag] = sharedTransitionTag;
42
+ getConfigsForType(SHARED_ELEMENT_TRANSITION)[tag] = config;
43
+ if (type == SHARED_ELEMENT_TRANSITION) {
44
+ ignoreProgressAnimationForTag_.insert(tag);
45
+ }
46
+ }
47
+ }
48
+
49
+ void LayoutAnimationsManager::setShouldAnimateExiting(
50
+ const int tag,
51
+ const bool value) {
52
+ auto lock = std::unique_lock<std::recursive_mutex>(animationsMutex_);
53
+ shouldAnimateExitingForTag_[tag] = value;
54
+ }
55
+
56
+ bool LayoutAnimationsManager::shouldAnimateExiting(
57
+ const int tag,
58
+ const bool shouldAnimate) {
59
+ auto lock = std::unique_lock<std::recursive_mutex>(animationsMutex_);
60
+ return collection::contains(shouldAnimateExitingForTag_, tag)
61
+ ? shouldAnimateExitingForTag_[tag]
62
+ : shouldAnimate;
63
+ }
64
+
65
+ bool LayoutAnimationsManager::hasLayoutAnimation(
66
+ const int tag,
67
+ const LayoutAnimationType type) {
68
+ auto lock = std::unique_lock<std::recursive_mutex>(animationsMutex_);
69
+ if (type == SHARED_ELEMENT_TRANSITION_PROGRESS) {
70
+ auto end = ignoreProgressAnimationForTag_.end();
71
+ return ignoreProgressAnimationForTag_.find(tag) == end;
72
+ }
73
+ return collection::contains(getConfigsForType(type), tag);
74
+ }
75
+
76
+ void LayoutAnimationsManager::clearSharedTransitionConfig(const int tag) {
77
+ auto lock = std::unique_lock<std::recursive_mutex>(animationsMutex_);
78
+ #ifndef NDEBUG
79
+ const auto &pair = viewsScreenSharedTagMap_[tag];
80
+ screenSharedTagSet_.erase(pair);
81
+ viewsScreenSharedTagMap_.erase(tag);
82
+ #endif // NDEBUG
83
+
84
+ sharedTransitionAnimations_.erase(tag);
85
+ auto const &groupName = viewTagToSharedTag_[tag];
86
+ if (groupName.empty()) {
87
+ viewTagToSharedTag_.erase(tag);
88
+ return;
89
+ }
90
+ auto &group = sharedTransitionGroups_[groupName];
91
+ auto position = std::find(group.begin(), group.end(), tag);
92
+ if (position != group.end()) {
93
+ group.erase(position);
94
+ }
95
+ if (group.size() == 0) {
96
+ sharedTransitionGroups_.erase(groupName);
97
+ }
98
+ viewTagToSharedTag_.erase(tag);
99
+ ignoreProgressAnimationForTag_.erase(tag);
100
+ }
101
+
102
+ void LayoutAnimationsManager::clearLayoutAnimationConfig(const int tag) {
103
+ auto lock = std::unique_lock<std::recursive_mutex>(animationsMutex_);
104
+ enteringAnimations_.erase(tag);
105
+ exitingAnimations_.erase(tag);
106
+ layoutAnimations_.erase(tag);
107
+ shouldAnimateExitingForTag_.erase(tag);
108
+ clearSharedTransitionConfig(tag);
109
+ }
110
+
111
+ void LayoutAnimationsManager::startLayoutAnimation(
112
+ jsi::Runtime &rt,
113
+ const int tag,
114
+ const LayoutAnimationType type,
115
+ const jsi::Object &values) {
116
+ std::shared_ptr<Shareable> config, viewShareable;
117
+ {
118
+ auto lock = std::unique_lock<std::recursive_mutex>(animationsMutex_);
119
+ if (!collection::contains(getConfigsForType(type), tag)) {
120
+ return;
121
+ }
122
+ config = getConfigsForType(type)[tag];
123
+ }
124
+ // TODO: cache the following!!
125
+ jsi::Value layoutAnimationRepositoryAsValue =
126
+ rt.global()
127
+ .getPropertyAsObject(rt, "global")
128
+ .getProperty(rt, "LayoutAnimationsManager");
129
+ jsi::Function startAnimationForTag =
130
+ layoutAnimationRepositoryAsValue.getObject(rt).getPropertyAsFunction(
131
+ rt, "start");
132
+ startAnimationForTag.call(
133
+ rt,
134
+ jsi::Value(tag),
135
+ jsi::Value(static_cast<int>(type)),
136
+ values,
137
+ config->toJSValue(rt));
138
+ }
139
+
140
+ void LayoutAnimationsManager::cancelLayoutAnimation(
141
+ jsi::Runtime &rt,
142
+ const int tag) const {
143
+ jsi::Value layoutAnimationRepositoryAsValue =
144
+ rt.global()
145
+ .getPropertyAsObject(rt, "global")
146
+ .getProperty(rt, "LayoutAnimationsManager");
147
+ jsi::Function cancelLayoutAnimation =
148
+ layoutAnimationRepositoryAsValue.getObject(rt).getPropertyAsFunction(
149
+ rt, "stop");
150
+ cancelLayoutAnimation.call(rt, jsi::Value(tag));
151
+ }
152
+
153
+ /*
154
+ The top screen on the stack triggers the animation, so we need to find
155
+ the sibling view registered in the past. This method finds view
156
+ registered in the same transition group (with the same transition tag)
157
+ which has been added to that group directly before the one that we
158
+ provide as an argument.
159
+ */
160
+ int LayoutAnimationsManager::findPrecedingViewTagForTransition(const int tag) {
161
+ auto const &groupName = viewTagToSharedTag_[tag];
162
+ auto const &group = sharedTransitionGroups_[groupName];
163
+ auto position = std::find(group.begin(), group.end(), tag);
164
+ if (position != group.end() && position != group.begin()) {
165
+ return *std::prev(position);
166
+ }
167
+ return -1;
168
+ }
169
+
170
+ const std::vector<int> &LayoutAnimationsManager::getSharedGroup(
171
+ const int viewTag) {
172
+ const auto &groupSharedTag = viewTagToSharedTag_[viewTag];
173
+ return sharedTransitionGroups_[groupSharedTag];
174
+ }
175
+
176
+ #ifdef RCT_NEW_ARCH_ENABLED
177
+ void LayoutAnimationsManager::transferConfigFromNativeID(
178
+ const int nativeId,
179
+ const int tag) {
180
+ auto lock = std::unique_lock<std::recursive_mutex>(animationsMutex_);
181
+ auto config = enteringAnimationsForNativeID_[nativeId];
182
+ if (config) {
183
+ enteringAnimations_.insert_or_assign(tag, config);
184
+ }
185
+ enteringAnimationsForNativeID_.erase(nativeId);
186
+ }
187
+ #endif
188
+
189
+ #ifndef NDEBUG
190
+ std::string LayoutAnimationsManager::getScreenSharedTagPairString(
191
+ const int screenTag,
192
+ const std::string &sharedTag) const {
193
+ return std::to_string(screenTag) + ":" + sharedTag;
194
+ }
195
+
196
+ void LayoutAnimationsManager::checkDuplicateSharedTag(
197
+ const int viewTag,
198
+ const int screenTag) {
199
+ if (!viewTagToSharedTag_.count(viewTag)) {
200
+ return;
201
+ }
202
+ const auto &sharedTag = viewTagToSharedTag_[viewTag];
203
+ const auto &pair = getScreenSharedTagPairString(screenTag, sharedTag);
204
+ bool hasDuplicate = screenSharedTagSet_.count(pair);
205
+ if (hasDuplicate) {
206
+ jsLogger_->warnOnJS(
207
+ "[Reanimated] Duplicate shared tag \"" + sharedTag +
208
+ "\" on the same screen");
209
+ }
210
+ viewsScreenSharedTagMap_[viewTag] = pair;
211
+ screenSharedTagSet_.insert(pair);
212
+ }
213
+ #endif // NDEBUG
214
+
215
+ std::unordered_map<int, std::shared_ptr<Shareable>> &
216
+ LayoutAnimationsManager::getConfigsForType(const LayoutAnimationType type) {
217
+ switch (type) {
218
+ case ENTERING:
219
+ return enteringAnimations_;
220
+ case EXITING:
221
+ return exitingAnimations_;
222
+ case LAYOUT:
223
+ return layoutAnimations_;
224
+ case SHARED_ELEMENT_TRANSITION:
225
+ case SHARED_ELEMENT_TRANSITION_PROGRESS:
226
+ return sharedTransitionAnimations_;
227
+ default:
228
+ assert(false);
229
+ }
230
+ }
231
+
232
+ } // namespace reanimated
@@ -0,0 +1,90 @@
1
+ #pragma once
2
+
3
+ #include <reanimated/LayoutAnimations/LayoutAnimationType.h>
4
+
5
+ #include <worklets/SharedItems/Shareables.h>
6
+ #include <worklets/Tools/JSLogger.h>
7
+
8
+ #include <jsi/jsi.h>
9
+ #include <stdio.h>
10
+ #include <functional>
11
+ #include <memory>
12
+ #include <mutex>
13
+ #include <string>
14
+ #include <unordered_map>
15
+ #include <unordered_set>
16
+ #include <vector>
17
+
18
+ namespace reanimated {
19
+
20
+ using namespace facebook;
21
+ using namespace worklets;
22
+
23
+ struct LayoutAnimationConfig {
24
+ int tag;
25
+ LayoutAnimationType type;
26
+ std::shared_ptr<Shareable> config;
27
+ std::string sharedTransitionTag;
28
+ };
29
+
30
+ class LayoutAnimationsManager {
31
+ public:
32
+ explicit LayoutAnimationsManager(const std::shared_ptr<JSLogger> &jsLogger)
33
+ : jsLogger_(jsLogger) {}
34
+ void configureAnimationBatch(
35
+ const std::vector<LayoutAnimationConfig> &layoutAnimationsBatch);
36
+ void setShouldAnimateExiting(const int tag, const bool value);
37
+ bool shouldAnimateExiting(const int tag, const bool shouldAnimate);
38
+ bool hasLayoutAnimation(const int tag, const LayoutAnimationType type);
39
+ void startLayoutAnimation(
40
+ jsi::Runtime &rt,
41
+ const int tag,
42
+ const LayoutAnimationType type,
43
+ const jsi::Object &values);
44
+ void clearLayoutAnimationConfig(const int tag);
45
+ void clearSharedTransitionConfig(const int tag);
46
+ void cancelLayoutAnimation(jsi::Runtime &rt, const int tag) const;
47
+ #ifdef RCT_NEW_ARCH_ENABLED
48
+ void transferConfigFromNativeID(const int nativeId, const int tag);
49
+ #endif
50
+ int findPrecedingViewTagForTransition(const int tag);
51
+ const std::vector<int> &getSharedGroup(const int viewTag);
52
+ #ifndef NDEBUG
53
+ std::string getScreenSharedTagPairString(
54
+ const int screenTag,
55
+ const std::string &sharedTag) const;
56
+ void checkDuplicateSharedTag(const int viewTag, const int screenTag);
57
+ #endif
58
+
59
+ private:
60
+ std::unordered_map<int, std::shared_ptr<Shareable>> &getConfigsForType(
61
+ const LayoutAnimationType type);
62
+
63
+ std::shared_ptr<JSLogger> jsLogger_;
64
+ #ifndef NDEBUG
65
+ // This set's function is to detect duplicate sharedTags on a single screen
66
+ // it contains strings in form: "reactScreenTag:sharedTag"
67
+ std::unordered_set<std::string> screenSharedTagSet_;
68
+ // And this map is to remove collected pairs on SET removal
69
+ std::unordered_map<int, std::string> viewsScreenSharedTagMap_;
70
+ #endif
71
+
72
+ #ifdef RCT_NEW_ARCH_ENABLED
73
+ std::unordered_map<int, std::shared_ptr<Shareable>>
74
+ enteringAnimationsForNativeID_;
75
+ #endif
76
+ std::unordered_map<int, std::shared_ptr<Shareable>> enteringAnimations_;
77
+ std::unordered_map<int, std::shared_ptr<Shareable>> exitingAnimations_;
78
+ std::unordered_map<int, std::shared_ptr<Shareable>> layoutAnimations_;
79
+ std::unordered_map<int, std::shared_ptr<Shareable>>
80
+ sharedTransitionAnimations_;
81
+ std::unordered_set<int> ignoreProgressAnimationForTag_;
82
+ std::unordered_map<std::string, std::vector<int>> sharedTransitionGroups_;
83
+ std::unordered_map<int, std::string> viewTagToSharedTag_;
84
+ std::unordered_map<int, bool> shouldAnimateExitingForTag_;
85
+ mutable std::recursive_mutex
86
+ animationsMutex_; // Protects `enteringAnimations_`, `exitingAnimations_`,
87
+ // `layoutAnimations_`, `viewSharedValues_` and `shouldAnimateExitingForTag_`.
88
+ };
89
+
90
+ } // namespace reanimated