Naming etc

This commit is contained in:
Dan Abramov
2023-12-23 02:01:55 +00:00
parent b7b46ea6fb
commit f6e921efbd
+14 -8
View File
@@ -110,7 +110,9 @@ function ListImpl<ItemT>(
useResizeObserver(containerRef, onContentSizeChange) useResizeObserver(containerRef, onContentSizeChange)
// --- onScroll --- // --- onScroll ---
const handleScroll = useNonReactiveCallback(() => { const [isInsideVisibleTree, setIsInsideVisibleTree] = React.useState(false)
const handleWindowScroll = useNonReactiveCallback(() => {
if (isInsideVisibleTree) {
contextScrollHandlers.onScroll?.( contextScrollHandlers.onScroll?.(
{ {
contentOffset: { contentOffset: {
@@ -120,17 +122,17 @@ function ListImpl<ItemT>(
} as any, // TODO: Better types. } as any, // TODO: Better types.
null as any, null as any,
) )
}
}) })
const [isParentTreeVisible, setIsParentTreeVisible] = React.useState(false)
React.useEffect(() => { React.useEffect(() => {
if (!isParentTreeVisible) { if (!isInsideVisibleTree) {
// Prevents hidden tabs from firing scroll events. // Prevents hidden tabs from firing scroll events.
// Only one list is expected to be firing these at a time. // Only one list is expected to be firing these at a time.
return return
} }
window.addEventListener('scroll', handleScroll) window.addEventListener('scroll', handleWindowScroll)
return () => window.removeEventListener('scroll', handleScroll) return () => window.removeEventListener('scroll', handleWindowScroll)
}, [isParentTreeVisible, handleScroll]) }, [isInsideVisibleTree, handleWindowScroll])
// --- onScrolledDownChange --- // --- onScrolledDownChange ---
const isScrolledDown = useRef(false) const isScrolledDown = useRef(false)
@@ -158,8 +160,12 @@ function ListImpl<ItemT>(
return ( return (
<View {...props} style={style} ref={nativeRef}> <View {...props} style={style} ref={nativeRef}>
<Visibility <Visibility
onVisibleChange={setIsParentTreeVisible} onVisibleChange={setIsInsideVisibleTree}
style={styles.parentTreeVisibilityDetector} style={
// This has position: fixed, so it should always report as visible
// unless we're within a display: none tree (like a hidden tab).
styles.parentTreeVisibilityDetector
}
/> />
<View <View
ref={containerRef} ref={containerRef}