From 634b76dc3d117afc35a1fd8800f331d5d10490a2 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 15 Dec 2023 06:21:55 +0000 Subject: [PATCH] Hook up context scroll handlers --- src/view/com/util/List.tsx | 2 +- src/view/com/util/List.web.tsx | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/view/com/util/List.tsx b/src/view/com/util/List.tsx index 0ba499f09f..3929537096 100644 --- a/src/view/com/util/List.tsx +++ b/src/view/com/util/List.tsx @@ -1,4 +1,4 @@ -import React, {memo, startTransition} from 'react' +import React, {memo} from 'react' import {FlatListProps, RefreshControl} from 'react-native' import {FlatList_INTERNAL} from './Views' import {addStyle} from 'lib/styles' diff --git a/src/view/com/util/List.web.tsx b/src/view/com/util/List.web.tsx index 0dc418110c..595a6feee4 100644 --- a/src/view/com/util/List.web.tsx +++ b/src/view/com/util/List.web.tsx @@ -3,6 +3,7 @@ import {FlatListProps, StyleSheet, View, ViewProps} from 'react-native' import {addStyle} from 'lib/styles' import {usePalette} from 'lib/hooks/usePalette' import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' +import {useScrollHandlers} from '#/lib/ScrollContext' import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback' import {batchedUpdates} from '#/lib/batchedUpdates' @@ -41,6 +42,7 @@ function ListImpl( }: ListProps, ref: React.Ref, ) { + const contextScrollHandlers = useScrollHandlers() const pal = usePalette('default') const {isMobile} = useWebMediaQueries() if (!isMobile) { @@ -102,16 +104,27 @@ function ListImpl( ) const [isVisible, setIsVisible] = React.useState(false) + const handleScroll = useNonReactiveCallback(() => { + contextScrollHandlers.onScroll?.( + { + contentOffset: { + x: window.scrollX, + y: window.scrollY, + }, + // TODO + }, + { + /* TODO */ + }, + ) + }) React.useEffect(() => { if (!isVisible) { return } - function handleScroll() { - console.log(window.scrollY) - } window.addEventListener('scroll', handleScroll) return () => window.removeEventListener('scroll', handleScroll) - }, [isVisible]) + }, [isVisible, handleScroll]) const isScrolledDown = useRef(false) function handleAboveTheFoldVisibleChange(isAboveTheFold: boolean) {