diff options
author | dan <dan.abramov@gmail.com> | 2023-12-21 22:56:45 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-21 14:56:45 -0800 |
commit | bc31da47fdcb4c1704c96b0083f8e5429475da4e (patch) | |
tree | def266d74be5554614b53bf097e8d2ce24687615 /src/view/com/util/List.tsx | |
parent | 987c543727dd4d816987148ec3ccdb4337d601ac (diff) | |
download | voidsky-bc31da47fdcb4c1704c96b0083f8e5429475da4e.tar.zst |
Consolidate List props a bit (#2216)
Diffstat (limited to 'src/view/com/util/List.tsx')
-rw-r--r-- | src/view/com/util/List.tsx | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/view/com/util/List.tsx b/src/view/com/util/List.tsx index 2acc3f4b3..9abd7d35a 100644 --- a/src/view/com/util/List.tsx +++ b/src/view/com/util/List.tsx @@ -1,27 +1,42 @@ import React, {memo, startTransition} from 'react' -import {FlatListProps} from 'react-native' +import {FlatListProps, RefreshControl} from 'react-native' import {FlatList_INTERNAL} from './Views' +import {addStyle} from 'lib/styles' import {useScrollHandlers} from '#/lib/ScrollContext' import {runOnJS, useSharedValue} from 'react-native-reanimated' import {useAnimatedScrollHandler} from '#/lib/hooks/useAnimatedScrollHandler_FIXED' +import {usePalette} from '#/lib/hooks/usePalette' export type ListMethods = FlatList_INTERNAL export type ListProps<ItemT> = Omit< 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 + headerOffset?: number + refreshing?: boolean + onRefresh?: () => void } export type ListRef = React.MutableRefObject<FlatList_INTERNAL | null> const SCROLLED_DOWN_LIMIT = 200 function ListImpl<ItemT>( - {onScrolledDownChange, ...props}: ListProps<ItemT>, + { + onScrolledDownChange, + refreshing, + onRefresh, + headerOffset, + style, + ...props + }: ListProps<ItemT>, ref: React.Ref<ListMethods>, ) { const isScrolledDown = useSharedValue(false) const contextScrollHandlers = useScrollHandlers() + const pal = usePalette('default') function handleScrolledDownChange(didScrollDown: boolean) { startTransition(() => { @@ -49,12 +64,36 @@ function ListImpl<ItemT>( }, }) + let refreshControl + if (refreshing !== undefined || onRefresh !== undefined) { + refreshControl = ( + <RefreshControl + refreshing={refreshing ?? false} + onRefresh={onRefresh} + tintColor={pal.colors.text} + titleColor={pal.colors.text} + progressViewOffset={headerOffset} + /> + ) + } + + let contentOffset + if (headerOffset != null) { + style = addStyle(style, { + paddingTop: headerOffset, + }) + contentOffset = {x: 0, y: headerOffset * -1} + } + return ( <FlatList_INTERNAL {...props} scrollIndicatorInsets={{right: 1}} + contentOffset={contentOffset} + refreshControl={refreshControl} onScroll={scrollHandler} scrollEventThrottle={1} + style={style} ref={ref} /> ) |