|
| 1 | +import React, { useState } from "react"; |
| 2 | +import { |
| 3 | + KeyboardAvoidingView, |
| 4 | + SafeAreaView, |
| 5 | + StyleSheet, |
| 6 | + View, |
| 7 | +} from "react-native"; |
| 8 | +import BigList from "react-native-big-list"; |
| 9 | +import { Appbar, List, Subheading, TextInput } from "react-native-paper"; |
| 10 | +import { StatusBar } from "expo-status-bar"; |
| 11 | + |
| 12 | +import sections from "../data/sections.json"; |
| 13 | +import Block from "./components/Block"; |
| 14 | + |
| 15 | +export default function SectionColumnsTest() { |
| 16 | + const [numberColumns, setNumberColumns] = useState(2); |
| 17 | + const renderItem = ({ item }) => { |
| 18 | + return ( |
| 19 | + <List.Item |
| 20 | + title={item.title} |
| 21 | + description={item.description} |
| 22 | + style={styles.container} |
| 23 | + left={(props) => <List.Icon {...props} icon="account" />} |
| 24 | + /> |
| 25 | + ); |
| 26 | + }; |
| 27 | + const renderEmpty = () => <List.Item title="No items" />; |
| 28 | + const renderHeader = () => ( |
| 29 | + <View> |
| 30 | + <TextInput |
| 31 | + label="Number of columns (max 5)" |
| 32 | + value={String(numberColumns)} |
| 33 | + type="numeric" |
| 34 | + keyboardType="numeric" |
| 35 | + onChangeText={(value) => { |
| 36 | + const num = parseInt(value, 10) || ""; |
| 37 | + setNumberColumns(num); |
| 38 | + }} |
| 39 | + /> |
| 40 | + </View> |
| 41 | + ); |
| 42 | + const renderFooter = () => ( |
| 43 | + <Block> |
| 44 | + <Subheading>No more items available...</Subheading> |
| 45 | + </Block> |
| 46 | + ); |
| 47 | + const renderSectionHeader = (section, sectionData) => ( |
| 48 | + <Appbar style={styles.header}> |
| 49 | + <Appbar.Content |
| 50 | + style={styles.headerContent} |
| 51 | + title={"Section " + (section + 1)} |
| 52 | + subtitle={`Below are listed ${sectionData?.length || 0} section items`} |
| 53 | + /> |
| 54 | + </Appbar> |
| 55 | + ); |
| 56 | + const renderSectionFooter = (section, sectionData) => ( |
| 57 | + <Block> |
| 58 | + <Subheading> |
| 59 | + Footer Section {section} ({sectionData?.length || 0} items) |
| 60 | + </Subheading> |
| 61 | + </Block> |
| 62 | + ); |
| 63 | + return ( |
| 64 | + <SafeAreaView style={styles.container}> |
| 65 | + <KeyboardAvoidingView style={styles.container}> |
| 66 | + <BigList |
| 67 | + style={styles.container} |
| 68 | + sections={sections} |
| 69 | + numColumns={Math.min( |
| 70 | + Math.max(parseInt(numberColumns, 10) || 1, 1), |
| 71 | + 5 |
| 72 | + )} |
| 73 | + // Item |
| 74 | + itemHeight={90} |
| 75 | + renderItem={renderItem} |
| 76 | + renderEmpty={renderEmpty} |
| 77 | + // Header |
| 78 | + headerHeight={90} |
| 79 | + renderHeader={renderHeader} |
| 80 | + // Footer |
| 81 | + footerHeight={100} |
| 82 | + renderFooter={renderFooter} |
| 83 | + // Section |
| 84 | + sectionHeaderHeight={75} |
| 85 | + renderSectionHeader={renderSectionHeader} |
| 86 | + // Section footer |
| 87 | + sectionFooterHeight={60} |
| 88 | + renderSectionFooter={renderSectionFooter} |
| 89 | + /> |
| 90 | + <StatusBar style="auto" /> |
| 91 | + </KeyboardAvoidingView> |
| 92 | + </SafeAreaView> |
| 93 | + ); |
| 94 | +} |
| 95 | + |
| 96 | +const styles = StyleSheet.create({ |
| 97 | + container: { |
| 98 | + flex: 1, |
| 99 | + }, |
| 100 | + header: { elevation: 0, height: 50 }, |
| 101 | + headerContent: { alignItems: "center", height: 50, justifyContent: "center" }, |
| 102 | +}); |
0 commit comments