Skip to content

Commit 7b09d85

Browse files
Merge pull request #381 from marcocesarato/copilot/fix-numcolumns-in-section-list
Fix numColumns not working in sections list
2 parents 73bffa9 + e73a85c commit 7b09d85

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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+
});

lib/BigList.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ class BigList extends PureComponent {
10171017
sections,
10181018
initialScrollIndex,
10191019
columnWrapperStyle,
1020+
numColumns,
10201021
renderHeader,
10211022
renderFooter,
10221023
renderSectionHeader,
@@ -1098,6 +1099,12 @@ class BigList extends PureComponent {
10981099
) : null,
10991100
contentContainerStyle: {
11001101
maxWidth: "100%",
1102+
...(numColumns > 1 && !horizontal
1103+
? {
1104+
flexDirection: "row",
1105+
flexWrap: "wrap",
1106+
}
1107+
: {}),
11011108
},
11021109
};
11031110

0 commit comments

Comments
 (0)