More FlatList parity
This commit is contained in:
@@ -52,6 +52,7 @@ export function CenteredView({
|
|||||||
export const FlatList = React.forwardRef(function FlatListImpl<ItemT>(
|
export const FlatList = React.forwardRef(function FlatListImpl<ItemT>(
|
||||||
{
|
{
|
||||||
data,
|
data,
|
||||||
|
extraData,
|
||||||
contentOffset,
|
contentOffset,
|
||||||
keyExtractor,
|
keyExtractor,
|
||||||
renderItem,
|
renderItem,
|
||||||
@@ -60,6 +61,8 @@ export const FlatList = React.forwardRef(function FlatListImpl<ItemT>(
|
|||||||
onEndReached,
|
onEndReached,
|
||||||
onEndReachedThreshold,
|
onEndReachedThreshold,
|
||||||
onScroll,
|
onScroll,
|
||||||
|
ListHeaderComponent,
|
||||||
|
ListFooterComponent,
|
||||||
...props
|
...props
|
||||||
}: React.PropsWithChildren<FlatListProps<ItemT> & AddedProps>,
|
}: React.PropsWithChildren<FlatListProps<ItemT> & AddedProps>,
|
||||||
ref: React.Ref<Animated.FlatList<ItemT>>,
|
ref: React.Ref<Animated.FlatList<ItemT>>,
|
||||||
@@ -85,6 +88,7 @@ export const FlatList = React.forwardRef(function FlatListImpl<ItemT>(
|
|||||||
paddingTop: Math.abs(contentOffset.y),
|
paddingTop: Math.abs(contentOffset.y),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const nativeRef = React.useRef(null)
|
const nativeRef = React.useRef(null)
|
||||||
React.useImperativeHandle(
|
React.useImperativeHandle(
|
||||||
ref,
|
ref,
|
||||||
@@ -134,21 +138,44 @@ export const FlatList = React.forwardRef(function FlatListImpl<ItemT>(
|
|||||||
})
|
})
|
||||||
}, [onEndReachedThreshold, onEndReached])
|
}, [onEndReachedThreshold, onEndReached])
|
||||||
|
|
||||||
|
let header = null
|
||||||
|
if (ListHeaderComponent != null) {
|
||||||
|
if (typeof ListHeaderComponent === 'object') {
|
||||||
|
header = ListHeaderComponent
|
||||||
|
} else if (typeof ListHeaderComponent === 'function') {
|
||||||
|
// @ts-ignore We aren't using classes so it's a render function.
|
||||||
|
header = ListHeaderComponent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let footer = null
|
||||||
|
if (ListFooterComponent != null) {
|
||||||
|
if (typeof ListFooterComponent === 'object') {
|
||||||
|
footer = ListFooterComponent
|
||||||
|
} else if (typeof ListFooterComponent === 'function') {
|
||||||
|
// @ts-ignore We aren't using classes so it's a render function.
|
||||||
|
footer = ListFooterComponent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Animated.ScrollView {...props} style={style} ref={nativeRef}>
|
<Animated.ScrollView {...props} style={style} ref={nativeRef}>
|
||||||
<View
|
<View
|
||||||
style={[styles.contentContainer, contentContainerStyle, pal.border]}>
|
style={[styles.contentContainer, contentContainerStyle, pal.border]}>
|
||||||
|
{header}
|
||||||
{(data as Array<ItemT>).map((item, index) => (
|
{(data as Array<ItemT>).map((item, index) => (
|
||||||
<Row<ItemT>
|
<Row<ItemT>
|
||||||
key={keyExtractor!(item, index)}
|
key={keyExtractor!(item, index)}
|
||||||
item={item}
|
item={item}
|
||||||
index={index}
|
index={index}
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
|
extraData={extraData}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
{onEndReached && (
|
{onEndReached && (
|
||||||
<Tail threshold={onEndReachedThreshold} onVisible={onVisible} />
|
<Tail threshold={onEndReachedThreshold} onVisible={onVisible} />
|
||||||
)}
|
)}
|
||||||
|
{footer}
|
||||||
</View>
|
</View>
|
||||||
</Animated.ScrollView>
|
</Animated.ScrollView>
|
||||||
)
|
)
|
||||||
@@ -158,6 +185,7 @@ let Row = function RowImpl<ItemT>({
|
|||||||
item,
|
item,
|
||||||
index,
|
index,
|
||||||
renderItem,
|
renderItem,
|
||||||
|
extraData: _unused,
|
||||||
}: {
|
}: {
|
||||||
item: ItemT
|
item: ItemT
|
||||||
index: number
|
index: number
|
||||||
@@ -165,6 +193,7 @@ let Row = function RowImpl<ItemT>({
|
|||||||
| null
|
| null
|
||||||
| undefined
|
| undefined
|
||||||
| ((data: {index: number; item: any; separators: any}) => React.ReactNode)
|
| ((data: {index: number; item: any; separators: any}) => React.ReactNode)
|
||||||
|
extraData: any
|
||||||
}): React.ReactNode {
|
}): React.ReactNode {
|
||||||
if (!renderItem) {
|
if (!renderItem) {
|
||||||
return null
|
return null
|
||||||
|
|||||||
Reference in New Issue
Block a user