mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
53 lines
46 KiB
HTML
53 lines
46 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<meta name="generator" content="Docusaurus v2.0.0-alpha.70">
|
|
<link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="React Native Blog RSS Feed">
|
|
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="React Native Blog Atom Feed">
|
|
<link rel="preconnect" href="https://www.google-analytics.com">
|
|
<script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=+new Date,ga("create","UA-41298772-2","auto"),ga("send","pageview")</script>
|
|
<script async src="https://www.google-analytics.com/analytics.js"></script>
|
|
<link rel="preconnect" href="https://www.google-analytics.com">
|
|
<link rel="preconnect" href="https://www.googletagmanager.com">
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-41298772-2"></script>
|
|
<script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","UA-41298772-2",{})</script>
|
|
<link rel="search" type="application/opensearchdescription+xml" title="React Native" href="/opensearch.xml">
|
|
<link rel="icon" href="/img/pwa/manifest-icon-512.png">
|
|
<link rel="manifest" href="/manifest.json">
|
|
<meta name="theme-color" content="#20232a">
|
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
<meta name="apple-mobile-web-app-status-bar-style" content="#20232a">
|
|
<link rel="apple-touch-icon" href="/img/pwa/manifest-icon-512.png">
|
|
<link rel="mask-icon" href="/img/pwa/manifest-icon-512.png" color="#06bcee">
|
|
<meta name="msapplication-TileImage" href="/img/pwa/manifest-icon-512.png">
|
|
<meta name="msapplication-TileColor" content="#20232a">
|
|
<script src="https://cdn.jsdelivr.net/npm/focus-visible@5.2.0/dist/focus-visible.min.js" defer="defer"></script>
|
|
<script src="https://snack.expo.io/embed.js" defer="defer"></script><title data-react-helmet="true">ListView · React Native</title><meta data-react-helmet="true" name="twitter:image:alt" content="Image for React Native"><meta data-react-helmet="true" name="docsearch:language" content="en"><meta data-react-helmet="true" name="docsearch:version" content="0.63"><meta data-react-helmet="true" name="docsearch:docusaurus_tag" content="docs-default-0.63"><meta data-react-helmet="true" property="og:image" content="https://reactnative.dev/img/logo-og.png"><meta data-react-helmet="true" name="twitter:card" content="summary"><meta data-react-helmet="true" name="twitter:image" content="https://reactnative.dev/img/logo-og.png"><meta data-react-helmet="true" property="og:title" content="ListView · React Native"><meta data-react-helmet="true" name="description" content="DEPRECATED - use one of the new list components, such as FlatList or SectionList for bounded memory use, fewer bugs, better performance, an easier to use API, and more features. Check out this blog post for more details."><meta data-react-helmet="true" property="og:description" content="DEPRECATED - use one of the new list components, such as FlatList or SectionList for bounded memory use, fewer bugs, better performance, an easier to use API, and more features. Check out this blog post for more details."><meta data-react-helmet="true" property="og:url" content="https://reactnative.dev/docs/listview"><link data-react-helmet="true" rel="shortcut icon" href="/img/favicon.ico"><link data-react-helmet="true" rel="preconnect" href="https://BH4D9OD16A-dsn.algolia.net" crossorigin="anonymous"><link data-react-helmet="true" rel="canonical" href="https://reactnative.dev/docs/listview"><link rel="stylesheet" href="/styles.f56da522.css">
|
|
<link rel="stylesheet" href="/main.3de2b5ef.css">
|
|
<link rel="preload" href="/styles.69e4b76b.js" as="script">
|
|
<link rel="preload" href="/runtime~main.289e81aa.js" as="script">
|
|
<link rel="preload" href="/main.b86b035f.js" as="script">
|
|
<link rel="preload" href="/1.de054a96.js" as="script">
|
|
<link rel="preload" href="/2.d28ff3f3.js" as="script">
|
|
<link rel="preload" href="/929.d078dd2b.js" as="script">
|
|
<link rel="preload" href="/ee5b3385.efdac311.js" as="script">
|
|
<link rel="preload" href="/17896441.a6fe599d.js" as="script">
|
|
<link rel="preload" href="/ffc0709f.07ddfbec.js" as="script">
|
|
</head>
|
|
<body>
|
|
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
|
|
<nav aria-label="Skip navigation links"><button type="button" tabindex="0" class="skipToContent_3aLp">Skip to main content</button></nav><nav class="navbar navbar--fixed-top navbar--dark"><div class="navbar__inner"><div class="navbar__items"><div aria-label="Navigation bar toggle" class="navbar__toggle" role="button" tabindex="0"><svg aria-label="Menu" width="30" height="30" viewBox="0 0 30 30" role="img" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></div><a class="navbar__brand" href="/"><img src="/img/header_logo.svg" alt="React Native" class="themedImage_phiS themedImage--light_VJaY navbar__logo"><img src="/img/header_logo.svg" alt="React Native" class="themedImage_phiS themedImage--dark_1NF3 navbar__logo"><strong class="navbar__title">React Native</strong></a><div class="navbar__item dropdown dropdown--hoverable dropdown--left"><a class="navbar__item navbar__link" href="/docs/getting-started">0.63</a><ul class="dropdown__menu"><li><a class="dropdown__link" href="/docs/next/getting-started">Next</a></li><li><a aria-current="page" class="dropdown__link dropdown__link--active" href="/docs/listview">0.63</a></li><li><a class="dropdown__link" href="/docs/0.62/listview">0.62</a></li><li><a class="dropdown__link" href="/docs/0.61/listview">0.61</a></li><li><a class="dropdown__link" href="/docs/0.60/listview">0.60</a></li><li><a class="dropdown__link" href="/versions">All versions</a></li></ul></div></div><div class="navbar__items navbar__items--right"><a class="navbar__item navbar__link" href="/docs/getting-started">Docs</a><a class="navbar__item navbar__link" href="/docs/components-and-apis">Components</a><a class="navbar__item navbar__link" href="/docs/accessibilityinfo">API</a><a class="navbar__item navbar__link" href="/help">Community</a><a class="navbar__item navbar__link" href="/blog">Blog</a><a href="https://github.com/facebook/react-native" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link navbar-github-link" aria-label="GitHub repository"></a><div class="react-toggle react-toggle--disabled displayOnlyInLargeViewport_Bh6k"><div class="react-toggle-track"><div class="react-toggle-track-check"><span class="toggle_1UDy">🌜</span></div><div class="react-toggle-track-x"><span class="toggle_1UDy">🌞</span></div></div><div class="react-toggle-thumb"></div><input type="checkbox" disabled="" aria-label="Dark mode toggle" class="react-toggle-screenreader-only"></div><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span></button></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div><div class="navbar-sidebar"><div class="navbar-sidebar__brand"><a class="navbar__brand" href="/"><img src="/img/header_logo.svg" alt="React Native" class="themedImage_phiS themedImage--light_VJaY navbar__logo"><img src="/img/header_logo.svg" alt="React Native" class="themedImage_phiS themedImage--dark_1NF3 navbar__logo"><strong class="navbar__title">React Native</strong></a></div><div class="navbar-sidebar__items"><div class="menu"><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" href="/docs/getting-started">Docs</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/components-and-apis">Components</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/accessibilityinfo">API</a></li><li class="menu__list-item"><a class="menu__link" href="/help">Community</a></li><li class="menu__list-item"><a class="menu__link" href="/blog">Blog</a></li><li class="menu__list-item"><a role="button" class="menu__link menu__link--sublist">Versions</a><ul class="menu__list"><li class="menu__list-item"><a class="menu__link" href="/docs/next/getting-started">Next</a></li><li class="menu__list-item"><a aria-current="page" class="menu__link menu__link--active" href="/docs/listview">0.63</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/0.62/listview">0.62</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/0.61/listview">0.61</a></li><li class="menu__list-item"><a class="menu__link" href="/docs/0.60/listview">0.60</a></li><li class="menu__list-item"><a class="menu__link" href="/versions">All versions</a></li></ul></li><li class="menu__list-item"><a href="https://github.com/facebook/react-native" target="_blank" rel="noopener noreferrer" class="menu__link navbar-github-link" aria-label="GitHub repository"></a></li></ul></div></div></div></nav><div class="main-wrapper"><div class="docPage_1mVJ"><main class="docMainContainer_1zi2"><div class="container padding-vert--lg docItemWrapper_1hMI"><div class="row"><div class="col docItemCol_2AGf"><div class="docItemContainer_1tAC"><article><header><h1 class="docTitle_cWlf">ListView</h1></header><div class="markdown"><p>DEPRECATED - use one of the new list components, such as <a href="/docs/flatlist"><code>FlatList</code></a> or <a href="/docs/sectionlist"><code>SectionList</code></a> for bounded memory use, fewer bugs, better performance, an easier to use API, and more features. Check out this <a href="/blog/2017/03/13/better-list-views">blog post</a> for more details.</p><p>ListView - A core component designed for efficient display of vertically scrolling lists of changing data. The minimal API is to create a <a href="/docs/listviewdatasource"><code>ListView.DataSource</code></a>, populate it with a flat array of data blobs, and instantiate a <code>ListView</code> component with that data source and a <code>renderRow</code> callback which takes a blob from the data array and returns a renderable component.</p><p>Minimal example:</p><div class="mdxCodeBlock_1daz"><div class="codeBlockContent_2es_"><div tabindex="0" class="prism-code language-jsx codeBlock_27aQ thin-scrollbar"><div class="codeBlockLines_2rCb" style="color:#FFFFFF;background:#282C34"><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token keyword" style="color:#c5a5c5">class</span><span class="token plain"> </span><span class="token class-name" style="color:#fac863">MyComponent</span><span class="token plain"> </span><span class="token keyword" style="color:#c5a5c5">extends</span><span class="token plain"> </span><span class="token class-name" style="color:#fac863">Component</span><span class="token plain"> </span><span class="token punctuation" style="color:#657b83">{</span><span class="token plain"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> </span><span class="token function" style="color:#79b6f2">constructor</span><span class="token punctuation" style="color:#657b83">(</span><span class="token punctuation" style="color:#657b83">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#657b83">{</span><span class="token plain"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> </span><span class="token keyword" style="color:#c5a5c5">super</span><span class="token punctuation" style="color:#657b83">(</span><span class="token punctuation" style="color:#657b83">)</span><span class="token punctuation" style="color:#657b83">;</span><span class="token plain"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> </span><span class="token keyword" style="color:#c5a5c5">const</span><span class="token plain"> ds </span><span class="token operator" style="color:#fc929e">=</span><span class="token plain"> </span><span class="token keyword" style="color:#c5a5c5">new</span><span class="token plain"> </span><span class="token class-name" style="color:#fac863">ListView</span><span class="token class-name punctuation" style="color:#657b83">.</span><span class="token class-name" style="color:#fac863">DataSource</span><span class="token punctuation" style="color:#657b83">(</span><span class="token punctuation" style="color:#657b83">{</span><span class="token plain"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> </span><span class="token function-variable function" style="color:#79b6f2">rowHasChanged</span><span class="token operator" style="color:#fc929e">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#657b83">(</span><span class="token parameter">r1</span><span class="token parameter punctuation" style="color:#657b83">,</span><span class="token parameter"> r2</span><span class="token punctuation" style="color:#657b83">)</span><span class="token plain"> </span><span class="token operator" style="color:#fc929e">=></span><span class="token plain"> r1 </span><span class="token operator" style="color:#fc929e">!==</span><span class="token plain"> r2</span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> </span><span class="token punctuation" style="color:#657b83">}</span><span class="token punctuation" style="color:#657b83">)</span><span class="token punctuation" style="color:#657b83">;</span><span class="token plain"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> </span><span class="token keyword" style="color:#c5a5c5">this</span><span class="token punctuation" style="color:#657b83">.</span><span class="token plain">state </span><span class="token operator" style="color:#fc929e">=</span><span class="token plain"> </span><span class="token punctuation" style="color:#657b83">{</span><span class="token plain"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> dataSource</span><span class="token operator" style="color:#fc929e">:</span><span class="token plain"> ds</span><span class="token punctuation" style="color:#657b83">.</span><span class="token function" style="color:#79b6f2">cloneWithRows</span><span class="token punctuation" style="color:#657b83">(</span><span class="token punctuation" style="color:#657b83">[</span><span class="token string" style="color:#8dc891">'row 1'</span><span class="token punctuation" style="color:#657b83">,</span><span class="token plain"> </span><span class="token string" style="color:#8dc891">'row 2'</span><span class="token punctuation" style="color:#657b83">]</span><span class="token punctuation" style="color:#657b83">)</span><span class="token plain"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> </span><span class="token punctuation" style="color:#657b83">}</span><span class="token punctuation" style="color:#657b83">;</span><span class="token plain"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> </span><span class="token punctuation" style="color:#657b83">}</span><span class="token plain"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain" style="display:inline-block">
|
|
</span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> </span><span class="token function" style="color:#79b6f2">render</span><span class="token punctuation" style="color:#657b83">(</span><span class="token punctuation" style="color:#657b83">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#657b83">{</span><span class="token plain"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> </span><span class="token keyword" style="color:#c5a5c5">return</span><span class="token plain"> </span><span class="token punctuation" style="color:#657b83">(</span><span class="token plain"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> </span><span class="token tag punctuation" style="color:#657b83"><</span><span class="token tag class-name" style="color:#fac863">ListView</span><span class="token tag" style="color:#fc929e"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token tag" style="color:#fc929e"> </span><span class="token tag attr-name" style="color:#c5a5c5">dataSource</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:#657b83">=</span><span class="token tag script language-javascript punctuation" style="color:#657b83">{</span><span class="token tag script language-javascript keyword" style="color:#c5a5c5">this</span><span class="token tag script language-javascript punctuation" style="color:#657b83">.</span><span class="token tag script language-javascript" style="color:#fc929e">state</span><span class="token tag script language-javascript punctuation" style="color:#657b83">.</span><span class="token tag script language-javascript" style="color:#fc929e">dataSource</span><span class="token tag script language-javascript punctuation" style="color:#657b83">}</span><span class="token tag" style="color:#fc929e"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token tag" style="color:#fc929e"> </span><span class="token tag attr-name" style="color:#c5a5c5">renderRow</span><span class="token tag script language-javascript script-punctuation punctuation" style="color:#657b83">=</span><span class="token tag script language-javascript punctuation" style="color:#657b83">{</span><span class="token tag script language-javascript punctuation" style="color:#657b83">(</span><span class="token tag script language-javascript parameter" style="color:#fc929e">rowData</span><span class="token tag script language-javascript punctuation" style="color:#657b83">)</span><span class="token tag script language-javascript" style="color:#fc929e"> </span><span class="token tag script language-javascript operator" style="color:#fc929e">=></span><span class="token tag script language-javascript" style="color:#fc929e"> </span><span class="token tag script language-javascript tag punctuation" style="color:#657b83"><</span><span class="token tag script language-javascript tag class-name" style="color:#fac863">Text</span><span class="token tag script language-javascript tag punctuation" style="color:#657b83">></span><span class="token tag script language-javascript punctuation" style="color:#657b83">{</span><span class="token tag script language-javascript" style="color:#fc929e">rowData</span><span class="token tag script language-javascript punctuation" style="color:#657b83">}</span><span class="token tag script language-javascript tag punctuation" style="color:#657b83"></</span><span class="token tag script language-javascript tag class-name" style="color:#fac863">Text</span><span class="token tag script language-javascript tag punctuation" style="color:#657b83">></span><span class="token tag script language-javascript punctuation" style="color:#657b83">}</span><span class="token tag" style="color:#fc929e"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token tag" style="color:#fc929e"> </span><span class="token tag punctuation" style="color:#657b83">/></span><span class="token plain"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> </span><span class="token punctuation" style="color:#657b83">)</span><span class="token punctuation" style="color:#657b83">;</span><span class="token plain"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"> </span><span class="token punctuation" style="color:#657b83">}</span><span class="token plain"></span></div><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token plain"></span><span class="token punctuation" style="color:#657b83">}</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_2bml">Copy</button></div></div><p>ListView also supports more advanced features, including sections with sticky section headers, header and footer support, callbacks on reaching the end of the available data (<code>onEndReached</code>) and on the set of rows that are visible in the device viewport change (<code>onChangeVisibleRows</code>), and several performance optimizations.</p><p>There are a few performance operations designed to make ListView scroll smoothly while dynamically loading potentially very large (or conceptually infinite) data sets:</p><ul><li><p>Only re-render changed rows - the rowHasChanged function provided to the data source tells the ListView if it needs to re-render a row because the source data has changed - see ListViewDataSource for more details.</p></li><li><p>Rate-limited row rendering - By default, only one row is rendered per event-loop (customizable with the <code>pageSize</code> prop). This breaks up the work into smaller chunks to reduce the chance of dropping frames while rendering rows.</p></li></ul><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="props"></a>Props<a class="hash-link" href="#props" title="Direct link to heading">#</a></h3><ul><li><a href="/docs/scrollview#props">ScrollView props...</a></li></ul><ul><li><a href="/docs/listview#datasource"><code>dataSource</code></a></li><li><a href="/docs/listview#initiallistsize"><code>initialListSize</code></a></li><li><a href="/docs/listview#onendreachedthreshold"><code>onEndReachedThreshold</code></a></li><li><a href="/docs/listview#pagesize"><code>pageSize</code></a></li><li><a href="/docs/listview#renderrow"><code>renderRow</code></a></li><li><a href="/docs/listview#renderscrollcomponent"><code>renderScrollComponent</code></a></li><li><a href="/docs/listview#scrollrenderaheaddistance"><code>scrollRenderAheadDistance</code></a></li><li><a href="/docs/listview#stickyheaderindices"><code>stickyHeaderIndices</code></a></li><li><a href="/docs/listview#enableemptysections"><code>enableEmptySections</code></a></li><li><a href="/docs/listview#renderheader"><code>renderHeader</code></a></li><li><a href="/docs/listview#onendreached"><code>onEndReached</code></a></li><li><a href="/docs/listview#stickysectionheadersenabled"><code>stickySectionHeadersEnabled</code></a></li><li><a href="/docs/listview#rendersectionheader"><code>renderSectionHeader</code></a></li><li><a href="/docs/listview#renderseparator"><code>renderSeparator</code></a></li><li><a href="/docs/listview#onchangevisiblerows"><code>onChangeVisibleRows</code></a></li><li><a href="/docs/listview#removeclippedsubviews"><code>removeClippedSubviews</code></a></li><li><a href="/docs/listview#renderfooter"><code>renderFooter</code></a></li></ul><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="methods"></a>Methods<a class="hash-link" href="#methods" title="Direct link to heading">#</a></h3><ul><li><a href="/docs/listview#getmetrics"><code>getMetrics</code></a></li><li><a href="/docs/listview#scrollto"><code>scrollTo</code></a></li><li><a href="/docs/listview#scrolltoend"><code>scrollToEnd</code></a></li><li><a href="/docs/listview#flashscrollindicators"><code>flashScrollIndicators</code></a></li></ul><hr><h1><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="reference"></a>Reference<a class="hash-link" href="#reference" title="Direct link to heading">#</a></h1><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="props-1"></a>Props<a class="hash-link" href="#props-1" title="Direct link to heading">#</a></h2><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="datasource"></a><code>dataSource</code><a class="hash-link" href="#datasource" title="Direct link to heading">#</a></h3><p>An instance of <a href="/docs/listviewdatasource">ListView.DataSource</a> to use</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>ListViewDataSource</td><td>Yes</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="initiallistsize"></a><code>initialListSize</code><a class="hash-link" href="#initiallistsize" title="Direct link to heading">#</a></h3><p>How many rows to render on initial component mount. Use this to make it so that the first screen worth of data appears at one time instead of over the course of multiple frames.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>number</td><td>Yes</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="onendreachedthreshold"></a><code>onEndReachedThreshold</code><a class="hash-link" href="#onendreachedthreshold" title="Direct link to heading">#</a></h3><p>Threshold in pixels (virtual, not physical) for calling onEndReached.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>number</td><td>Yes</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="pagesize"></a><code>pageSize</code><a class="hash-link" href="#pagesize" title="Direct link to heading">#</a></h3><p>Number of rows to render per event loop. Note: if your 'rows' are actually cells, i.e. they don't span the full width of your view (as in the ListViewGridLayoutExample), you should set the pageSize to be a multiple of the number of cells per row, otherwise you're likely to see gaps at the edge of the ListView as new pages are loaded.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>number</td><td>Yes</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="renderrow"></a><code>renderRow</code><a class="hash-link" href="#renderrow" title="Direct link to heading">#</a></h3><p>(rowData, sectionID, rowID, highlightRow) => renderable</p><p>Takes a data entry from the data source and its ids and should return a renderable component to be rendered as the row. By default the data is exactly what was put into the data source, but it's also possible to provide custom extractors. ListView can be notified when a row is being highlighted by calling <code>highlightRow(sectionID, rowID)</code>. This sets a boolean value of adjacentRowHighlighted in renderSeparator, allowing you to control the separators above and below the highlighted row. The highlighted state of a row can be reset by calling highlightRow(null).</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>function</td><td>Yes</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="renderscrollcomponent"></a><code>renderScrollComponent</code><a class="hash-link" href="#renderscrollcomponent" title="Direct link to heading">#</a></h3><p>(props) => renderable</p><p>A function that returns the scrollable component in which the list rows are rendered. Defaults to returning a ScrollView with the given props.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>function</td><td>Yes</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="scrollrenderaheaddistance"></a><code>scrollRenderAheadDistance</code><a class="hash-link" href="#scrollrenderaheaddistance" title="Direct link to heading">#</a></h3><p>How early to start rendering rows before they come on screen, in pixels.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>number</td><td>Yes</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="stickyheaderindices"></a><code>stickyHeaderIndices</code><a class="hash-link" href="#stickyheaderindices" title="Direct link to heading">#</a></h3><p>An array of child indices determining which children get docked to the top of the screen when scrolling. For example, passing <code>stickyHeaderIndices={[0]}</code> will cause the first child to be fixed to the top of the scroll view. This property is not supported in conjunction with <code>horizontal={true}</code>.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>array of number</td><td>Yes</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="enableemptysections"></a><code>enableEmptySections</code><a class="hash-link" href="#enableemptysections" title="Direct link to heading">#</a></h3><p>Flag indicating whether empty section headers should be rendered. In the future release empty section headers will be rendered by default, and the flag will be deprecated. If empty sections are not desired to be rendered their indices should be excluded from sectionID object.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>bool</td><td>No</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="renderheader"></a><code>renderHeader</code><a class="hash-link" href="#renderheader" title="Direct link to heading">#</a></h3><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>function</td><td>No</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="onendreached"></a><code>onEndReached</code><a class="hash-link" href="#onendreached" title="Direct link to heading">#</a></h3><p>Called when all rows have been rendered and the list has been scrolled to within onEndReachedThreshold of the bottom. The native scroll event is provided.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>function</td><td>No</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="stickysectionheadersenabled"></a><code>stickySectionHeadersEnabled</code><a class="hash-link" href="#stickysectionheadersenabled" title="Direct link to heading">#</a></h3><p>Makes the sections headers sticky. The sticky behavior means that it will scroll with the content at the top of the section until it reaches the top of the screen, at which point it will stick to the top until it is pushed off the screen by the next section header. This property is not supported in conjunction with <code>horizontal={true}</code>. Only enabled by default on iOS because of typical platform standards.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>bool</td><td>No</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="rendersectionheader"></a><code>renderSectionHeader</code><a class="hash-link" href="#rendersectionheader" title="Direct link to heading">#</a></h3><p>(sectionData, sectionID) => renderable</p><p>If provided, a header is rendered for this section.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>function</td><td>No</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="renderseparator"></a><code>renderSeparator</code><a class="hash-link" href="#renderseparator" title="Direct link to heading">#</a></h3><p>(sectionID, rowID, adjacentRowHighlighted) => renderable</p><p>If provided, a renderable component to be rendered as the separator below each row but not the last row if there is a section header below. Take a sectionID and rowID of the row above and whether its adjacent row is highlighted.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>function</td><td>No</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="onchangevisiblerows"></a><code>onChangeVisibleRows</code><a class="hash-link" href="#onchangevisiblerows" title="Direct link to heading">#</a></h3><p>(visibleRows, changedRows) => void</p><p>Called when the set of visible rows changes. <code>visibleRows</code> maps { sectionID: { rowID: true }} for all the visible rows, and <code>changedRows</code> maps { sectionID: { rowID: true | false }} for the rows that have changed their visibility, with true indicating visible, and false indicating the view has moved out of view.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>function</td><td>No</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="removeclippedsubviews"></a><code>removeClippedSubviews</code><a class="hash-link" href="#removeclippedsubviews" title="Direct link to heading">#</a></h3><p>A performance optimization for improving scroll perf of large lists, used in conjunction with overflow: 'hidden' on the row containers. This is enabled by default.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>bool</td><td>No</td></tr></tbody></table><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="renderfooter"></a><code>renderFooter</code><a class="hash-link" href="#renderfooter" title="Direct link to heading">#</a></h3><p>() => renderable</p><p>The header and footer are always rendered (if these props are provided) on every render pass. If they are expensive to re-render, wrap them in StaticContainer or other mechanism as appropriate. Footer is always at the bottom of the list, and header at the top, on every render pass. In a horizontal ListView, the header is rendered on the left and the footer on the right.</p><table><thead><tr><th>Type</th><th>Required</th></tr></thead><tbody><tr><td>function</td><td>No</td></tr></tbody></table><h2><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="methods-1"></a>Methods<a class="hash-link" href="#methods-1" title="Direct link to heading">#</a></h2><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="getmetrics"></a><code>getMetrics()</code><a class="hash-link" href="#getmetrics" title="Direct link to heading">#</a></h3><div class="mdxCodeBlock_1daz"><div class="codeBlockContent_2es_"><div tabindex="0" class="prism-code language-jsx codeBlock_27aQ thin-scrollbar"><div class="codeBlockLines_2rCb" style="color:#FFFFFF;background:#282C34"><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token function" style="color:#79b6f2">getMetrics</span><span class="token punctuation" style="color:#657b83">(</span><span class="token punctuation" style="color:#657b83">)</span><span class="token punctuation" style="color:#657b83">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_2bml">Copy</button></div></div><p>Exports some data, e.g. for perf investigations or analytics.</p><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="scrollto"></a><code>scrollTo()</code><a class="hash-link" href="#scrollto" title="Direct link to heading">#</a></h3><div class="mdxCodeBlock_1daz"><div class="codeBlockContent_2es_"><div tabindex="0" class="prism-code language-jsx codeBlock_27aQ thin-scrollbar"><div class="codeBlockLines_2rCb" style="color:#FFFFFF;background:#282C34"><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token function" style="color:#79b6f2">scrollTo</span><span class="token punctuation" style="color:#657b83">(</span><span class="token punctuation" style="color:#657b83">(</span><span class="token operator" style="color:#fc929e">...</span><span class="token plain">args</span><span class="token operator" style="color:#fc929e">:</span><span class="token plain"> Array</span><span class="token punctuation" style="color:#657b83">)</span><span class="token punctuation" style="color:#657b83">)</span><span class="token punctuation" style="color:#657b83">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_2bml">Copy</button></div></div><p>Scrolls to a given x, y offset, either immediately or with a smooth animation.</p><p>See <code>ScrollView#scrollTo</code>.</p><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="scrolltoend"></a><code>scrollToEnd()</code><a class="hash-link" href="#scrolltoend" title="Direct link to heading">#</a></h3><div class="mdxCodeBlock_1daz"><div class="codeBlockContent_2es_"><div tabindex="0" class="prism-code language-jsx codeBlock_27aQ thin-scrollbar"><div class="codeBlockLines_2rCb" style="color:#FFFFFF;background:#282C34"><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token function" style="color:#79b6f2">scrollToEnd</span><span class="token punctuation" style="color:#657b83">(</span><span class="token punctuation" style="color:#657b83">(</span><span class="token punctuation" style="color:#657b83">[</span><span class="token plain">options</span><span class="token punctuation" style="color:#657b83">]</span><span class="token operator" style="color:#fc929e">:</span><span class="token plain"> object</span><span class="token punctuation" style="color:#657b83">)</span><span class="token punctuation" style="color:#657b83">)</span><span class="token punctuation" style="color:#657b83">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_2bml">Copy</button></div></div><p>If this is a vertical ListView scrolls to the bottom. If this is a horizontal ListView scrolls to the right.</p><p>Use <code>scrollToEnd({animated: true})</code> for smooth animated scrolling, <code>scrollToEnd({animated: false})</code> for immediate scrolling. If no options are passed, <code>animated</code> defaults to true.</p><p>See <code>ScrollView#scrollToEnd</code>.</p><hr><h3><a aria-hidden="true" tabindex="-1" class="anchor enhancedAnchor_E4oP" id="flashscrollindicators"></a><code>flashScrollIndicators()</code><a class="hash-link" href="#flashscrollindicators" title="Direct link to heading">#</a></h3><div class="mdxCodeBlock_1daz"><div class="codeBlockContent_2es_"><div tabindex="0" class="prism-code language-jsx codeBlock_27aQ thin-scrollbar"><div class="codeBlockLines_2rCb" style="color:#FFFFFF;background:#282C34"><div class="token-line" style="color:#FFFFFF;background:#282C34"><span class="token function" style="color:#79b6f2">flashScrollIndicators</span><span class="token punctuation" style="color:#657b83">(</span><span class="token punctuation" style="color:#657b83">)</span><span class="token punctuation" style="color:#657b83">;</span></div></div></div><button type="button" aria-label="Copy code to clipboard" class="copyButton_2bml">Copy</button></div></div><p>Displays the scroll indicators momentarily.</p></div></article><div class="docMetadata margin-vert--xl"><div class="row"><div class="col"><a href="https://github.com/facebook/react-native-website/blob/master/website/versioned_docs/version-0.63/listview.md" target="_blank" rel="noreferrer noopener"><svg fill="currentColor" height="1.2em" width="1.2em" preserveAspectRatio="xMidYMid meet" role="img" viewBox="0 0 40 40" class="iconEdit_2Hwv"><g><path d="m34.5 11.7l-3 3.1-6.3-6.3 3.1-3q0.5-0.5 1.2-0.5t1.1 0.5l3.9 3.9q0.5 0.4 0.5 1.1t-0.5 1.2z m-29.5 17.1l18.4-18.5 6.3 6.3-18.4 18.4h-6.3v-6.2z"></path></g></svg>Edit this page</a></div><div class="col text--right"><em><small class="docMetadata-updated">Last updated on <time datetime="2020-12-07T11:00:02.000Z" class="docLastUpdatedAt_1gIo">12/7/2020</time></small></em></div></div></div><div class="margin-vert--lg"><nav class="pagination-nav" aria-label="Blog list page navigation"><div class="pagination-nav__item"></div><div class="pagination-nav__item pagination-nav__item--next"></div></nav></div></div></div><div class="col col--3"><div class="tableOfContents_1zTD thin-scrollbar"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#props" class="table-of-contents__link">Props</a></li><li><a href="#methods" class="table-of-contents__link">Methods</a></li><li><a href="#props-1" class="table-of-contents__link">Props</a><ul><li><a href="#datasource" class="table-of-contents__link"><code>dataSource</code></a></li><li><a href="#initiallistsize" class="table-of-contents__link"><code>initialListSize</code></a></li><li><a href="#onendreachedthreshold" class="table-of-contents__link"><code>onEndReachedThreshold</code></a></li><li><a href="#pagesize" class="table-of-contents__link"><code>pageSize</code></a></li><li><a href="#renderrow" class="table-of-contents__link"><code>renderRow</code></a></li><li><a href="#renderscrollcomponent" class="table-of-contents__link"><code>renderScrollComponent</code></a></li><li><a href="#scrollrenderaheaddistance" class="table-of-contents__link"><code>scrollRenderAheadDistance</code></a></li><li><a href="#stickyheaderindices" class="table-of-contents__link"><code>stickyHeaderIndices</code></a></li><li><a href="#enableemptysections" class="table-of-contents__link"><code>enableEmptySections</code></a></li><li><a href="#renderheader" class="table-of-contents__link"><code>renderHeader</code></a></li><li><a href="#onendreached" class="table-of-contents__link"><code>onEndReached</code></a></li><li><a href="#stickysectionheadersenabled" class="table-of-contents__link"><code>stickySectionHeadersEnabled</code></a></li><li><a href="#rendersectionheader" class="table-of-contents__link"><code>renderSectionHeader</code></a></li><li><a href="#renderseparator" class="table-of-contents__link"><code>renderSeparator</code></a></li><li><a href="#onchangevisiblerows" class="table-of-contents__link"><code>onChangeVisibleRows</code></a></li><li><a href="#removeclippedsubviews" class="table-of-contents__link"><code>removeClippedSubviews</code></a></li><li><a href="#renderfooter" class="table-of-contents__link"><code>renderFooter</code></a></li></ul></li><li><a href="#methods-1" class="table-of-contents__link">Methods</a><ul><li><a href="#getmetrics" class="table-of-contents__link"><code>getMetrics()</code></a></li><li><a href="#scrollto" class="table-of-contents__link"><code>scrollTo()</code></a></li><li><a href="#scrolltoend" class="table-of-contents__link"><code>scrollToEnd()</code></a></li><li><a href="#flashscrollindicators" class="table-of-contents__link"><code>flashScrollIndicators()</code></a></li></ul></li></ul></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container"><div class="row footer__links"><div class="col footer__col"><h4 class="footer__title">Docs</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/docs/getting-started">Getting Started</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/tutorial">Tutorial</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/components-and-apis">Components and APIs</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/more-resources">More Resources</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Community</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/help">The React Native Community</a></li><li class="footer__item"><a class="footer__link-item" href="/showcase">Who's using React Native?</a></li><li class="footer__item"><a href="https://stackoverflow.com/questions/tagged/react-native" target="_blank" rel="noopener noreferrer" class="footer__link-item">Ask Questions on Stack Overflow</a></li><li class="footer__item"><a href="https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md" target="_blank" rel="noopener noreferrer" class="footer__link-item">Contributor Guide</a></li><li class="footer__item"><a href="https://dev.to/t/reactnative" target="_blank" rel="noopener noreferrer" class="footer__link-item">DEV Community</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">Find us</h4><ul class="footer__items"><li class="footer__item"><a class="footer__link-item" href="/blog">Blog</a></li><li class="footer__item"><a href="https://twitter.com/reactnative" target="_blank" rel="noopener noreferrer" class="footer__link-item">Twitter</a></li><li class="footer__item"><a href="https://github.com/facebook/react-native" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub</a></li></ul></div><div class="col footer__col"><h4 class="footer__title">More</h4><ul class="footer__items"><li class="footer__item"><a href="https://reactjs.org/" target="_blank" rel="noopener noreferrer" class="footer__link-item">React</a></li><li class="footer__item"><a href="https://opensource.facebook.com/legal/privacy" target="_blank" rel="noopener noreferrer" class="footer__link-item">Privacy Policy</a></li><li class="footer__item"><a href="https://opensource.facebook.com/legal/terms" target="_blank" rel="noopener noreferrer" class="footer__link-item">Terms of Service</a></li></ul></div></div><div class="footer__bottom text--center"><div class="margin-bottom--sm"><a href="https://opensource.facebook.com" target="_blank" rel="noopener noreferrer" class="footerLogoLink_3cAK"><img class="footer__logo" alt="Facebook Open Source Logo" src="/img/oss_logo.png"></a></div><div class="footer__copyright">Copyright © 2021 Facebook, Inc.</div></div></div></footer></div>
|
|
<script src="/styles.69e4b76b.js"></script>
|
|
<script src="/runtime~main.289e81aa.js"></script>
|
|
<script src="/main.b86b035f.js"></script>
|
|
<script src="/1.de054a96.js"></script>
|
|
<script src="/2.d28ff3f3.js"></script>
|
|
<script src="/929.d078dd2b.js"></script>
|
|
<script src="/ee5b3385.efdac311.js"></script>
|
|
<script src="/17896441.a6fe599d.js"></script>
|
|
<script src="/ffc0709f.07ddfbec.js"></script>
|
|
</body>
|
|
</html> |