Simplify
This commit is contained in:
@@ -1,11 +1,5 @@
|
|||||||
import React, {memo, startTransition} from 'react'
|
import React, {memo, startTransition} from 'react'
|
||||||
import {
|
import {FlatListProps, StyleSheet, View} from 'react-native'
|
||||||
FlatListProps,
|
|
||||||
RefreshControl,
|
|
||||||
ScrollView,
|
|
||||||
StyleSheet,
|
|
||||||
View,
|
|
||||||
} 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'
|
||||||
@@ -113,18 +107,15 @@ function ListImpl<ItemT>(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
function handleScroll() {
|
function handleScroll() {
|
||||||
// TODO
|
console.log(window.scrollY)
|
||||||
}
|
}
|
||||||
window.addEventListener('scroll', handleScroll)
|
window.addEventListener('scroll', handleScroll)
|
||||||
return () => window.removeEventListener('scroll', handleScroll)
|
return () => window.removeEventListener('scroll', handleScroll)
|
||||||
}, [isVisible])
|
}, [isVisible])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Visibility
|
<View style={{paddingTop: 0}}>
|
||||||
onVisibleChange={newIsVisible => {
|
<View {...props} style={style} ref={nativeRef}>
|
||||||
setIsVisible(newIsVisible)
|
|
||||||
}}>
|
|
||||||
<ScrollView {...props} style={style} ref={nativeRef}>
|
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
||||||
styles.contentContainer,
|
styles.contentContainer,
|
||||||
@@ -132,6 +123,13 @@ function ListImpl<ItemT>(
|
|||||||
desktopFixedHeight ? styles.minHeightViewport : null,
|
desktopFixedHeight ? styles.minHeightViewport : null,
|
||||||
pal.border,
|
pal.border,
|
||||||
]}>
|
]}>
|
||||||
|
<View style={styles.visibilityDetector}>
|
||||||
|
<Visibility
|
||||||
|
onVisibleChange={newIsVisible => {
|
||||||
|
setIsVisible(newIsVisible)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
{header}
|
{header}
|
||||||
{(data as Array<ItemT>).map((item, index) => (
|
{(data as Array<ItemT>).map((item, index) => (
|
||||||
<Row<ItemT>
|
<Row<ItemT>
|
||||||
@@ -156,8 +154,8 @@ function ListImpl<ItemT>(
|
|||||||
)}
|
)}
|
||||||
{footer}
|
{footer}
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</View>
|
||||||
</Visibility>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,11 +187,9 @@ Row = React.memo(Row)
|
|||||||
let Visibility = ({
|
let Visibility = ({
|
||||||
threshold = 0,
|
threshold = 0,
|
||||||
onVisibleChange,
|
onVisibleChange,
|
||||||
children,
|
|
||||||
}: {
|
}: {
|
||||||
threshold?: number | null | undefined
|
threshold?: number | null | undefined
|
||||||
onVisibleChange: (isVisible: boolean) => void
|
onVisibleChange: (isVisible: boolean) => void
|
||||||
children?: React.ReactNode
|
|
||||||
}): React.ReactNode => {
|
}): React.ReactNode => {
|
||||||
const tailRef = React.useRef(null)
|
const tailRef = React.useRef(null)
|
||||||
const isIntersecting = React.useRef(false)
|
const isIntersecting = React.useRef(false)
|
||||||
@@ -220,7 +216,7 @@ let Visibility = ({
|
|||||||
}
|
}
|
||||||
}, [handleIntersection, threshold])
|
}, [handleIntersection, threshold])
|
||||||
|
|
||||||
return <View ref={tailRef}>{children}</View>
|
return <View ref={tailRef} />
|
||||||
}
|
}
|
||||||
Visibility = React.memo(Visibility)
|
Visibility = React.memo(Visibility)
|
||||||
|
|
||||||
@@ -240,11 +236,15 @@ const styles = StyleSheet.create({
|
|||||||
marginRight: 'auto',
|
marginRight: 'auto',
|
||||||
},
|
},
|
||||||
row: {
|
row: {
|
||||||
// @ts-ignore web
|
// @ts-ignore web only
|
||||||
contentVisibility: 'auto',
|
contentVisibility: 'auto',
|
||||||
},
|
},
|
||||||
minHeightViewport: {
|
minHeightViewport: {
|
||||||
// @ts-ignore web only
|
// @ts-ignore web only
|
||||||
minHeight: '100vh',
|
minHeight: '100vh',
|
||||||
},
|
},
|
||||||
|
visibilityDetector: {
|
||||||
|
// @ts-ignore web only
|
||||||
|
position: 'fixed',
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user