diff --git a/src/components/List/index.tsx b/src/components/List/index.tsx index c5e55da795..44338a8241 100644 --- a/src/components/List/index.tsx +++ b/src/components/List/index.tsx @@ -26,7 +26,10 @@ export { * * - `contentOffset` - Use `headerOffset` or `footerOffset` */ -type ListProps = Omit, 'contentOffset'> & { +type ListProps = Omit< + FlatListProps, + 'contentOffset' +> & { /** * Wrapper around `onViewableItemsChanged` that calls back with individual * items IF they `item.isViewable` is true. @@ -49,7 +52,7 @@ type ListProps = Omit, 'contentOffset'> & { onScrolledDownChange?: (isScrolledDown: boolean) => void } -export const List = forwardRef(function List( +export const List = forwardRef(function List( props: ListProps, ref: React.Ref>, ) { @@ -126,6 +129,7 @@ export const List = forwardRef(function List( return ( i.key)} viewabilityConfig={viewabilityConfig} onViewableItemsChanged={onViewableItemsChanged} /** @@ -150,14 +154,6 @@ export const List = forwardRef(function List( */ right: 1, }} - /** - * iOS-only, should match `scrollIndicatorInsets` - * @see https://reactnative.dev/docs/scrollview#contentinset-ios - */ - contentInset={{ - top: props.headerOffset ?? 0, - bottom: props.footerOffset ?? 0, - }} /** * Native only. On web, we use padding on `style` instead. */ @@ -168,21 +164,21 @@ export const List = forwardRef(function List( refreshControl={refreshControl} {...(props as FlatListPropsWithLayout)} style={[ - /* - * On web, the List should always fill its container, otherwise - * `onScroll` will not work due to the entire page scrolling. - */ + { + paddingTop: props.headerOffset, + paddingBottom: props.footerOffset, + }, web([ + /* + * On web, the List should always fill its container, otherwise + * `onScroll` will not work due to the entire page scrolling. + */ a.h_full, - { - paddingTop: props.headerOffset, - paddingBottom: props.footerOffset, - }, ]), ]} onScroll={onScroll} /> ) -}) as ( +}) as ( props: ListProps & {ref?: React.Ref>}, ) => React.ReactElement diff --git a/src/view/screens/StorybookLists/index.tsx b/src/view/screens/StorybookLists/index.tsx index 347d6e6d62..ca67e33742 100644 --- a/src/view/screens/StorybookLists/index.tsx +++ b/src/view/screens/StorybookLists/index.tsx @@ -1,7 +1,10 @@ +import {useState} from 'react' import {View} from 'react-native' import {runOnJS} from 'react-native-reanimated' +import {List as OldList} from '#/view/com/util/List' import {atoms as a} from '#/alf' +import {Button, ButtonText} from '#/components/Button' import * as Layout from '#/components/Layout' import {List, ListScrollProvider, useListScrollHandler} from '#/components/List' import {Text} from '#/components/Typography' @@ -36,6 +39,7 @@ type Item = { const log = (msg: any) => console.log(msg) export function Inner() { + const [old, setOld] = useState(false) const onScrollWorklet = useListScrollHandler(e => { 'worklet' runOnJS(log)(`scroll ${e.contentOffset.y}`) @@ -43,22 +47,54 @@ export function Inner() { return ( - - - data={items} - headerOffset={100} - footerOffset={100} - onScrolledDownChange={scrolledDown => { - console.log(`Scrolled down: ${scrolledDown}`) - }} - renderItem={({item}) => ( - - {item.title} - - )} - style={[a.debug]} - /> - + + + + + {!old ? ( + + + data={items} + headerOffset={100} + footerOffset={100} + onScrolledDownChange={scrolledDown => { + console.log(`Scrolled down: ${scrolledDown}`) + }} + renderItem={({item}) => ( + + {item.title} + + )} + style={[a.debug]} + /> + + ) : ( + + item.key} + headerOffset={100} + onScrolledDownChange={scrolledDown => { + console.log(`Scrolled down: ${scrolledDown}`) + }} + renderItem={({item}) => ( + + {item.title} + + )} + style={[a.debug]} + /> + + )} ) }