Skip to content

Commit d736164

Browse files
committed
override with reset styles
1 parent 35434c3 commit d736164

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/react-native-reanimated/Common/cpp/reanimated/CSS/registries/CSSAnimationsRegistry.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ void CSSAnimationsRegistry::updateViewAnimations(
175175
folly::dynamic result = folly::dynamic::object;
176176
std::shared_ptr<AnimatedPropsBuilder> propsBuilder = std::make_shared<AnimatedPropsBuilder>();
177177
std::shared_ptr<const ShadowNode> shadowNode = nullptr;
178+
// We collect reset updates to avoid merging AnimatedProps for now.
179+
std::vector<std::shared_ptr<AnimatedPropsBuilder>> resetPropsUpdates;
180+
178181
bool hasUpdates = false;
179182

180183
for (const auto animationIndex : animationIndices) {
@@ -196,7 +199,13 @@ void CSSAnimationsRegistry::updateViewAnimations(
196199
if (addToBatch && !animation->hasForwardsFillMode()) {
197200
// We also have to manually commit style values
198201
// reverting the changes applied by the animation.
199-
hasUpdates = addStyleUpdates(result, animation->getResetStyle(), false) || hasUpdates;
202+
auto resetStyle = animation->getResetStyle();
203+
hasUpdates = addStyleUpdates(result, resetStyle, false) || hasUpdates;
204+
if (hasUpdates) {
205+
std::shared_ptr<AnimatedPropsBuilder> resetPropsBuilder = std::make_shared<AnimatedPropsBuilder>();
206+
resetPropsBuilder->storeDynamic(resetStyle);
207+
resetPropsUpdates.push_back(resetPropsBuilder);
208+
}
200209
updatesAddedToBatch = true;
201210
// We want to remove style changes applied by the animation that is
202211
// finished and has no forwards fill mode. We cannot simply remove
@@ -219,6 +228,10 @@ void CSSAnimationsRegistry::updateViewAnimations(
219228
if (hasUpdates) {
220229
if constexpr (StaticFeatureFlags::getFlag("USE_ANIMATION_BACKEND")) {
221230
addAnimatedPropsToBatch(shadowNode, propsBuilder->get());
231+
// overrides previous styles if not empty
232+
for (auto &delayedPropsBuilder : resetPropsUpdates) {
233+
addAnimatedPropsToBatch(shadowNode, delayedPropsBuilder->get());
234+
}
222235
}
223236
addUpdatesToBatch(shadowNode, result);
224237
}

0 commit comments

Comments
 (0)