Skip to content

Commit

Permalink
Avoid starting animations for non-layout updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomiejbloniarz committed Jun 11, 2024
1 parent 2d22cb4 commit 490ce6b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ void LayoutAnimationsProxy::handleUpdatesAndEnterings(
}

case ShadowViewMutation::Type::Update: {
if (!layoutAnimationsManager_->hasLayoutAnimation(tag, LAYOUT)) {
auto shouldAnimate = hasLayoutChanged(mutation);
if (!layoutAnimationsManager_->hasLayoutAnimation(tag, LAYOUT) || (!shouldAnimate && !layoutAnimations_.contains(tag))) {
// We should cancel any ongoing animation here to ensure that the
// proper final state is reached for this view However, due to how
// RNSScreens handle adding headers (a second commit is triggered to
Expand All @@ -324,6 +325,9 @@ void LayoutAnimationsProxy::handleUpdatesAndEnterings(
// TODO: find a better solution for this problem
filteredMutations.push_back(mutation);
continue;
} else if (!shouldAnimate){
updateOngoingAnimationTarget(tag, mutation);
continue;
}
startLayoutAnimation(tag, mutation);
break;
Expand Down Expand Up @@ -644,7 +648,7 @@ void LayoutAnimationsProxy::startLayoutAnimation(
auto parentView = std::make_shared<ShadowView>(mutation.parentShadowView);
layoutAnimations_.insert_or_assign(
tag, LayoutAnimation{finalView, currentView, parentView, {}, count});

Snapshot currentValues(oldView, surfaceManager.getWindow(surfaceId));
Snapshot targetValues(
mutation.newChildShadowView, surfaceManager.getWindow(surfaceId));
Expand All @@ -671,6 +675,12 @@ void LayoutAnimationsProxy::startLayoutAnimation(
});
}

void LayoutAnimationsProxy::updateOngoingAnimationTarget(
const int tag,
const ShadowViewMutation &mutation) const {
layoutAnimations_[tag].finalView = std::make_shared<ShadowView>(mutation.newChildShadowView);
}

void LayoutAnimationsProxy::maybeCancelAnimation(const int tag) const {
if (!layoutAnimations_.contains(tag)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ struct LayoutAnimationsProxy : public MountingOverrideDelegate {
void addOngoingAnimations(
SurfaceId surfaceId,
ShadowViewMutationList &mutations) const;
void updateOngoingAnimationTarget(
const int tag,
const ShadowViewMutation& mutation) const;

void updateIndexForMutation(ShadowViewMutation &mutation) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ static inline bool isRNSScreen(std::shared_ptr<MutationNode> node) {
node->mutation.oldChildShadowView.componentName, "RNSScreen");
}

static inline bool hasLayoutChanged(const ShadowViewMutation& mutation){
return mutation.oldChildShadowView.layoutMetrics.frame != mutation.newChildShadowView.layoutMetrics.frame;
}

static inline void mergeAndSwap(std::vector<std::shared_ptr<MutationNode>>& A, std::vector<std::shared_ptr<MutationNode>>& B){
std::vector<std::shared_ptr<MutationNode>> merged;
auto it1 = A.begin(), it2 = B.begin();
Expand Down

0 comments on commit 490ce6b

Please sign in to comment.