Skip to content

Commit 9126da4

Browse files
zeyapmeta-codesync[bot]
authored andcommitted
Flush unbatched createAnimatedNode under the shared AnimationBackend (#57180)
Summary: Pull Request resolved: #57180 ## Changelog: [Internal] Reviewed By: javache Differential Revision: D108062822 fbshipit-source-id: 5e49107d34db31fc5e21e913cf74ec0e2ed366aa
1 parent 0e86a04 commit 9126da4

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,9 @@ AnimationMutations NativeAnimatedNodesManager::pullAnimationMutations(
10391039

10401040
isOnRenderThread_ = true;
10411041

1042+
// Apply nodes created via the unbatched `createAnimatedNodeAsync` path.
1043+
flushAnimatedNodesCreatedAsync();
1044+
10421045
// Run operations scheduled from AnimatedModule
10431046
std::vector<UiTask> operations;
10441047
{
@@ -1097,6 +1100,24 @@ AnimationMutations NativeAnimatedNodesManager::pullAnimationMutations(
10971100
return mutations;
10981101
}
10991102

1103+
void NativeAnimatedNodesManager::flushAnimatedNodesCreatedAsync() noexcept {
1104+
// Flush async created animated nodes
1105+
std::unordered_map<Tag, std::unique_ptr<AnimatedNode>>
1106+
animatedNodesCreatedAsync;
1107+
{
1108+
std::lock_guard<std::mutex> lock(animatedNodesCreatedAsyncMutex_);
1109+
std::swap(animatedNodesCreatedAsync, animatedNodesCreatedAsync_);
1110+
}
1111+
1112+
if (!animatedNodesCreatedAsync.empty()) {
1113+
std::lock_guard<std::mutex> lock(connectedAnimatedNodesMutex_);
1114+
for (auto& [tag, node] : animatedNodesCreatedAsync) {
1115+
animatedNodes_.insert({tag, std::move(node)});
1116+
updatedNodeTags_.insert(tag);
1117+
}
1118+
}
1119+
}
1120+
11001121
void NativeAnimatedNodesManager::onRender() {
11011122
if (ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
11021123
return;
@@ -1112,23 +1133,7 @@ void NativeAnimatedNodesManager::onRender() {
11121133

11131134
isOnRenderThread_ = true;
11141135

1115-
{
1116-
// Flush async created animated nodes
1117-
std::unordered_map<Tag, std::unique_ptr<AnimatedNode>>
1118-
animatedNodesCreatedAsync;
1119-
{
1120-
std::lock_guard<std::mutex> lock(animatedNodesCreatedAsyncMutex_);
1121-
std::swap(animatedNodesCreatedAsync, animatedNodesCreatedAsync_);
1122-
}
1123-
1124-
if (!animatedNodesCreatedAsync.empty()) {
1125-
std::lock_guard<std::mutex> lock(connectedAnimatedNodesMutex_);
1126-
for (auto& [tag, node] : animatedNodesCreatedAsync) {
1127-
animatedNodes_.insert({tag, std::move(node)});
1128-
updatedNodeTags_.insert(tag);
1129-
}
1130-
}
1131-
}
1136+
flushAnimatedNodesCreatedAsync();
11321137

11331138
// Run operations scheduled from AnimatedModule
11341139
std::vector<UiTask> operations;

packages/react-native/ReactCommon/react/renderer/animated/NativeAnimatedNodesManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ class NativeAnimatedNodesManager : public std::enable_shared_from_this<NativeAni
207207

208208
bool onAnimationFrame(double timestamp);
209209

210+
void flushAnimatedNodesCreatedAsync() noexcept;
211+
210212
bool isAnimationUpdateNeeded() const noexcept;
211213

212214
void stopAnimationsForNode(Tag nodeTag);

0 commit comments

Comments
 (0)