mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
24 lines
7.2 KiB
Markdown
24 lines
7.2 KiB
Markdown
---
|
|
id: version-0.49-virtualizedlist
|
|
title: virtualizedlist
|
|
original_id: virtualizedlist
|
|
---
|
|
<a id="content"></a><h1><a class="anchor" name="virtualizedlist"></a>VirtualizedList <a class="hash-link" href="docs/virtualizedlist.html#virtualizedlist">#</a></h1><div><div><p>Base implementation for the more convenient <a href="/react-native/docs/flatlist.html" target=""><code><FlatList></code></a>
|
|
and <a href="/react-native/docs/sectionlist.html" target=""><code><SectionList></code></a> components, which are also better
|
|
documented. In general, this should only really be used if you need more flexibility than
|
|
<code>FlatList</code> provides, e.g. for use with immutable data instead of plain arrays.</p><p>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.</p><p>Some caveats:</p><ul><li>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.</li><li>This is a <code>PureComponent</code> which means that it will not re-render if <code>props</code> remain shallow-
|
|
equal. Make sure that everything your <code>renderItem</code> function depends on is passed as a prop
|
|
(e.g. <code>extraData</code>) that is not <code>===</code> after updates, otherwise your UI may not update on
|
|
changes. This includes the <code>data</code> prop and parent component state.</li><li>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 ands 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.</li><li>By default, the list looks for a <code>key</code> prop on each item and uses that for the React key.
|
|
Alternatively, you can provide a custom <code>keyExtractor</code> prop.</li></ul></div><h3><a class="anchor" name="props"></a>Props <a class="hash-link" href="docs/virtualizedlist.html#props">#</a></h3><div class="props"><div class="prop"><h4 class="propTitle"><a class="anchor" name="disablevirtualization"></a>disableVirtualization?: <a class="hash-link" href="docs/virtualizedlist.html#disablevirtualization">#</a></h4></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="first"></a>first: <span class="propType">number</span> <a class="hash-link" href="docs/virtualizedlist.html#first">#</a></h4></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="horizontal"></a>horizontal?: <a class="hash-link" href="docs/virtualizedlist.html#horizontal">#</a></h4></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="initialnumtorender"></a>initialNumToRender?: <a class="hash-link" href="docs/virtualizedlist.html#initialnumtorender">#</a></h4></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="keyextractor"></a>keyExtractor?: <a class="hash-link" href="docs/virtualizedlist.html#keyextractor">#</a></h4></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="last"></a>last: <span class="propType">number</span> <a class="hash-link" href="docs/virtualizedlist.html#last">#</a></h4></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="maxtorenderperbatch"></a>maxToRenderPerBatch?: <a class="hash-link" href="docs/virtualizedlist.html#maxtorenderperbatch">#</a></h4></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="onendreachedthreshold"></a>onEndReachedThreshold?: <a class="hash-link" href="docs/virtualizedlist.html#onendreachedthreshold">#</a></h4></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="scrolleventthrottle"></a>scrollEventThrottle?: <a class="hash-link" href="docs/virtualizedlist.html#scrolleventthrottle">#</a></h4></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="updatecellsbatchingperiod"></a>updateCellsBatchingPeriod?: <a class="hash-link" href="docs/virtualizedlist.html#updatecellsbatchingperiod">#</a></h4></div><div class="prop"><h4 class="propTitle"><a class="anchor" name="windowsize"></a>windowSize?: <a class="hash-link" href="docs/virtualizedlist.html#windowsize">#</a></h4></div></div><span><h3><a class="anchor" name="methods"></a>Methods <a class="hash-link" href="docs/virtualizedlist.html#methods">#</a></h3><div class="props"><div class="prop"><h4 class="methodTitle"><a class="anchor" name="scrolltoend"></a>scrollToEnd<span class="methodType">(params?: object)</span> <a class="hash-link" href="docs/virtualizedlist.html#scrolltoend">#</a></h4></div><div class="prop"><h4 class="methodTitle"><a class="anchor" name="scrolltoindex"></a>scrollToIndex<span class="methodType">(params: object)</span> <a class="hash-link" href="docs/virtualizedlist.html#scrolltoindex">#</a></h4></div><div class="prop"><h4 class="methodTitle"><a class="anchor" name="scrolltoitem"></a>scrollToItem<span class="methodType">(params: object)</span> <a class="hash-link" href="docs/virtualizedlist.html#scrolltoitem">#</a></h4></div><div class="prop"><h4 class="methodTitle"><a class="anchor" name="scrolltooffset"></a>scrollToOffset<span class="methodType">(params: object)</span> <a class="hash-link" href="docs/virtualizedlist.html#scrolltooffset">#</a></h4><div><p>Scroll to a specific content pixel offset in the list.</p><p>Param <code>offset</code> expects the offset to scroll to.
|
|
In case of <code>horizontal</code> is true, the offset is the x-value,
|
|
in any other case the offset is the y-value.</p><p>Param <code>animated</code> (<code>true</code> by default) defines whether the list
|
|
should do an animation while scrolling.</p></div></div><div class="prop"><h4 class="methodTitle"><a class="anchor" name="recordinteraction"></a>recordInteraction<span class="methodType">()</span> <a class="hash-link" href="docs/virtualizedlist.html#recordinteraction">#</a></h4></div><div class="prop"><h4 class="methodTitle"><a class="anchor" name="flashscrollindicators"></a>flashScrollIndicators<span class="methodType">()</span> <a class="hash-link" href="docs/virtualizedlist.html#flashscrollindicators">#</a></h4></div></div></span><span><h3><a class="anchor" name="type-definitions"></a>Type Definitions <a class="hash-link" href="docs/virtualizedlist.html#type-definitions">#</a></h3><div class="props"><div class="prop"><h4 class="propTitle"><a class="anchor" name="props"></a>Props <a class="hash-link" href="docs/virtualizedlist.html#props">#</a></h4><strong>Type:</strong><br>IntersectionTypeAnnotation</div></div></span></div><p class="edit-page-block"><a target="_blank" href="https://github.com/facebook/react-native/blob/master/Libraries/Lists/VirtualizedList.js">Improve this page</a> by sending a pull request!</p><div class="docs-prevnext"><a class="docs-prev" href="docs/viewpagerandroid.html#content">← Prev</a><a class="docs-next" href="docs/webview.html#content">Next →</a></div> |