From 908c33514021468e2f85bcde9735596811ee621a Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 27 Jul 2024 09:51:34 +0800 Subject: [PATCH] fix list auto scroll down when mutation is triggered while hidden --- src/components/FlatList/index.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/FlatList/index.tsx b/src/components/FlatList/index.tsx index b45a8418d9a3..75b5c54cb5d7 100644 --- a/src/components/FlatList/index.tsx +++ b/src/components/FlatList/index.tsx @@ -121,6 +121,12 @@ function MVCPFlatList({maintainVisibleContentPosition, horizontal = false mutationObserverRef.current?.disconnect(); const mutationObserver = new MutationObserver(() => { + // When the list is hidden, the size will be 0. + // Ignore the callback if the list is hidden because scrollOffset will always be 0. + if (!getScrollableNode(scrollRef.current)?.clientHeight) { + return; + } + // This needs to execute after scroll events are dispatched, but // in the same tick to avoid flickering. rAF provides the right timing. requestAnimationFrame(() => {