Skip to content

Commit 9a06195

Browse files
authored
Merge pull request #36 from RoboJackets/ItemList
Added an ItemList component to be used throughout the app
2 parents 5c5e41d + a9d7be1 commit 9a06195

3 files changed

Lines changed: 95 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# dependencies
44
node_modules/
55

6+
#VsCode
7+
.vscode/settings.json
8+
69
# Expo
710
.expo/
811
dist/

Components/ItemList.tsx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React from 'react';
2+
import { FlatList, Pressable, StyleSheet, View } from 'react-native';
3+
4+
type ItemListProps<T> = {
5+
items: T[];
6+
onItemSelected: (item: T) => void;
7+
title: React.ReactNode;
8+
itemKey: (item: T, index: number) => string;
9+
callout?: React.ReactNode;
10+
empty?: React.ReactNode;
11+
itemContent: (item: T) => React.ReactNode;
12+
separator?: React.ReactNode;
13+
};
14+
15+
export function ItemList<T>(props: ItemListProps<T>) {
16+
return (
17+
<View style={styles.container}>
18+
{props.title}
19+
{props.callout}
20+
21+
{props.items.length === 0 ? (
22+
(props.empty ?? null)
23+
) : (
24+
<FlatList
25+
data={props.items}
26+
keyExtractor={props.itemKey}
27+
ItemSeparatorComponent={() => (
28+
<View>{props.separator ?? <View style={styles.separator} />}</View>
29+
)}
30+
renderItem={({ item }) => (
31+
<View>
32+
<Pressable onPress={() => props.onItemSelected(item)} style={styles.listItem}>
33+
{props.itemContent(item)}
34+
</Pressable>
35+
</View>
36+
)}
37+
/>
38+
)}
39+
</View>
40+
);
41+
}
42+
43+
const styles = StyleSheet.create({
44+
container: {
45+
flex: 1,
46+
width: '100%',
47+
},
48+
listItem: {
49+
borderColor: '#ddd',
50+
padding: 16,
51+
},
52+
53+
separator: {
54+
// Default styles, which can be overridden by props
55+
backgroundColor: '#ccc', // Default color (light gray)
56+
height: 2, // Determines the thickness of the line
57+
marginVertical: 5, // Adds some space above and below the line
58+
width: '100%', // Makes the line span the full width
59+
},
60+
});

Merchandise/MerchandiseScreen.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,38 @@ function MerchandiseScreen() {
66
// eslint-disable-next-line react-native/no-inline-styles
77
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
88
<Text>Merchandise Screen</Text>
9+
{/* {
10+
//Example of how to use the ItemList component. Replace with actual merchandise data and navigation logic as needed.
11+
<ItemList
12+
items={[
13+
{ name: 'T-shirt' },
14+
{ name: 'Hoodie' },
15+
{ name: 'Mug' },
16+
{ name: 'Sticker' },
17+
{ name: 'Cap' },
18+
{ name: 'Cap' },
19+
{ name: 'Cap' },
20+
{ name: 'Cap' },
21+
{ name: 'Cap' },
22+
{ name: 'Cap' },
23+
{ name: 'Cap' },
24+
{ name: 'Cap' },
25+
{ name: 'Cap' },
26+
{ name: 'Cap' },
27+
{ name: 'Cap' },
28+
{ name: 'Cap' },
29+
]} // Replace with actual merchandise data
30+
onItemSelected={(item) => console.log(item)}
31+
title={
32+
//Replace with actual color from current theme
33+
<Text style={{ color: Colors.surfaceDark }}>Pick a merchandise item to distribute</Text>
34+
}
35+
itemKey={(item, index) => index.toString()}
36+
empty={<Text>No items available</Text>}
37+
//Replace with actual color from current theme
38+
itemContent={(item) => <Text style={{ color: Colors.surfaceDark }}>{item.name}</Text>}
39+
/>
40+
} */}
941
</View>
1042
);
1143
}

0 commit comments

Comments
 (0)