diff --git a/README.md b/README.md index 4226be5..454246f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # react-native-tiny-list -Simple flat list component +Tiny, readable virtualized lists for React Native ## Installation @@ -28,6 +28,37 @@ area and replaces the rest with spacer views. Item heights are measured with `onLayout` and cached by index; unmeasured items are assumed to be 50 px tall. Expect blank areas and content jumps while scrolling fast. +```tsx +import { TinyFlatList } from 'react-native-tiny-list'; + + item.id} + initialNumToRender={10} + windowSize={21} + maxToRenderPerBatch={10} + updateCellsBatchingPeriod={50} +/> +``` + +`TinyFlatList` adds the core ideas of React Native's `FlatList` on top of +`TinyList`: + +- **Keys.** `keyExtractor` (default: `item.key`, then `item.id`, then the + index) keys both the items and the cached sizes, so sizes survive inserts and + reorders. Unmeasured items count as the average measured size. +- **`initialNumToRender`.** Items rendered before the viewport is measured. + They stay rendered, so scrolling back to the top shows them instantly. +- **`windowSize`.** The area kept rendered, in viewports, centered on the + visible one. +- **Batched rendering.** Scrolling does not re-render the list while the + visible items are already rendered. The area off screen is filled + `maxToRenderPerBatch` items at a time, every `updateCellsBatchingPeriod` ms. + When the visible area is blank, the list renders right away. +- **Memoized items.** Each item re-renders only when its props or `extraData` + change. + ## Contributing diff --git a/example/src/App.tsx b/example/src/App.tsx index 9a3da52..7c10e62 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,5 +1,10 @@ -import { StyleSheet, Text, View } from 'react-native'; -import { TinyList } from 'react-native-tiny-list'; +import { useState } from 'react'; +import { Button, StyleSheet, Text, View } from 'react-native'; +import { + TinyFlatList, + TinyList, + type TinyFlatListRenderItemInfo, +} from 'react-native-tiny-list'; type Item = { id: number; title: string }; @@ -8,18 +13,31 @@ const DATA: Item[] = Array.from({ length: 10_000 }, (_, i) => ({ title: `Item ${i}`, })); +// Defined outside the component so it stays stable and TinyFlatList can skip +// re-rendering unchanged items. +function renderItem({ item, index }: TinyFlatListRenderItemInfo) { + return ( + // Vary heights to exercise measurement. + + {item.title} + + ); +} + export default function App() { + const [list, setList] = useState<'list' | 'flatList'>('flatList'); + return ( - ( - // Vary heights to exercise measurement. - - {item.title} - - )} - /> + +