don't render onEndReached or onStartReached Visibility if empty
This commit is contained in:
@@ -73,6 +73,8 @@ function ListImpl<ItemT>(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isEmpty = !data || data.length === 0
|
||||||
|
|
||||||
let headerComponent: JSX.Element | null = null
|
let headerComponent: JSX.Element | null = null
|
||||||
if (ListHeaderComponent != null) {
|
if (ListHeaderComponent != null) {
|
||||||
if (isValidElement(ListHeaderComponent)) {
|
if (isValidElement(ListHeaderComponent)) {
|
||||||
@@ -334,7 +336,7 @@ function ListImpl<ItemT>(
|
|||||||
onVisibleChange={handleAboveTheFoldVisibleChange}
|
onVisibleChange={handleAboveTheFoldVisibleChange}
|
||||||
style={[styles.aboveTheFoldDetector, {height: headerOffset}]}
|
style={[styles.aboveTheFoldDetector, {height: headerOffset}]}
|
||||||
/>
|
/>
|
||||||
{onStartReached && (
|
{onStartReached && !isEmpty && (
|
||||||
<Visibility
|
<Visibility
|
||||||
root={containWeb ? nativeRef : null}
|
root={containWeb ? nativeRef : null}
|
||||||
onVisibleChange={onHeadVisibilityChange}
|
onVisibleChange={onHeadVisibilityChange}
|
||||||
@@ -342,7 +344,7 @@ function ListImpl<ItemT>(
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{headerComponent}
|
{headerComponent}
|
||||||
{!data || data.length === 0
|
{isEmpty
|
||||||
? emptyComponent
|
? emptyComponent
|
||||||
: (data as Array<ItemT>)?.map((item, index) => {
|
: (data as Array<ItemT>)?.map((item, index) => {
|
||||||
const key = keyExtractor!(item, index)
|
const key = keyExtractor!(item, index)
|
||||||
@@ -358,7 +360,7 @@ function ListImpl<ItemT>(
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
{onEndReached && (
|
{onEndReached && !isEmpty && (
|
||||||
<Visibility
|
<Visibility
|
||||||
root={containWeb ? nativeRef : null}
|
root={containWeb ? nativeRef : null}
|
||||||
onVisibleChange={onTailVisibilityChange}
|
onVisibleChange={onTailVisibilityChange}
|
||||||
|
|||||||
Reference in New Issue
Block a user