More stuff
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
import React, {memo, startTransition} from 'react'
|
import React, {memo, startTransition} from 'react'
|
||||||
import {FlatListProps, ScrollView, StyleSheet, View} from 'react-native'
|
import {
|
||||||
|
FlatListProps,
|
||||||
|
RefreshControl,
|
||||||
|
ScrollView,
|
||||||
|
StyleSheet,
|
||||||
|
View,
|
||||||
|
} from 'react-native'
|
||||||
import {addStyle} from 'lib/styles'
|
import {addStyle} from 'lib/styles'
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||||
@@ -8,9 +14,14 @@ import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
|
|||||||
export type ListMethods = FlatList_INTERNAL
|
export type ListMethods = FlatList_INTERNAL
|
||||||
export type ListProps<ItemT> = Omit<
|
export type ListProps<ItemT> = Omit<
|
||||||
FlatListProps<ItemT>,
|
FlatListProps<ItemT>,
|
||||||
'onScroll' // Use ScrollContext instead.
|
| 'onScroll' // Use ScrollContext instead.
|
||||||
|
| 'refreshControl' // Pass refreshing and/or onRefresh instead.
|
||||||
|
| 'contentOffset' // Pass headerOffset instead.
|
||||||
> & {
|
> & {
|
||||||
onScrolledDownChange?: (isScrolledDown: boolean) => void
|
onScrolledDownChange?: (isScrolledDown: boolean) => void
|
||||||
|
headerOffset?: number
|
||||||
|
refreshing?: boolean
|
||||||
|
onRefresh?: () => void
|
||||||
}
|
}
|
||||||
export type ListRef = React.MutableRefObject<FlatList_INTERNAL | null>
|
export type ListRef = React.MutableRefObject<FlatList_INTERNAL | null>
|
||||||
|
|
||||||
@@ -19,13 +30,15 @@ function ListImpl<ItemT>(
|
|||||||
ListHeaderComponent,
|
ListHeaderComponent,
|
||||||
ListFooterComponent,
|
ListFooterComponent,
|
||||||
contentContainerStyle,
|
contentContainerStyle,
|
||||||
contentOffset,
|
|
||||||
data,
|
data,
|
||||||
desktopFixedHeight,
|
desktopFixedHeight, // TODO
|
||||||
|
headerOffset,
|
||||||
keyExtractor,
|
keyExtractor,
|
||||||
|
refreshing,
|
||||||
onEndReached,
|
onEndReached,
|
||||||
onEndReachedThreshold,
|
onEndReachedThreshold,
|
||||||
onScrolledDownChange,
|
onRefresh,
|
||||||
|
onScrolledDownChange, // TODO
|
||||||
renderItem,
|
renderItem,
|
||||||
extraData,
|
extraData,
|
||||||
style,
|
style,
|
||||||
@@ -42,20 +55,6 @@ function ListImpl<ItemT>(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contentOffset && contentOffset?.y !== 0) {
|
|
||||||
// NOTE
|
|
||||||
// we use paddingTop & contentOffset to space around the floating header
|
|
||||||
// but reactnative web puts the paddingTop on the wrong element (style instead of the contentContainer)
|
|
||||||
// so we manually correct it here
|
|
||||||
// -prf
|
|
||||||
style = addStyle(style, {
|
|
||||||
paddingTop: 0,
|
|
||||||
})
|
|
||||||
contentContainerStyle = addStyle(contentContainerStyle, {
|
|
||||||
paddingTop: Math.abs(contentOffset.y),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
let header = null
|
let header = null
|
||||||
if (ListHeaderComponent != null) {
|
if (ListHeaderComponent != null) {
|
||||||
if (typeof ListHeaderComponent === 'object') {
|
if (typeof ListHeaderComponent === 'object') {
|
||||||
@@ -76,6 +75,26 @@ function ListImpl<ItemT>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: This doesn't work when refreshing is true. Is it supposed to?'
|
||||||
|
let refreshControl
|
||||||
|
if (refreshing !== undefined || onRefresh !== undefined) {
|
||||||
|
refreshControl = (
|
||||||
|
<RefreshControl
|
||||||
|
refreshing={refreshing ?? false}
|
||||||
|
onRefresh={onRefresh}
|
||||||
|
tintColor={pal.colors.text}
|
||||||
|
titleColor={pal.colors.text}
|
||||||
|
progressViewOffset={headerOffset}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (headerOffset != null) {
|
||||||
|
style = addStyle(style, {
|
||||||
|
paddingTop: headerOffset,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const nativeRef = React.useRef(null)
|
const nativeRef = React.useRef(null)
|
||||||
React.useImperativeHandle(
|
React.useImperativeHandle(
|
||||||
ref,
|
ref,
|
||||||
@@ -127,6 +146,7 @@ function ListImpl<ItemT>(
|
|||||||
desktopFixedHeight ? styles.minHeightViewport : null,
|
desktopFixedHeight ? styles.minHeightViewport : null,
|
||||||
pal.border,
|
pal.border,
|
||||||
]}>
|
]}>
|
||||||
|
{refreshControl}
|
||||||
{header}
|
{header}
|
||||||
{(data as Array<ItemT>).map((item, index) => (
|
{(data as Array<ItemT>).map((item, index) => (
|
||||||
<Row<ItemT>
|
<Row<ItemT>
|
||||||
|
|||||||
Reference in New Issue
Block a user