Skip to content

Commit

Permalink
fix list auto scroll down when mutation is triggered while hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Jul 27, 2024
1 parent 9901ca3 commit 908c335
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/components/FlatList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ function MVCPFlatList<TItem>({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(() => {
Expand Down

0 comments on commit 908c335

Please sign in to comment.