Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# dependencies
node_modules/

#VsCode
.vscode/settings.json
Comment thread
Jacob-Mayhue marked this conversation as resolved.

# Expo
.expo/
dist/
Expand Down
65 changes: 65 additions & 0 deletions Components/ItemList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React from 'react';
import { FlatList, Pressable, StyleSheet, View } from 'react-native';

type ItemListProps<T> = {
items: T[];
onItemSelected: (item: T) => void;
title: React.ReactNode;
itemKey: (item: T, index: number) => string;
callout?: React.ReactNode;
preItem?: (index: number) => React.ReactNode;
postItem?: (index: number) => React.ReactNode;
empty?: React.ReactNode;
itemContent: (item: T) => React.ReactNode;
separator?: React.ReactNode;
};

export function ItemList<T>(props: ItemListProps<T>) {
return (
<View style={styles.container}>
{props.title}
{props.callout}

{props.items.length === 0 ? (
(props.empty ?? null)
) : (
<FlatList
data={props.items}
keyExtractor={props.itemKey}
ItemSeparatorComponent={() => (
<View>{props.separator ?? <View style={styles.separator} />}</View>
)}
renderItem={({ item, index }) => (
<View>
{props.preItem?.(index)}

<Pressable onPress={() => props.onItemSelected(item)} style={styles.listItem}>
{props.itemContent(item)}
</Pressable>

{props.postItem?.(index)}
</View>
Comment thread
jvogt23 marked this conversation as resolved.
)}
/>
)}
</View>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
},
listItem: {
borderColor: '#ddd',
padding: 16,
},

separator: {
// Default styles, which can be overridden by props
backgroundColor: '#ccc', // Default color (light gray)
height: StyleSheet.hairlineWidth + 2, // Determines the thickness of the line
marginVertical: 5, // Adds some space above and below the line
width: '100%', // Makes the line span the full width
},
});
25 changes: 24 additions & 1 deletion Merchandise/MerchandiseScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
import React from 'react';
import { Text, View } from 'react-native';
import { ItemList } from '../Components/ItemList';
import { Colors } from '../Themes/Colors';

function MerchandiseScreen() {
return (
// eslint-disable-next-line react-native/no-inline-styles
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<View style={{ flex: 1, alignItems: 'flex-start', justifyContent: 'flex-start' }}>
<Text>Merchandise Screen</Text>
{
//Example of how to use the ItemList component. Replace with actual merchandise data and navigation logic as needed.
<ItemList
items={[
{ name: 'T-shirt' },
{ name: 'Hoodie' },
{ name: 'Mug' },
{ name: 'Sticker' },
{ name: 'Cap' },
]} // Replace with actual merchandise data
onItemSelected={(item) => console.log(item)}
title={
//Replace with actual color from current theme
<Text style={{ color: Colors.surfaceDark }}>Pick a merchandise item to distribute</Text>
}
itemKey={(item, index) => index.toString()}
empty={<Text>No items available</Text>}
//Replace with actual color from current theme
itemContent={(item) => <Text style={{ color: Colors.surfaceDark }}>{item.name}</Text>}
/>
}
</View>
);
}
Expand Down
Loading