Skip to content

Commit dc133ec

Browse files
committed
fix(mobile): preserve entering frames across retargets
1 parent 7ca989d commit dc133ec

2 files changed

Lines changed: 43 additions & 11 deletions

File tree

‎patches/[email protected]‎

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ diff --git a/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp b/
22
index c0825bb47a6fac02331138b5e0a0e5bbb52df0fa..1658cd1286d1087dec1dff84234f6251f791d63a 100644
33
--- a/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp
44
+++ b/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp
5-
@@ -823,35 +823,40 @@ void LayoutAnimationsProxy::addOngoingAnimations(ShadowViewMutationList &mutatio
5+
@@ -823,35 +823,41 @@ void LayoutAnimationsProxy::addOngoingAnimations(ShadowViewMutationList &mutatio
66

77
maybeCorrectedTags = preserveMountedTags_(tagsToUpdate);
88
if (!maybeCorrectedTags.has_value()) {
@@ -48,14 +48,15 @@ index c0825bb47a6fac02331138b5e0a0e5bbb52df0fa..1658cd1286d1087dec1dff84234f6251
4848
+ // A reduced-motion animation may have only one frame, before its view mounts.
4949
+ // Keep it until a UI-thread pull can apply it; cancellation and teardown erase it.
5050
+ // https://github.com/software-mansion/react-native-reanimated/issues/7493
51+
+ schedulePullOnNextFrame();
5152
+ ++it;
5253
continue;
5354
}
5455
+#endif
5556

5657
auto &layoutAnimation = layoutAnimationIt != layoutAnimations_.end() ? layoutAnimationIt->second
5758
: completedAnimationIt->second.animation;
58-
@@ -867,8 +872,8 @@ void LayoutAnimationsProxy::addOngoingAnimations(ShadowViewMutationList &mutatio
59+
@@ -867,8 +873,8 @@ void LayoutAnimationsProxy::addOngoingAnimations(ShadowViewMutationList &mutatio
5960
if (layoutAnimation.opacity && getViewProps(newView).opacity == *layoutAnimation.opacity) {
6061
layoutAnimation.opacity.reset();
6162
}
@@ -65,7 +66,7 @@ index c0825bb47a6fac02331138b5e0a0e5bbb52df0fa..1658cd1286d1087dec1dff84234f6251
6566
}
6667

6768
void LayoutAnimationsProxy::endAnimationsRecursively(
68-
@@ -1056,10 +1061,14 @@ void LayoutAnimationsProxy::cleanupAnimations(
69+
@@ -1056,10 +1062,14 @@ void LayoutAnimationsProxy::cleanupAnimations(
6970
const PropsParserContext &propsParserContext,
7071
const bool flushStructuralMutations) const {
7172
ReanimatedSystraceSection s("cleanupAnimations");
@@ -82,7 +83,7 @@ index c0825bb47a6fac02331138b5e0a0e5bbb52df0fa..1658cd1286d1087dec1dff84234f6251
8283
continue;
8384
}
8485
const auto containerIt = sharedContainers_.find(tag);
85-
@@ -1067,7 +1076,7 @@ void LayoutAnimationsProxy::cleanupAnimations(
86+
@@ -1067,7 +1077,7 @@ void LayoutAnimationsProxy::cleanupAnimations(
8687
continue;
8788
}
8889
if (!flushStructuralMutations) {
@@ -91,7 +92,7 @@ index c0825bb47a6fac02331138b5e0a0e5bbb52df0fa..1658cd1286d1087dec1dff84234f6251
9192
continue;
9293
}
9394
if (containerIt->second.restoreAfterNode) {
94-
@@ -1078,14 +1087,15 @@ void LayoutAnimationsProxy::cleanupAnimations(
95+
@@ -1078,14 +1088,15 @@ void LayoutAnimationsProxy::cleanupAnimations(
9596

9697
cleanupSharedTransitions(transaction, propsParserContext);
9798
}
@@ -109,6 +110,37 @@ index c0825bb47a6fac02331138b5e0a0e5bbb52df0fa..1658cd1286d1087dec1dff84234f6251
109110
});
110111
}
111112

113+
diff --git a/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.cpp b/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.cpp
114+
--- a/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.cpp
115+
+++ b/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.cpp
116+
@@ -265,7 +265,8 @@ ShadowView LayoutAnimationsProxyCommon::materializeLayoutAnimation(
117+
auto currentView = before;
118+
const auto activeAnimationIt = layoutAnimations_.find(tag);
119+
if (type == LayoutAnimationType::ENTERING) {
120+
- currentView = after;
121+
+ // A pending retarget has not changed the frame submitted for native mounting.
122+
+ currentView = before;
123+
} else if (activeAnimationIt != layoutAnimations_.end()) {
124+
currentView = activeAnimationIt->second.currentView;
125+
} else if (const auto completedAnimationIt = completedAnimations_.find(tag);
126+
@@ -546,5 +547,16 @@ bool LayoutAnimationsProxyCommon::updateEnteringAnimationTarget(const Tag tag, const ShadowView &finalView) const {
127+
}
128+
return true;
129+
}
130+
+ if (const auto completedAnimationIt = completedAnimations_.find(tag);
131+
+ completedAnimationIt != completedAnimations_.end() && !completedAnimationIt->second.shouldRemove &&
132+
+ completedAnimationIt->second.animation.type == LayoutAnimationType::ENTERING && updateMap_.contains(tag)) {
133+
+ // Retargeting must preserve the queued final frame until it reaches the native view.
134+
+ auto &animation = completedAnimationIt->second.animation;
135+
+ animation.finalView = finalView;
136+
+ if (animation.opacity) {
137+
+ animation.opacity = getViewProps(finalView).opacity;
138+
+ }
139+
+ return true;
140+
+ }
141+
return false;
142+
}
143+
112144
diff --git a/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h b/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h
113145
index 675b1b7d890971d0c43522f59106f1cf20b0fe1a..dea79ba4806e8f1ac31a11c7fa045298b54d6305 100644
114146
--- a/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h

‎pnpm-lock.yaml‎

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)