From 290b085de18c90a1c7b0d350023e709ffe208113 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 15 Dec 2023 04:43:14 +0000 Subject: [PATCH] More stuff --- src/view/com/util/List.web.tsx | 58 +++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/src/view/com/util/List.web.tsx b/src/view/com/util/List.web.tsx index f8e57abad4..2fb790c47b 100644 --- a/src/view/com/util/List.web.tsx +++ b/src/view/com/util/List.web.tsx @@ -1,5 +1,11 @@ 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 {usePalette} from 'lib/hooks/usePalette' import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' @@ -8,9 +14,14 @@ import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback' export type ListMethods = FlatList_INTERNAL export type ListProps = Omit< FlatListProps, - '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 @@ -19,13 +30,15 @@ function ListImpl( ListHeaderComponent, ListFooterComponent, contentContainerStyle, - contentOffset, data, - desktopFixedHeight, + desktopFixedHeight, // TODO + headerOffset, keyExtractor, + refreshing, onEndReached, onEndReachedThreshold, - onScrolledDownChange, + onRefresh, + onScrolledDownChange, // TODO renderItem, extraData, style, @@ -42,20 +55,6 @@ function ListImpl( ) } - 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 if (ListHeaderComponent != null) { if (typeof ListHeaderComponent === 'object') { @@ -76,6 +75,26 @@ function ListImpl( } } + // TODO: This doesn't work when refreshing is true. Is it supposed to?' + let refreshControl + if (refreshing !== undefined || onRefresh !== undefined) { + refreshControl = ( + + ) + } + + if (headerOffset != null) { + style = addStyle(style, { + paddingTop: headerOffset, + }) + } + const nativeRef = React.useRef(null) React.useImperativeHandle( ref, @@ -127,6 +146,7 @@ function ListImpl( desktopFixedHeight ? styles.minHeightViewport : null, pal.border, ]}> + {refreshControl} {header} {(data as Array).map((item, index) => (