2024-06-27 23:31:59 +02:00
|
|
|
import { Product } from "@/lib/product"
|
2024-06-29 02:04:30 +02:00
|
|
|
import { ImageBackground, StyleProp, StyleSheet, Text, View, ViewStyle } from "react-native";
|
2024-06-27 23:31:59 +02:00
|
|
|
import { AnimatedStyle } from "react-native-reanimated";
|
|
|
|
|
|
|
|
export type OnProductSelectedFunc = (product : Product) => any;
|
|
|
|
|
|
|
|
type MyStyle = StyleProp<AnimatedStyle<StyleProp<ViewStyle>>>;
|
|
|
|
|
|
|
|
export type ProductTileProps = {
|
|
|
|
product: (Product),
|
|
|
|
onProductSelected?: OnProductSelectedFunc,
|
|
|
|
style?: {
|
|
|
|
tile?: MyStyle,
|
|
|
|
image?: MyStyle,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const FALLBACK_IMAGE = "";
|
|
|
|
|
|
|
|
export function ProductTile ({product, onProductSelected, style} : ProductTileProps) {
|
|
|
|
const src = product.attributes.image || FALLBACK_IMAGE;
|
|
|
|
return (
|
2024-06-29 02:04:30 +02:00
|
|
|
<View style={styles.tile}>
|
2024-06-27 23:31:59 +02:00
|
|
|
<ImageBackground
|
|
|
|
src={src}
|
|
|
|
resizeMode="cover"
|
|
|
|
style={styles.image}
|
|
|
|
>
|
|
|
|
<Text style={styles.text}>{product.attributes.name || `Product ${product.id}`}</Text>
|
2024-06-29 02:04:30 +02:00
|
|
|
<Text style={styles.text}>{ product.priceDisplay } </Text>
|
2024-06-27 23:31:59 +02:00
|
|
|
</ImageBackground>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
image: {
|
|
|
|
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
|
2024-06-29 02:04:30 +02:00
|
|
|
},
|
|
|
|
tile: {
|
|
|
|
|
2024-06-27 23:31:59 +02:00
|
|
|
},
|
|
|
|
})
|