Skip to content

Commit 670d769

Browse files
zeyapmeta-codesync[bot]
authored andcommitted
Inline onTransitionAnimationEnd and fix iterator invalidation in ViewTransitionModule (#56104)
Summary: Pull Request resolved: #56104 `startViewTransitionEnd` was removing entries from `nameRegistry_` while iterating over it via `onTransitionAnimationEnd`, which is undefined behavior. This diff improves the fix by: - Inlining `onTransitionAnimationEnd` (private, single call site) - Clearing `nameRegistry_` after the loop instead of erasing during iteration, removing the need for a copy ## Changelog: [Internal] [Fixed] - Inline onTransitionAnimationEnd and fix iterator invalidation in ViewTransitionModule Reviewed By: christophpurrer Differential Revision: D96085815 fbshipit-source-id: b8e425d1166421cd10b27ea5d366d9fdef58d468
1 parent 44ac8c2 commit 670d769

2 files changed

Lines changed: 6 additions & 21 deletions

File tree

packages/react-native/ReactCommon/react/renderer/viewtransition/ViewTransitionModule.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,13 @@ void ViewTransitionModule::startViewTransition(
131131
}
132132

133133
void ViewTransitionModule::startViewTransitionEnd() {
134-
for (const auto& it : nameRegistry_) {
135-
onTransitionAnimationEnd(it.second, it.first, 0);
134+
for (const auto& [tag, names] : nameRegistry_) {
135+
for (const auto& name : names) {
136+
oldLayout_.erase(name);
137+
newLayout_.erase(name);
138+
}
136139
}
140+
nameRegistry_.clear();
137141

138142
transitionStarted_ = false;
139143
}
@@ -170,21 +174,4 @@ ViewTransitionModule::getViewTransitionInstance(
170174
return std::nullopt;
171175
}
172176

173-
void ViewTransitionModule::onTransitionAnimationEnd(
174-
const std::unordered_set<std::string>& names,
175-
Tag newTag,
176-
Tag oldTag) {
177-
for (const auto& name : names) {
178-
oldLayout_.erase(name);
179-
newLayout_.erase(name);
180-
}
181-
182-
if (newTag != 0) {
183-
nameRegistry_.erase(newTag);
184-
}
185-
if (oldTag != 0) {
186-
nameRegistry_.erase(oldTag);
187-
}
188-
}
189-
190177
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/viewtransition/ViewTransitionModule.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ class ViewTransitionModule : public UIManagerViewTransitionDelegate {
6262
};
6363

6464
private:
65-
void onTransitionAnimationEnd(const std::unordered_set<std::string> &names, Tag newTag, Tag oldTag);
66-
6765
// registry of layout of old/new views
6866
std::unordered_map<std::string, AnimationKeyFrameView> oldLayout_{};
6967
std::unordered_map<std::string, AnimationKeyFrameView> newLayout_{};

0 commit comments

Comments
 (0)