[Web] Retrigger onEndReached if needed when content height changes (#4859)
* Extract EdgeVisibility * Key Visibility by container height instead of item countzio/stable
parent
c75bb65bef
commit
576cef88b5
|
@ -344,10 +344,11 @@ function ListImpl<ItemT>(
|
|||
style={[styles.aboveTheFoldDetector, {height: headerOffset}]}
|
||||
/>
|
||||
{onStartReached && !isEmpty && (
|
||||
<Visibility
|
||||
<EdgeVisibility
|
||||
root={disableFullWindowScroll ? nativeRef : null}
|
||||
onVisibleChange={onHeadVisibilityChange}
|
||||
topMargin={(onStartReachedThreshold ?? 0) * 100 + '%'}
|
||||
containerRef={containerRef}
|
||||
/>
|
||||
)}
|
||||
{headerComponent}
|
||||
|
@ -368,11 +369,11 @@ function ListImpl<ItemT>(
|
|||
)
|
||||
})}
|
||||
{onEndReached && !isEmpty && (
|
||||
<Visibility
|
||||
<EdgeVisibility
|
||||
root={disableFullWindowScroll ? nativeRef : null}
|
||||
onVisibleChange={onTailVisibilityChange}
|
||||
bottomMargin={(onEndReachedThreshold ?? 0) * 100 + '%'}
|
||||
key={data?.length}
|
||||
containerRef={containerRef}
|
||||
/>
|
||||
)}
|
||||
{footerComponent}
|
||||
|
@ -381,6 +382,34 @@ function ListImpl<ItemT>(
|
|||
)
|
||||
}
|
||||
|
||||
function EdgeVisibility({
|
||||
root,
|
||||
topMargin,
|
||||
bottomMargin,
|
||||
containerRef,
|
||||
onVisibleChange,
|
||||
}: {
|
||||
root?: React.RefObject<HTMLDivElement> | null
|
||||
topMargin?: string
|
||||
bottomMargin?: string
|
||||
containerRef: React.RefObject<Element>
|
||||
onVisibleChange: (isVisible: boolean) => void
|
||||
}) {
|
||||
const [containerHeight, setContainerHeight] = React.useState(0)
|
||||
useResizeObserver(containerRef, (w, h) => {
|
||||
setContainerHeight(h)
|
||||
})
|
||||
return (
|
||||
<Visibility
|
||||
key={containerHeight}
|
||||
root={root}
|
||||
topMargin={topMargin}
|
||||
bottomMargin={bottomMargin}
|
||||
onVisibleChange={onVisibleChange}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function useResizeObserver(
|
||||
ref: React.RefObject<Element>,
|
||||
onResize: undefined | ((w: number, h: number) => void),
|
||||
|
|
Loading…
Reference in New Issue