From f6e921efbdf7597df4332c7ef8539e7966ad374d Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sat, 23 Dec 2023 02:01:55 +0000 Subject: [PATCH] Naming etc --- src/view/com/util/List.web.tsx | 40 +++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/view/com/util/List.web.tsx b/src/view/com/util/List.web.tsx index 0c5560b6ea..e5613ddd01 100644 --- a/src/view/com/util/List.web.tsx +++ b/src/view/com/util/List.web.tsx @@ -110,27 +110,29 @@ function ListImpl( useResizeObserver(containerRef, onContentSizeChange) // --- onScroll --- - const handleScroll = useNonReactiveCallback(() => { - contextScrollHandlers.onScroll?.( - { - contentOffset: { - x: window.scrollX, - y: window.scrollY, - }, - } as any, // TODO: Better types. - null as any, - ) + const [isInsideVisibleTree, setIsInsideVisibleTree] = React.useState(false) + const handleWindowScroll = useNonReactiveCallback(() => { + if (isInsideVisibleTree) { + contextScrollHandlers.onScroll?.( + { + contentOffset: { + x: window.scrollX, + y: window.scrollY, + }, + } as any, // TODO: Better types. + null as any, + ) + } }) - const [isParentTreeVisible, setIsParentTreeVisible] = React.useState(false) React.useEffect(() => { - if (!isParentTreeVisible) { + if (!isInsideVisibleTree) { // Prevents hidden tabs from firing scroll events. // Only one list is expected to be firing these at a time. return } - window.addEventListener('scroll', handleScroll) - return () => window.removeEventListener('scroll', handleScroll) - }, [isParentTreeVisible, handleScroll]) + window.addEventListener('scroll', handleWindowScroll) + return () => window.removeEventListener('scroll', handleWindowScroll) + }, [isInsideVisibleTree, handleWindowScroll]) // --- onScrolledDownChange --- const isScrolledDown = useRef(false) @@ -158,8 +160,12 @@ function ListImpl( return (