FlatList provides, e.g. for use with immutable data instead of plain arrays.
Virtualization massively improves memory consumption and performance of large lists by maintaining a finite render window of active items and replacing all items outside of the render window with appropriately sized blank space. The window adapts to scrolling behavior, and items are rendered incrementally with low-pri (after any running interactions) if they are far from the visible area, or with hi-pri otherwise to minimize the potential of seeing blank space.
Example
Some caveats:
- Internal state is not preserved when content scrolls out of the render window. Make sure all your data is captured in the item data or external stores like Flux, Redux, or Relay.
- This is a
PureComponentwhich means that it will not re-render ifpropsare shallow-equal. Make sure that everything yourrenderItemfunction depends on is passed as a prop (e.g.extraData) that is not===after updates, otherwise your UI may not update on changes. This includes thedataprop and parent component state. - In order to constrain memory and enable smooth scrolling, content is rendered asynchronously offscreen. This means it’s possible to scroll faster than the fill rate and momentarily see blank content. This is a tradeoff that can be adjusted to suit the needs of each application, and we are working on improving it behind the scenes.
- By default, the list looks for a
keyprop on each item and uses that for the React key. Alternatively, you can provide a customkeyExtractorprop.
Reference
Props
ScrollView props
Inherits ScrollView Props.data
Opaque data type passed togetItem and getItemCount to retrieve items.
getItem Required
getItemCount Required
renderItem Required
data and renders it into the list
ItemSeparatorComponent
Rendered in between each item, but not at the top or bottom. By default,highlighted and leadingItem props are provided. renderItem provides separators.highlight/unhighlight which will update the highlighted prop, but you can also add custom props with separators.updateProps. Can be a React Component (e.g. SomeComponent), or a React element (e.g. ).
ListItemComponent
Each data item is rendered using this element. Can be a React Component Class, or a render function.ListFooterComponent
Rendered at the bottom of all the items. Can be a React Component (e.g.SomeComponent), or a React element (e.g. ).
ListFooterComponentStyle
Styling for internal View forListFooterComponent.
ListHeaderComponent
Rendered at the top of all the items. Can be a React Component (e.g.SomeComponent), or a React element (e.g. ).
ListHeaderComponentStyle
Styling for internal View forListHeaderComponent.
debug
debug will turn on extra logging and visual overlays to aid with debugging both usage and implementation, but with a significant perf hit.
getItemLayout
horizontal
Iftrue, renders items next to each other horizontally instead of stacked vertically.
initialNumToRender
How many items to render in the initial batch. This should be enough to fill the screen but not much more. Note these items will never be unmounted as part of the windowed rendering in order to improve perceived performance of scroll-to-top actions.initialScrollIndex
Instead of starting at the top with the first item, start atinitialScrollIndex. This disables the “scroll to top” optimization that keeps the first initialNumToRender items always rendered and immediately renders the items starting at this initial index. Requires getItemLayout to be implemented.
keyExtractor
item.key, then item.id, and then falls back to using the index, like React does.
onEndReached
Called once when the scroll position gets withinonEndReachedThreshold from the logical end of the list.
onEndReachedThreshold
How far from the end (in units of visible length of the list) the trailing edge of the list must be from the end of the content to trigger theonEndReached callback. Thus, a value of 0.5 will trigger onEndReached when the end of the content is within half the visible length of the list.
onStartReached
Called once when the scroll position gets within withinonStartReachedThreshold from the logical start of the list.
onStartReachedThreshold
How far from the start (in units of visible length of the list) the leading edge of the list must be from the start of the content to trigger theonStartReached callback. Thus, a value of 0.5 will trigger onStartReached when the start of the content is within half the visible length of the list.
onViewableItemsChanged
Called when the viewability of rows changes, as defined by theviewabilityConfig prop.
progressViewOffset
Set this when offset is needed for the loading indicator to show correctly.viewabilityConfig
SeeViewabilityHelper.js for flow type and further documentation.
viewabilityConfigCallbackPairs
List ofViewabilityConfig/onViewableItemsChanged pairs. A specific onViewableItemsChanged will be called when its corresponding ViewabilityConfig’s conditions are met. See ViewabilityHelper.js for flow type and further documentation.
scrollToEnd()
getItemLayout prop.
Parameters:
params keys are:
'animated'(boolean) - Whether the list should do an animation while scrolling. Defaults totrue.
scrollToIndex()
params consist of:
- index (number). Required.
- animated (boolean). Optional.
- viewOffset (number). Optional.
- viewPosition (number). Optional.
scrollToOffset()
offset expects the offset to scroll to. In case of horizontal is true, the offset is the x-value, in any other case the offset is the y-value.
Param animated (true by default) defines whether the list should do an animation while scrolling.

