Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,9 @@ AnimationMutations NativeAnimatedNodesManager::pullAnimationMutations(

isOnRenderThread_ = true;

// Apply nodes created via the unbatched `createAnimatedNodeAsync` path.
flushAnimatedNodesCreatedAsync();

// Run operations scheduled from AnimatedModule
std::vector<UiTask> operations;
{
Expand Down Expand Up @@ -1097,6 +1100,24 @@ AnimationMutations NativeAnimatedNodesManager::pullAnimationMutations(
return mutations;
}

void NativeAnimatedNodesManager::flushAnimatedNodesCreatedAsync() noexcept {
// Flush async created animated nodes
std::unordered_map<Tag, std::unique_ptr<AnimatedNode>>
animatedNodesCreatedAsync;
{
std::lock_guard<std::mutex> lock(animatedNodesCreatedAsyncMutex_);
std::swap(animatedNodesCreatedAsync, animatedNodesCreatedAsync_);
}

if (!animatedNodesCreatedAsync.empty()) {
std::lock_guard<std::mutex> lock(connectedAnimatedNodesMutex_);
for (auto& [tag, node] : animatedNodesCreatedAsync) {
animatedNodes_.insert({tag, std::move(node)});
updatedNodeTags_.insert(tag);
}
}
}

void NativeAnimatedNodesManager::onRender() {
if (ReactNativeFeatureFlags::useSharedAnimatedBackend()) {
return;
Expand All @@ -1112,23 +1133,7 @@ void NativeAnimatedNodesManager::onRender() {

isOnRenderThread_ = true;

{
// Flush async created animated nodes
std::unordered_map<Tag, std::unique_ptr<AnimatedNode>>
animatedNodesCreatedAsync;
{
std::lock_guard<std::mutex> lock(animatedNodesCreatedAsyncMutex_);
std::swap(animatedNodesCreatedAsync, animatedNodesCreatedAsync_);
}

if (!animatedNodesCreatedAsync.empty()) {
std::lock_guard<std::mutex> lock(connectedAnimatedNodesMutex_);
for (auto& [tag, node] : animatedNodesCreatedAsync) {
animatedNodes_.insert({tag, std::move(node)});
updatedNodeTags_.insert(tag);
}
}
}
flushAnimatedNodesCreatedAsync();

// Run operations scheduled from AnimatedModule
std::vector<UiTask> operations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ class NativeAnimatedNodesManager : public std::enable_shared_from_this<NativeAni

bool onAnimationFrame(double timestamp);

void flushAnimatedNodesCreatedAsync() noexcept;

bool isAnimationUpdateNeeded() const noexcept;

void stopAnimationsForNode(Tag nodeTag);
Expand Down
Loading