@react-native-ohos/react-native-reanimated 3.18.2 → 3.18.3-beta.2

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 (94) hide show
  1. package/LICENSE +21 -21
  2. package/README.OpenSource +10 -10
  3. package/README.md +10 -10
  4. package/harmony/reanimated/BuildProfile.ets +1 -1
  5. package/harmony/reanimated/build-profile.json5 +11 -11
  6. package/harmony/reanimated/oh-package-lock.json5 +29 -0
  7. package/harmony/reanimated/oh-package.json5 +11 -11
  8. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp +86 -86
  9. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h +47 -47
  10. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.cpp +68 -68
  11. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.h +73 -68
  12. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +101 -101
  13. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +51 -51
  14. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitShadowNode.h +49 -49
  15. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +96 -96
  16. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +33 -33
  17. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.cpp +95 -95
  18. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h +29 -29
  19. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationType.h +9 -9
  20. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp +232 -232
  21. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h +90 -90
  22. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp +870 -870
  23. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +147 -147
  24. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp +91 -91
  25. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +176 -176
  26. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +971 -971
  27. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +252 -254
  28. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.cpp +231 -231
  29. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.h +109 -109
  30. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.cpp +56 -56
  31. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.h +20 -20
  32. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp +70 -70
  33. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h +35 -35
  34. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/CollectionUtils.h +14 -14
  35. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.cpp +5 -5
  36. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.h +19 -19
  37. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +98 -98
  38. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedSystraceSection.h +135 -135
  39. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +47 -47
  40. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +59 -59
  41. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.cpp +27 -27
  42. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.h +25 -25
  43. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +94 -94
  44. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.h +49 -49
  45. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +8 -8
  46. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +39 -39
  47. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.cpp +326 -326
  48. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.h +345 -345
  49. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.cpp +52 -52
  50. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.h +35 -35
  51. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/Defs.h +10 -10
  52. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.cpp +342 -342
  53. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.h +47 -47
  54. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.cpp +16 -16
  55. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.h +20 -20
  56. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.cpp +20 -20
  57. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.h +29 -29
  58. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/PlatformLogger.h +16 -16
  59. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.cpp +26 -26
  60. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.h +199 -199
  61. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.cpp +95 -95
  62. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.h +19 -19
  63. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/SingleInstanceChecker.h +72 -72
  64. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ThreadSafeQueue.h +49 -49
  65. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.cpp +20 -20
  66. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.h +22 -22
  67. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +29 -29
  68. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.h +41 -41
  69. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +16 -16
  70. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +19 -19
  71. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.cpp +112 -112
  72. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.h +127 -127
  73. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.cpp +53 -53
  74. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.h +22 -22
  75. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RuntimeInitialization.md +191 -191
  76. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +173 -173
  77. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +90 -90
  78. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +36 -36
  79. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +189 -189
  80. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +22 -22
  81. package/harmony/reanimated/src/main/cpp/ReanimatedModule.cpp +4 -6
  82. package/harmony/reanimated/src/main/cpp/WorkletsModule.cpp +60 -60
  83. package/harmony/reanimated/src/main/cpp/patches/AnimatedSensor/AnimatedSensorModule.cpp +89 -89
  84. package/harmony/reanimated/src/main/cpp/patches/NativeModules/ReanimatedModuleProxy.cpp +22 -4
  85. package/harmony/reanimated/src/main/ets/ReanimatedModule.ts +88 -13
  86. package/harmony/reanimated/src/main/module.json5 +12 -12
  87. package/harmony/reanimated/src/main/resources/base/element/color.json +7 -7
  88. package/harmony/reanimated/src/main/resources/base/element/string.json +15 -15
  89. package/harmony/reanimated/src/main/resources/base/profile/main_pages.json +5 -5
  90. package/harmony/reanimated/src/main/resources/en_US/element/string.json +15 -15
  91. package/harmony/reanimated/src/main/resources/zh_CN/element/string.json +15 -15
  92. package/harmony/reanimated/ts.ts +6 -6
  93. package/harmony/reanimated.har +0 -0
  94. package/package.json +51 -50
@@ -1,232 +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
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
@@ -1,90 +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
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