0.4.0 • Published 2 years ago

react-native-speedy-list v0.4.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Speedy List

npm npm npm

A performance-focused component for React Native.

Purpose

Speedy List is a high-performance list component for React Native inspired by the great project RecyclerListView. It relies on the idea that repositioning elements and changing their content is faster than instantiating new elements.

This simple idea along with small tricks creates smoother animations, navigations and dialog openings.

How it works

While your list may need to handle 1 million items, the screen shows actually only a few of them. Besides that, these big lists usually have a similar layout for all items, which brings us an interesting possibility: why not only render enough items to fill the screen, and reuse items while scrolling? That's the main purpose of Speedy List.

Let's suppose your screen has a height of 1920 pixels, and each list element has a height of 192 pixels, so 20 items would be enough to fit two times the entire screen. Once you start scrolling your list, the first item will be hidden at the top and will be invisible to the user. Speedy List will take advantage of it, by repositioning this hidden item at position 21 and changing its content to item 21's content, which is faster than rendering new components every time the screen is scrolled.

Another good improvement is on the first render. Instead of rendering 20 elements at once, Speedy List will render these elements in a configurable number of batches, which makes navigations softer. This is especially perceptible on animated list dialogs.

That's it, simple and effective.

Limitations

At the moment, Speedy List can't handle:

  • Horizontal scrolling;
  • Sticky indexes, excepting the first index;
  • Items with zero height.

Also, please note that this is a young project, and still needs a lot of improvements. PRs are welcome.

Installation

Install Speedy List with either yarn or npm:

yarn add react-native-speedy-list or npm install --save react-native-speedy-list

No native setup is needed.

Usage Example

import { SpeedyList, SpeedyListItemMeta, SpeedyListItemRenderer } from "react-native-speedy-list"

const [items] = useState<Array<User>>([{ id: 0, name: "User 001" }, ...]);  
  
const itemRenderer = useCallback<SpeedyListItemRenderer<User>>(
    ({ item }) => { 
        // Don't use key prop here, since it would kill
        // the recycling purpose.
        return <Text>{item.name}</Text> 
    }, 
    []
)
  
<SpeedyList<User>
    items={items} 
    itemRenderer={itemRenderer} 
    itemHeight={42}
    itemKey={"id"} />  

Props

PropValue TypeDefault ValueDescription
itemsArray<T>Required*List entries.
itemRendererSpeedyListItemRenderer<T>Required*Function to render a list entry.
itemHeightnumber \| ((meta: SpeedyListItemMeta<T>) => number)Required*Number or function to extract an entry height.
itemKeykeyof T \| ((meta: SpeedyListItemMeta<T>) => number \| string)Required*Property name or function to extract an entry unique key.
itemEquals(a: T, b: T) => booleanDefaults to a build-in shallow comparator.Function to compare two entries.
onEndReached() => voidnullCalled when the ScrollView reaches the end.
onEndReachedOffsetnumber0Offset of the botton before calling onEndReached.
columnsnumber1Amount of columns per row.
headerReact.ReactNodenullList header component.
footerReact.ReactNodenullList footer component.
initialBatchSizenumber8First render batch size.
recyclableItemsCountnumber32Amount of recyclable items to render. This should be enough to fill at least two times the screen height.
recyclingDelaynumber32Interval in milliseconds between list updates.
scrollViewPropsScrollViewPropsnullApplied to the internal ScrollView component.
headerStyleStyleProp<ViewStyle>nullApplied to the header wrapper component.
footerStyleStyleProp<ViewStyle>nullApplied to the footer wrapper component.
rowStyleStyleProp<ViewStyle>nullApplied to the row wrapper component.
cellStyleStyleProp<ViewStyle>nullApplied to the cell wrapper component.
debugbooleanfalseEnables Speedy List debug logs

Licence

MIT License

Special Thanks

Thanks to RecyclerListView creator and contributors. And thanks to kerleysol and mardsonferreira for contributing with the list update algorithm.

0.2.1

2 years ago

0.2.0

2 years ago

0.4.0

2 years ago

0.2.2

2 years ago

0.1.7

2 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago