Hook up context scroll handlers

This commit is contained in:
Dan Abramov
2023-12-15 06:21:55 +00:00
parent 534427d234
commit 634b76dc3d
2 changed files with 18 additions and 5 deletions
+1 -1
View File
@@ -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'
+17 -4
View File
@@ -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<ItemT>(
}: ListProps<ItemT>,
ref: React.Ref<ListMethods>,
) {
const contextScrollHandlers = useScrollHandlers()
const pal = usePalette('default')
const {isMobile} = useWebMediaQueries()
if (!isMobile) {
@@ -102,16 +104,27 @@ function ListImpl<ItemT>(
)
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) {