support multiple configs
This commit is contained in:
+31
-22
@@ -1,5 +1,10 @@
|
|||||||
import React, {memo} from 'react'
|
import React, {memo} from 'react'
|
||||||
import {FlatListProps, RefreshControl, ViewToken} from 'react-native'
|
import {
|
||||||
|
FlatListProps,
|
||||||
|
RefreshControl,
|
||||||
|
ViewabilityConfigCallbackPairs,
|
||||||
|
ViewToken,
|
||||||
|
} from 'react-native'
|
||||||
import {runOnJS, useSharedValue} from 'react-native-reanimated'
|
import {runOnJS, useSharedValue} from 'react-native-reanimated'
|
||||||
|
|
||||||
import {useAnimatedScrollHandler} from '#/lib/hooks/useAnimatedScrollHandler_FIXED'
|
import {useAnimatedScrollHandler} from '#/lib/hooks/useAnimatedScrollHandler_FIXED'
|
||||||
@@ -87,25 +92,30 @@ function ListImpl<ItemT>(
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const [onViewableItemsChanged, viewabilityConfig] = React.useMemo(() => {
|
const viewabilityConfigCallbackPairs: ViewabilityConfigCallbackPairs =
|
||||||
if (!onItemSeen) {
|
React.useMemo(() => {
|
||||||
return [undefined, undefined]
|
const pairs: ViewabilityConfigCallbackPairs = []
|
||||||
}
|
if (onItemSeen) {
|
||||||
return [
|
pairs.push({
|
||||||
(info: {viewableItems: Array<ViewToken>; changed: Array<ViewToken>}) => {
|
onViewableItemsChanged: (info: {
|
||||||
console.log(info.viewableItems[0])
|
viewableItems: Array<ViewToken>
|
||||||
for (const item of info.changed) {
|
changed: Array<ViewToken>
|
||||||
if (item.isViewable) {
|
}) => {
|
||||||
onItemSeen(item.item)
|
for (const item of info.changed) {
|
||||||
}
|
if (item.isViewable) {
|
||||||
}
|
onItemSeen(item.item)
|
||||||
},
|
}
|
||||||
{
|
}
|
||||||
itemVisiblePercentThreshold: 40,
|
},
|
||||||
minimumViewTime: 0,
|
viewabilityConfig: {
|
||||||
},
|
itemVisiblePercentThreshold: 40,
|
||||||
]
|
minimumViewTime: 1.5e3,
|
||||||
}, [onItemSeen])
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return pairs
|
||||||
|
}, [onItemSeen])
|
||||||
|
|
||||||
let refreshControl
|
let refreshControl
|
||||||
if (refreshing !== undefined || onRefresh !== undefined) {
|
if (refreshing !== undefined || onRefresh !== undefined) {
|
||||||
@@ -136,8 +146,7 @@ function ListImpl<ItemT>(
|
|||||||
refreshControl={refreshControl}
|
refreshControl={refreshControl}
|
||||||
onScroll={scrollHandler}
|
onScroll={scrollHandler}
|
||||||
scrollEventThrottle={1}
|
scrollEventThrottle={1}
|
||||||
onViewableItemsChanged={onViewableItemsChanged}
|
viewabilityConfigCallbackPairs={viewabilityConfigCallbackPairs}
|
||||||
viewabilityConfig={viewabilityConfig}
|
|
||||||
style={style}
|
style={style}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user