Skip to content

Commit

Permalink
fix rootMargin
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok committed May 5, 2024
1 parent 9fc8fa1 commit 945b18b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/view/com/util/List.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ function ListImpl<ItemT>(
))}
{onEndReached && (
<Visibility
topMargin={(onEndReachedThreshold ?? 0) * 100 + '%'}
onVisibleChange={onTailVisibilityChange}
bottomMargin={(onEndReachedThreshold ?? 0) * 100 + '%'}
/>
)}
{footer}
Expand Down Expand Up @@ -276,10 +276,12 @@ Row = React.memo(Row)

let Visibility = ({
topMargin = '0px',
bottomMargin = '0px',
onVisibleChange,
style,
}: {
topMargin?: string
bottomMargin?: string
onVisibleChange: (isVisible: boolean) => void
style?: ViewProps['style']
}): React.ReactNode => {
Expand All @@ -301,14 +303,14 @@ let Visibility = ({

React.useEffect(() => {
const observer = new IntersectionObserver(handleIntersection, {
rootMargin: `${topMargin} 0px 0px 0px`,
rootMargin: `${topMargin} 0px ${bottomMargin} 0px`,
})
const tail: Element | null = tailRef.current!
observer.observe(tail)
return () => {
observer.unobserve(tail)
}
}, [handleIntersection, topMargin])
}, [bottomMargin, handleIntersection, topMargin])

return (
<View ref={tailRef} style={addStyle(styles.visibilityDetector, style)} />
Expand Down

0 comments on commit 945b18b

Please sign in to comment.