Pro component
Requires all-access to use the source code
import { ListRenderItemInfo } from '@shopify/flash-list';
import { Stack } from 'expo-router';
import { View } from 'react-native';
import { Text } from '~/components/nativewindui/Text';
import { ESTIMATED_ITEM_HEIGHT, List, ListDataItem, ListItem, ListSectionHeader } from '../List';
export default function ListScreen() {
return (
<>
<Stack.Screen options={{ title: 'Insets' }} />
<List
variant="insets"
data={DATA}
estimatedItemSize={ESTIMATED_ITEM_HEIGHT.titleOnly}
renderItem={renderItem}
keyExtractor={keyExtractor}
/>
</>
);
}
function renderItem<T extends ListDataItem>(info: ListRenderItemInfo<T>) {
if (typeof info.item === 'string') {
return <ListSectionHeader {...info} />;
}
return (
<ListItem
leftView={
<View className="flex-1 justify-center px-4">
<View className="aspect-square h-8 rounded bg-red-500" />
</View>
}
rightView={
<View className="flex-1 justify-center px-4">
<Text variant="caption1" className="ios:px-0 text-muted-foreground px-2">
100+
</Text>
</View>
}
{...info}
onPress={() => console.log('onPress')}
/>
);
}
function keyExtractor(item: (Omit<ListDataItem, string> & { id: string }) | string) {
return typeof item === 'string' ? item : item.id;
}
const DATA = [
'Header',
{
id: '1',
title: 'Hello',
subTitle: 'World',
},
{
id: '2',
title: 'Hello',
subTitle: 'World',
},
{
id: '3',
title: 'Hello',
subTitle: 'World',
},
{
id: '4',
title: 'Hello',
subTitle: 'World',
},
'Header 2',
{
id: '5',
title: 'Hello',
subTitle: 'World',
},
{
id: '6',
title: 'Hello',
subTitle: 'World',
},
{
id: '7',
title: 'Hello',
subTitle: 'World',
},
{
id: '8',
title: 'Hello',
subTitle: 'World',
},
'Header 3',
{
id: '9',
title: 'Hello',
subTitle: 'World',
},
{
id: '10',
title: 'Hello',
subTitle: 'World',
},
{
id: '11',
title: 'Hello',
subTitle: 'World',
},
{
id: '12',
title: 'Hello',
subTitle: 'World',
},
];
Unlock All Pro Screens & Components
Elevate your app with powerful, native-feeling components and templates. Build faster with beautiful ready-to-use designs.
import {
ESTIMATED_ITEM_HEIGHT,
List,
ListItem,
} from '~/components/nativewindui/List';
<List
data={[
{
id: '1',
title: 'Hello',
subTitle: 'World',
},
{
id: '2',
title: 'Hello',
subTitle: 'World',
},
{
id: '3',
title: 'Hello',
subTitle: 'World',
},
]}
estimatedItemSize={ESTIMATED_ITEM_HEIGHT.withSubTitle}
renderItem={(info) => {
return <ListItem {...info} />;
}}
keyExtractor={(item) => item.id}
/>
List
Inherits all the props from @shopify's FlashList component.
Prop | Type | Default | Description |
---|---|---|---|
renderItem | ListRenderItem<T> | Custom render function for list items. | |
variant | ListVariant | 'full-width' | The layout variant for the list. |
sectionHeaderAsGap | boolean | false | Whether the section header is used as a gap. |
rootClassName | string | Class name for the root element. | |
rootStyle | StyleProp<ViewStyle> | Style for the root element. | |
contentInsetAdjustmentBehavior | 'automatic' | 'scrollableAxes' | 'never' | 'always' | 'automatic' | Behavior for adjusting content insets. |
data | T[] | Data source for the list. | |
ref | ListRef<T> | Reference to the FlashList instance. | |
contentContainerClassName | string | Class name for the content container. |
ListItem
Inherits all the props from React Native's Pressable component.
Prop | Type | Default | Description |
---|---|---|---|
item | T | The data item for this list item. | |
isFirstInSection | boolean | Indicates if this is the first item in a section. | |
isLastInSection | boolean | Indicates if this is the last item in a section. | |
index | number | The index of the item in the list. | |
variant | ListVariant | The variant for the list item. | |
className | string | Additional class names for the list item. | |
androidRootClassName | string | Class name for the root element on Android. | |
titleClassName | string | Class name for the title text. | |
titleStyle | StyleProp<TextStyle> | Style for the title text. | |
textNumberOfLines | number | Number of lines for the title text. | |
subTitleStyle | StyleProp<TextStyle> | Style for the subtitle text. | |
subTitleClassName | string | Class name for the subtitle text. | |
subTitleNumberOfLines | number | Number of lines for the subtitle text. | |
textContentClassName | string | Class name for the content text container. | |
sectionHeaderAsGap | boolean | Whether the section header is used as a gap. | |
removeSeparator | boolean | false | Whether to remove the separator below the item. |
leftView | React.ReactNode | Custom view rendered on the left side of the item. | |
rightView | React.ReactNode | Custom view rendered on the right side of the item. | |
disabled | boolean | false | Whether the item is disabled. |
ref | ListItemRef | Reference to the list item component. |
ESTIMATED_ITEM_HEIGHT
: The estimated height of each list item with title only and with subtle.