Cleanup 3
This commit is contained in:
@@ -72,10 +72,6 @@ export const FlatList = React.forwardRef(function FlatListImpl<ItemT>(
|
|||||||
styles.containerScroll,
|
styles.containerScroll,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
style = addStyle(style, {
|
|
||||||
// @ts-ignore web-only
|
|
||||||
contain: 'content',
|
|
||||||
})
|
|
||||||
if (contentOffset && contentOffset?.y !== 0) {
|
if (contentOffset && contentOffset?.y !== 0) {
|
||||||
// NOTE
|
// NOTE
|
||||||
// we use paddingTop & contentOffset to space around the floating header
|
// we use paddingTop & contentOffset to space around the floating header
|
||||||
@@ -132,6 +128,12 @@ export const FlatList = React.forwardRef(function FlatListImpl<ItemT>(
|
|||||||
return () => window.removeEventListener('scroll', handleScroll)
|
return () => window.removeEventListener('scroll', handleScroll)
|
||||||
}, [onScroll])
|
}, [onScroll])
|
||||||
|
|
||||||
|
const onVisible = React.useCallback(() => {
|
||||||
|
onEndReached?.({
|
||||||
|
distanceFromEnd: onEndReachedThreshold || 0,
|
||||||
|
})
|
||||||
|
}, [onEndReachedThreshold, onEndReached])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Animated.ScrollView {...props} style={style} ref={nativeRef}>
|
<Animated.ScrollView {...props} style={style} ref={nativeRef}>
|
||||||
<View
|
<View
|
||||||
@@ -142,27 +144,20 @@ export const FlatList = React.forwardRef(function FlatListImpl<ItemT>(
|
|||||||
</View>
|
</View>
|
||||||
))}
|
))}
|
||||||
{onEndReached && (
|
{onEndReached && (
|
||||||
<Tail
|
<Tail threshold={onEndReachedThreshold} onVisible={onVisible} />
|
||||||
threshold={onEndReachedThreshold}
|
|
||||||
onVisible={() => {
|
|
||||||
onEndReached({
|
|
||||||
distanceFromEnd: onEndReachedThreshold || 0,
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
</Animated.ScrollView>
|
</Animated.ScrollView>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
function Tail({
|
let Tail = ({
|
||||||
threshold = 0,
|
threshold = 0,
|
||||||
onVisible,
|
onVisible,
|
||||||
}: {
|
}: {
|
||||||
threshold?: number | null | undefined
|
threshold?: number | null | undefined
|
||||||
onVisible: () => void
|
onVisible: () => void
|
||||||
}) {
|
}): React.ReactNode => {
|
||||||
const tailRef = React.useRef(null)
|
const tailRef = React.useRef(null)
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
@@ -185,8 +180,9 @@ function Tail({
|
|||||||
}
|
}
|
||||||
}, [onVisible, threshold])
|
}, [onVisible, threshold])
|
||||||
|
|
||||||
return <div ref={tailRef} />
|
return <View ref={tailRef} />
|
||||||
}
|
}
|
||||||
|
Tail = React.memo(Tail)
|
||||||
|
|
||||||
export const ScrollView = React.forwardRef(function ScrollViewImpl(
|
export const ScrollView = React.forwardRef(function ScrollViewImpl(
|
||||||
{contentContainerStyle, ...props}: React.PropsWithChildren<ScrollViewProps>,
|
{contentContainerStyle, ...props}: React.PropsWithChildren<ScrollViewProps>,
|
||||||
@@ -219,7 +215,6 @@ const styles = StyleSheet.create({
|
|||||||
contentContainer: {
|
contentContainer: {
|
||||||
borderLeftWidth: 1,
|
borderLeftWidth: 1,
|
||||||
borderRightWidth: 1,
|
borderRightWidth: 1,
|
||||||
// @ts-ignore web only
|
|
||||||
},
|
},
|
||||||
container: {
|
container: {
|
||||||
width: '100%',
|
width: '100%',
|
||||||
@@ -233,8 +228,4 @@ const styles = StyleSheet.create({
|
|||||||
marginLeft: 'auto',
|
marginLeft: 'auto',
|
||||||
marginRight: 'auto',
|
marginRight: 'auto',
|
||||||
},
|
},
|
||||||
fixedHeight: {
|
|
||||||
// @ts-ignore web only
|
|
||||||
height: '100vh',
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user