Skip to content

Commit 5e30ceb

Browse files
improve comments
1 parent efdecbc commit 5e30ceb

2 files changed

Lines changed: 13 additions & 15 deletions

File tree

packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,17 @@ void UIManager::mountPortalChildren(
191191
Tag targetTag,
192192
const ShadowNode::UnsharedListOfShared& portalChildren) {
193193
if (portalChildren->empty()) {
194-
auto it = activePortals_.find(targetTag);
195-
if (it != activePortals_.end()) {
194+
auto it = portalChildren_.find(targetTag);
195+
if (it != portalChildren_.end()) {
196196
std::unordered_set<Tag> tags;
197197
for (const auto& child : *(it->second)) {
198198
tags.insert(child->getTag());
199199
}
200200
pendingPortalRemovals_[targetTag] = std::move(tags);
201-
activePortals_.erase(it);
201+
portalChildren_.erase(it);
202202
}
203203
} else {
204-
activePortals_[targetTag] = portalChildren;
204+
portalChildren_[targetTag] = portalChildren;
205205
pendingPortalRemovals_.erase(targetTag);
206206
}
207207
}
@@ -222,8 +222,8 @@ void UIManager::completeSurface(
222222
.children = rootChildren,
223223
});
224224

225-
// Apply any active portal children
226-
for (const auto& [targetTag, portalChildren] : activePortals_) {
225+
// Append portal children to the target node
226+
for (const auto& [targetTag, portalChildren] : portalChildren_) {
227227
auto targetNode = findShadowNodeByTagRecursively(
228228
std::static_pointer_cast<const ShadowNode>(newRoot),
229229
targetTag);
@@ -239,8 +239,6 @@ void UIManager::completeSurface(
239239
portalTags.insert(child->getTag());
240240
}
241241

242-
// Copy existing children, excluding any portal children
243-
// that are already present (from a previous commit)
244242
auto mergedChildren = std::make_shared<std::vector<std::shared_ptr<const ShadowNode>>>();
245243
mergedChildren->reserve(existingChildren.size() + portalChildren->size());
246244
for (const auto& child : existingChildren) {
@@ -262,6 +260,7 @@ void UIManager::completeSurface(
262260
}
263261
}
264262

263+
// Remove unmounted portal children
265264
for (const auto& [targetTag, tagsToRemove] : pendingPortalRemovals_) {
266265
auto targetNode = findShadowNodeByTagRecursively(
267266
std::static_pointer_cast<const ShadowNode>(newRoot),
@@ -272,19 +271,16 @@ void UIManager::completeSurface(
272271
targetNode->getFamily(),
273272
[&](const ShadowNode& oldNode) {
274273
auto existingChildren = oldNode.getChildren();
275-
auto newChildren = std::make_shared<
276-
std::vector<std::shared_ptr<const ShadowNode>>>();
274+
auto newChildren = std::make_shared<std::vector<std::shared_ptr<const ShadowNode>>>();
277275
for (const auto& child : existingChildren) {
278-
if (tagsToRemove.find(child->getTag()) ==
279-
tagsToRemove.end()) {
276+
if (tagsToRemove.find(child->getTag()) == tagsToRemove.end()) {
280277
newChildren->push_back(child);
281278
}
282279
}
283280
return oldNode.clone({.children = newChildren});
284281
});
285282
if (clonedRoot) {
286-
newRoot =
287-
std::static_pointer_cast<RootShadowNode>(clonedRoot);
283+
newRoot = std::static_pointer_cast<RootShadowNode>(clonedRoot);
288284
}
289285
}
290286
}

packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,10 @@ class UIManager final : public ShadowTreeDelegate {
254254

255255
std::shared_ptr<UIManagerAnimationBackend> animationBackend_;
256256

257-
std::unordered_map<Tag, ShadowNode::UnsharedListOfShared> activePortals_;
257+
// Portal children that are active and need to be committed
258+
std::unordered_map<Tag, ShadowNode::UnsharedListOfShared> portalChildren_;
258259

260+
// Portal children that are pending removal and need to be removed on the next commit
259261
std::unordered_map<Tag, std::unordered_set<Tag>> pendingPortalRemovals_;
260262
};
261263

0 commit comments

Comments
 (0)