Hook up context scroll handlers
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, {memo, startTransition} from 'react'
|
import React, {memo} from 'react'
|
||||||
import {FlatListProps, RefreshControl} from 'react-native'
|
import {FlatListProps, RefreshControl} from 'react-native'
|
||||||
import {FlatList_INTERNAL} from './Views'
|
import {FlatList_INTERNAL} from './Views'
|
||||||
import {addStyle} from 'lib/styles'
|
import {addStyle} from 'lib/styles'
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {FlatListProps, StyleSheet, View, ViewProps} from 'react-native'
|
|||||||
import {addStyle} from 'lib/styles'
|
import {addStyle} from 'lib/styles'
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||||
|
import {useScrollHandlers} from '#/lib/ScrollContext'
|
||||||
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
|
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
|
||||||
import {batchedUpdates} from '#/lib/batchedUpdates'
|
import {batchedUpdates} from '#/lib/batchedUpdates'
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ function ListImpl<ItemT>(
|
|||||||
}: ListProps<ItemT>,
|
}: ListProps<ItemT>,
|
||||||
ref: React.Ref<ListMethods>,
|
ref: React.Ref<ListMethods>,
|
||||||
) {
|
) {
|
||||||
|
const contextScrollHandlers = useScrollHandlers()
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const {isMobile} = useWebMediaQueries()
|
const {isMobile} = useWebMediaQueries()
|
||||||
if (!isMobile) {
|
if (!isMobile) {
|
||||||
@@ -102,16 +104,27 @@ function ListImpl<ItemT>(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const [isVisible, setIsVisible] = React.useState(false)
|
const [isVisible, setIsVisible] = React.useState(false)
|
||||||
|
const handleScroll = useNonReactiveCallback(() => {
|
||||||
|
contextScrollHandlers.onScroll?.(
|
||||||
|
{
|
||||||
|
contentOffset: {
|
||||||
|
x: window.scrollX,
|
||||||
|
y: window.scrollY,
|
||||||
|
},
|
||||||
|
// TODO
|
||||||
|
},
|
||||||
|
{
|
||||||
|
/* TODO */
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!isVisible) {
|
if (!isVisible) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
function handleScroll() {
|
|
||||||
console.log(window.scrollY)
|
|
||||||
}
|
|
||||||
window.addEventListener('scroll', handleScroll)
|
window.addEventListener('scroll', handleScroll)
|
||||||
return () => window.removeEventListener('scroll', handleScroll)
|
return () => window.removeEventListener('scroll', handleScroll)
|
||||||
}, [isVisible])
|
}, [isVisible, handleScroll])
|
||||||
|
|
||||||
const isScrolledDown = useRef(false)
|
const isScrolledDown = useRef(false)
|
||||||
function handleAboveTheFoldVisibleChange(isAboveTheFold: boolean) {
|
function handleAboveTheFoldVisibleChange(isAboveTheFold: boolean) {
|
||||||
|
|||||||
Reference in New Issue
Block a user