diff --git a/docs/sectionlist.md b/docs/sectionlist.md index e87afcc9248..082de77f685 100644 --- a/docs/sectionlist.md +++ b/docs/sectionlist.md @@ -20,80 +20,172 @@ If you don't need section support and want a simpler interface, use [` ## Example -```SnackPlayer name=SectionList -import React from 'react'; +
+ +
+ + + +```SnackPlayer name=SectionList%20Example +import React from "react"; import { StyleSheet, Text, View, SafeAreaView, - SectionList, -} from 'react-native'; -import Constants from 'expo-constants'; + SectionList +} from "react-native"; +import Constants from "expo-constants"; const DATA = [ { - title: 'Main dishes', - data: ['Pizza', 'Burger', 'Risotto'], + title: "Main dishes", + data: ["Pizza", "Burger", "Risotto"] }, { - title: 'Sides', - data: ['French Fries', 'Onion Rings', 'Fried Shrimps'], + title: "Sides", + data: ["French Fries", "Onion Rings", "Fried Shrimps"] }, { - title: 'Drinks', - data: ['Water', 'Coke', 'Beer'], + title: "Drinks", + data: ["Water", "Coke", "Beer"] }, { - title: 'Desserts', - data: ['Cheese Cake', 'Ice Cream'], + title: "Desserts", + data: ["Cheese Cake", "Ice Cream"] + } +]; + +const Item = ({ title }) => ( + + {title} + +); + +const App = () => ( + + item + index} + renderItem={({ item }) => } + renderSectionHeader={({ section: { title } }) => ( + {title} + )} + /> + +); + +export default App; + +const styles = StyleSheet.create({ + container: { + flex: 1, + marginTop: Constants.statusBarHeight, + marginHorizontal: 16 + }, + item: { + backgroundColor: "#f9c2ff", + padding: 20, + marginVertical: 8 }, + header: { + fontSize: 32, + backgroundColor: "#fff" + }, + title: { + fontSize: 24 + } +}); +``` + + + +```SnackPlayer name=SectionList%20Example +import React, { Component } from "react"; +import { + StyleSheet, + Text, + View, + SafeAreaView, + SectionList +} from "react-native"; +import Constants from "expo-constants"; + +const DATA = [ + { + title: "Main dishes", + data: ["Pizza", "Burger", "Risotto"] + }, + { + title: "Sides", + data: ["French Fries", "Onion Rings", "Fried Shrimps"] + }, + { + title: "Drinks", + data: ["Water", "Coke", "Beer"] + }, + { + title: "Desserts", + data: ["Cheese Cake", "Ice Cream"] + } ]; -function Item({ title }) { - return ( - - {title} - - ); +Item = ({ title }) => ( + + {title} + +); + +class App extends Component { + render() { + return ( + + item + index} + renderItem={({ item }) => } + renderSectionHeader={({ section: { title } }) => ( + {title} + )} + /> + + ); + } } -export default function App() { - return ( - - item + index} - renderItem={({ item }) => } - renderSectionHeader={({ section: { title } }) => ( - {title} - )} - /> - - ); -} +export default App; const styles = StyleSheet.create({ container: { flex: 1, marginTop: Constants.statusBarHeight, - marginHorizontal: 16, + marginHorizontal: 16 }, item: { - backgroundColor: '#f9c2ff', + backgroundColor: "#f9c2ff", padding: 20, - marginVertical: 8, + marginVertical: 8 }, header: { fontSize: 32, - backgroundColor: '#fff' + backgroundColor: "#fff" }, title: { - fontSize: 24, - }, + fontSize: 24 + } }); +] ``` + + This is a convenience wrapper around [``](virtualizedlist.md), and thus inherits its props (as well as those of [``](scrollview.md) that aren't explicitly listed here, along with the following 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.