From f334f74761ad1ddd8f6752e19493bc9712669a22 Mon Sep 17 00:00:00 2001 From: Abraham Nnaji Date: Sat, 15 Feb 2020 11:31:51 -0600 Subject: [PATCH] Added snack example for virtualized list --- docs/virtualizedlist.md | 68 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/docs/virtualizedlist.md b/docs/virtualizedlist.md index 127dd0558d3..53654536d53 100644 --- a/docs/virtualizedlist.md +++ b/docs/virtualizedlist.md @@ -7,6 +7,74 @@ Base implementation for the more convenient [``](flatlist.md) and [` { + return { + id: Math.random().toString(12).substring(0), + title: `Item ${index+1}` + } +} + +const getItemCount = (data) => { + return 50; +} + +const Item = ({ title })=> { + return ( + + {title} + + ); +} + +const VirtualizedListExample = () => { + return ( + + } + keyExtractor={item => item.key} + getItemCount={getItemCount} + getItem={getItem} + /> + + ); +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + marginTop: Constants.statusBarHeight, + }, + item: { + backgroundColor: '#f9c2ff', + height: 150, + justifyContent: 'center', + marginVertical: 8, + marginHorizontal: 16, + padding: 20, + }, + title: { + fontSize: 32, + }, +}); + +export default VirtualizedListExample; +``` + +--- + 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.