|
| 1 | +import React from "react"; |
| 2 | +import { |
| 3 | + SafeAreaView, |
| 4 | + View, |
| 5 | + FlatList, |
| 6 | + StyleSheet, |
| 7 | + Text, |
| 8 | + StatusBar, |
| 9 | +} from "react-native"; |
| 10 | + |
| 11 | +const DATA = [ |
| 12 | + { |
| 13 | + id: "bd7acbea-c1b1-46c2-aed5-3ad53abb28ba", |
| 14 | + title: "First Item", |
| 15 | + }, |
| 16 | + { |
| 17 | + id: "3ac68afc-c605-48d3-a4f8-fbd91aa97f63", |
| 18 | + title: "Second Item", |
| 19 | + }, |
| 20 | + { |
| 21 | + id: "58694a0f-3da1-471f-bd96-145571e29d72", |
| 22 | + title: "Third Item", |
| 23 | + }, |
| 24 | + { |
| 25 | + id: "bd7acbea-c1b1-46c2-aed5-3ad53abb8bbb", |
| 26 | + title: "Fourth Item", |
| 27 | + }, |
| 28 | + { |
| 29 | + id: "3ac68afc-c605-48d3-a4f8-fbd91aa97676", |
| 30 | + title: "Fifth Item", |
| 31 | + }, |
| 32 | + { |
| 33 | + id: "58694a0f-3da1-471f-bd96-145571e27234", |
| 34 | + title: "Sixth Item", |
| 35 | + }, |
| 36 | + { |
| 37 | + id: "58694a0f-3da1-471f-bd96-145571e29234", |
| 38 | + title: "Seven Item", |
| 39 | + }, |
| 40 | + { |
| 41 | + id: "58694a0f-3da1-471f-bd96-145571429234", |
| 42 | + title: "Eight Item", |
| 43 | + }, |
| 44 | + { |
| 45 | + id: "58694a0f-3da1-471f-bd96-115571429234", |
| 46 | + title: "Nine Item", |
| 47 | + }, |
| 48 | + { |
| 49 | + id: "58694a0f-3da1-471f-bd96-1155h1429234", |
| 50 | + title: "Ten Item", |
| 51 | + }, |
| 52 | +]; |
| 53 | + |
| 54 | +const Item = ({ title }) => ( |
| 55 | + <View style={styles.item}> |
| 56 | + <Text style={styles.title}>{title}</Text> |
| 57 | + </View> |
| 58 | +); |
| 59 | + |
| 60 | +const renderItem = ({ item }) => <Item title={item.title} />; |
| 61 | + |
| 62 | +const renderFlatList = ({ item }) => ( |
| 63 | + <View> |
| 64 | + <Text>Flatlist {item}</Text> |
| 65 | + <FlatList renderItem={renderItem} horizontal data={DATA} /> |
| 66 | + </View> |
| 67 | +); |
| 68 | + |
| 69 | +const FlatListNested = () => { |
| 70 | + return ( |
| 71 | + <SafeAreaView style={styles.container}> |
| 72 | + <FlatList |
| 73 | + data={[1, 2, 3]} |
| 74 | + renderItem={renderFlatList} |
| 75 | + keyExtractor={(item) => item.toString()} |
| 76 | + /> |
| 77 | + </SafeAreaView> |
| 78 | + ); |
| 79 | +}; |
| 80 | + |
| 81 | +const styles = StyleSheet.create({ |
| 82 | + container: { |
| 83 | + flex: 1, |
| 84 | + marginTop: StatusBar.currentHeight || 0, |
| 85 | + }, |
| 86 | + item: { |
| 87 | + backgroundColor: "#f9c2ff", |
| 88 | + padding: 20, |
| 89 | + marginVertical: 8, |
| 90 | + marginHorizontal: 16, |
| 91 | + }, |
| 92 | + title: { |
| 93 | + fontSize: 16, |
| 94 | + }, |
| 95 | +}); |
| 96 | + |
| 97 | +exports.title = "FlatList Nested"; |
| 98 | +exports.testTitle = "Test accessibility announcement in nested flatlist"; |
| 99 | +exports.category = "ListView"; |
| 100 | +exports.documentationURL = "https://reactnative.dev/docs/flatlist"; |
| 101 | +exports.description = "Nested flatlist example"; |
| 102 | +exports.examples = [ |
| 103 | + { |
| 104 | + title: "FlatList Nested example", |
| 105 | + render: function (): React.Element<typeof FlatListNested> { |
| 106 | + return <FlatListNested />; |
| 107 | + }, |
| 108 | + }, |
| 109 | +]; |
0 commit comments