diff --git a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp index f9c665f5d8..ab7d5de573 100644 --- a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp +++ b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp @@ -177,33 +177,7 @@ LayoutAnimationKeyFrameManager::pullTransaction( uint64_t now = now_(); bool inflightAnimationsExistInitially = !inflightAnimations_.empty(); - - // Execute stopSurface on any ongoing animations - if (inflightAnimationsExistInitially) { - better::set surfaceIdsToStop{}; - { - std::lock_guard lock(surfaceIdsToStopMutex_); - surfaceIdsToStop = surfaceIdsToStop_; - surfaceIdsToStop_.clear(); - } - - for (auto it = inflightAnimations_.begin(); - it != inflightAnimations_.end();) { - const auto &animation = *it; - -#ifdef LAYOUT_ANIMATION_VERBOSE_LOGGING - LOG(ERROR) - << "LayoutAnimations: stopping animation due to stopSurface on " - << surfaceId; -#endif - if (surfaceIdsToStop.find(animation.surfaceId) != - surfaceIdsToStop.end()) { - it = inflightAnimations_.erase(it); - } else { - it++; - } - } - } + deleteAnimationsForStoppedSurfaces(); if (!mutations.empty()) { #ifdef RN_SHADOW_TREE_INTROSPECTION @@ -1693,5 +1667,37 @@ void LayoutAnimationKeyFrameManager::getAndEraseConflictingAnimations( } } +void LayoutAnimationKeyFrameManager::deleteAnimationsForStoppedSurfaces() + const { + bool inflightAnimationsExistInitially = !inflightAnimations_.empty(); + + // Execute stopSurface on any ongoing animations + if (inflightAnimationsExistInitially) { + better::set surfaceIdsToStop{}; + { + std::lock_guard lock(surfaceIdsToStopMutex_); + surfaceIdsToStop = surfaceIdsToStop_; + surfaceIdsToStop_.clear(); + } + + for (auto it = inflightAnimations_.begin(); + it != inflightAnimations_.end();) { + const auto &animation = *it; + +#ifdef LAYOUT_ANIMATION_VERBOSE_LOGGING + LOG(ERROR) + << "LayoutAnimations: stopping animation due to stopSurface on " + << surfaceId; +#endif + if (surfaceIdsToStop.find(animation.surfaceId) != + surfaceIdsToStop.end()) { + it = inflightAnimations_.erase(it); + } else { + it++; + } + } + } +} + } // namespace react } // namespace facebook diff --git a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h index fc9a16ab13..80b225a750 100644 --- a/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h +++ b/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h @@ -166,6 +166,11 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate, SurfaceId surfaceId, ShadowViewMutationList const &mutations, std::vector &conflictingAnimations) const; + + /* + * Removes animations from `inflightAnimations_` for stopped surfaces. + */ + void deleteAnimationsForStoppedSurfaces() const; }; static inline bool shouldFirstComeBeforeSecondRemovesOnly(