add support for ListEmptyComponent, allow undefined data

This commit is contained in:
Hailey
2024-06-06 15:59:38 -07:00
parent bd1e6fced9
commit 5b976972f5
+14 -1
View File
@@ -38,6 +38,7 @@ function ListImpl<ItemT>(
{ {
ListHeaderComponent, ListHeaderComponent,
ListFooterComponent, ListFooterComponent,
ListEmptyComponent,
containWeb, containWeb,
contentContainerStyle, contentContainerStyle,
data, data,
@@ -92,6 +93,16 @@ function ListImpl<ItemT>(
} }
} }
let emptyComponent: JSX.Element | null = null
if (ListEmptyComponent != null) {
if (isValidElement(ListEmptyComponent)) {
emptyComponent = ListEmptyComponent
} else {
// @ts-ignore Nah it's fine.
emptyComponent = <ListEmptyComponent />
}
}
if (headerOffset != null) { if (headerOffset != null) {
style = addStyle(style, { style = addStyle(style, {
paddingTop: headerOffset, paddingTop: headerOffset,
@@ -331,7 +342,9 @@ function ListImpl<ItemT>(
/> />
)} )}
{header} {header}
{(data as Array<ItemT>).map((item, index) => { {!data || data.length === 0
? emptyComponent
: (data as Array<ItemT>)?.map((item, index) => {
const key = keyExtractor!(item, index) const key = keyExtractor!(item, index)
return ( return (
<Row<ItemT> <Row<ItemT>