Skip to content

Commit eb3ca72

Browse files
Bartlomiej Bloniarzfacebook-github-bot
authored andcommitted
Split families by surfaceId in Animation Backend (#54424)
Summary: AnimationBackend might be handling mulitple surfaces at once, so we need to separate the updates, by `SurfaceId` Reviewed By: zeyap Differential Revision: D84055753
1 parent 49d78d5 commit eb3ca72

2 files changed

Lines changed: 45 additions & 27 deletions

File tree

packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.cpp

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,23 @@ AnimationBackend::AnimationBackend(
9999

100100
void AnimationBackend::onAnimationFrame(double timestamp) {
101101
std::unordered_map<Tag, AnimatedProps> updates;
102-
std::unordered_set<const ShadowNodeFamily*> families;
102+
std::unordered_map<SurfaceId, std::unordered_set<const ShadowNodeFamily*>>
103+
surfaceToFamilies;
103104
bool hasAnyLayoutUpdates = false;
104105
for (auto& callback : callbacks) {
105106
auto muatations = callback(static_cast<float>(timestamp));
106107
for (auto& mutation : muatations) {
107108
hasAnyLayoutUpdates |= mutationHasLayoutUpdates(mutation);
108-
families.insert(mutation.family);
109+
const auto family = mutation.family;
110+
if (family != nullptr) {
111+
surfaceToFamilies[family->getSurfaceId()].insert(family);
112+
}
109113
updates[mutation.tag] = std::move(mutation.props);
110114
}
111115
}
112116

113117
if (hasAnyLayoutUpdates) {
114-
commitUpdatesWithFamilies(families, updates);
118+
commitUpdates(surfaceToFamilies, updates);
115119
} else {
116120
synchronouslyUpdateProps(updates);
117121
}
@@ -137,29 +141,43 @@ void AnimationBackend::stop(bool isAsync) {
137141
callbacks.clear();
138142
}
139143

140-
void AnimationBackend::commitUpdatesWithFamilies(
141-
const std::unordered_set<const ShadowNodeFamily*>& families,
144+
void AnimationBackend::commitUpdates(
145+
const std::unordered_map<
146+
SurfaceId,
147+
std::unordered_set<const ShadowNodeFamily*>>& surfaceToFamilies,
142148
std::unordered_map<Tag, AnimatedProps>& updates) {
143-
uiManager_->getShadowTreeRegistry().enumerate(
144-
[families, &updates](const ShadowTree& shadowTree, bool& /*stop*/) {
145-
shadowTree.commit(
146-
[families, &updates](const RootShadowNode& oldRootShadowNode) {
147-
return std::static_pointer_cast<RootShadowNode>(
148-
oldRootShadowNode.cloneMultiple(
149-
families,
150-
[families, &updates](
151-
const ShadowNode& shadowNode,
152-
const ShadowNodeFragment& fragment) {
153-
auto& animatedProps = updates.at(shadowNode.getTag());
154-
auto newProps = cloneProps(animatedProps, shadowNode);
155-
return shadowNode.clone(
156-
{newProps,
157-
fragment.children,
158-
shadowNode.getState()});
159-
}));
160-
},
161-
{.mountSynchronously = true});
162-
});
149+
for (const auto& surfaceEntry : surfaceToFamilies) {
150+
const auto& surfaceId = surfaceEntry.first;
151+
const auto& surfaceFamilies = surfaceEntry.second;
152+
uiManager_->getShadowTreeRegistry().visit(
153+
surfaceId, [&surfaceFamilies, &updates](const ShadowTree& shadowTree) {
154+
shadowTree.commit(
155+
[&surfaceFamilies,
156+
&updates](const RootShadowNode& oldRootShadowNode) {
157+
return std::static_pointer_cast<RootShadowNode>(
158+
oldRootShadowNode.cloneMultiple(
159+
surfaceFamilies,
160+
[&surfaceFamilies, &updates](
161+
const ShadowNode& shadowNode,
162+
const ShadowNodeFragment& fragment) {
163+
auto newProps =
164+
ShadowNodeFragment::propsPlaceholder();
165+
if (surfaceFamilies.contains(
166+
&shadowNode.getFamily())) {
167+
auto& animatedProps =
168+
updates.at(shadowNode.getTag());
169+
newProps = cloneProps(animatedProps, shadowNode);
170+
}
171+
return shadowNode.clone(
172+
{.props = newProps,
173+
.children = fragment.children,
174+
.state = shadowNode.getState(),
175+
.runtimeShadowNodeReference = false});
176+
}));
177+
},
178+
{.mountSynchronously = true});
179+
});
180+
}
163181
}
164182

165183
void AnimationBackend::synchronouslyUpdateProps(

packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class AnimationBackend : public UIManagerAnimationBackend {
5959
DirectManipulationCallback &&directManipulationCallback,
6060
FabricCommitCallback &&fabricCommitCallback,
6161
UIManager *uiManager);
62-
void commitUpdatesWithFamilies(
63-
const std::unordered_set<const ShadowNodeFamily *> &families,
62+
void commitUpdates(
63+
const std::unordered_map<SurfaceId, std::unordered_set<const ShadowNodeFamily *>> &surfaceToFamilies,
6464
std::unordered_map<Tag, AnimatedProps> &updates);
6565
void synchronouslyUpdateProps(const std::unordered_map<Tag, AnimatedProps> &updates);
6666

0 commit comments

Comments
 (0)