import { memo, useCallback } from "react" ;
import { FlashList } from "@shopify/flash-list" ;
import { Image, StyleSheet, Text, View } from "react-native" ;
interface Product {
id : string ;
name : string ;
price : string ;
imageUrl : string ;
}
const ESTIMATED_ROW_HEIGHT = 96 ;
const ProductRow = memo ( function ProductRow ({ item } : { item : Product }) {
return (
< View style = {styles.row}>
< Image source = {{ uri: item.imageUrl }} style = {styles.thumb} />
< View style = {styles.meta}>
< Text style = {styles.name} numberOfLines = { 1 }>
{item.name}
</ Text >
< Text style = {styles.price}>{item.price}</ Text >
</ View >
</ View >
);
});
export function ProductFeedScreen ({ products } : { products : Product [] }) {
const renderItem = useCallback (
({ item } : { item : Product }) => < ProductRow item = {item} />,
[],
);
return (
< View style = {styles.screen}>
< FlashList
data = {products}
estimatedItemSize = { ESTIMATED_ROW_HEIGHT }
keyExtractor = {( item ) => item.id}
renderItem = {renderItem}
drawDistance = { 250 }
contentContainerStyle = {styles.list}
/>
</ View >
);
}
const styles = StyleSheet. create ({
screen: { flex: 1 , backgroundColor: "#f8fafc" },
list: { paddingVertical: 8 },
row: {
flexDirection: "row" ,
alignItems: "center" ,
gap: 12 ,
paddingHorizontal: 16 ,
paddingVertical: 10 ,
backgroundColor: "#fff" ,
minHeight: ESTIMATED_ROW_HEIGHT ,
},
thumb: { width: 72 , height: 72 , borderRadius: 8 , backgroundColor: "#e2e8f0" },
meta: { flex: 1 },
name: { fontSize: 16 , fontWeight: "600" , color: "#0f172a" },
price: { fontSize: 14 , color: "#2563eb" , marginTop: 4 },
});