import { Image } from 'expo-image'; import React, { useState } from 'react'; import { Dimensions, FlatList, ImageBackground, StyleSheet, Text, TouchableOpacity, View, } from 'react-native'; import { Images } from '@/constants/images'; const { width } = Dimensions.get('window'); interface Product { cover: string; name: string; level: string; quantity?: number; } interface ProductSwiperProps { products: Product[]; onShowSwipe?: (index: number) => void; } export default function ProductSwiper({ products, onShowSwipe }: ProductSwiperProps) { const [current, setCurrent] = useState(0); const getProbability = (item: Product) => { return "10%"; // Placeholder }; if (!products || products.length === 0) return null; const renderItem = ({ item, index }: { item: Product; index: number }) => ( onShowSwipe?.(index)} style={styles.itemContainer} > {/* Details Button/Tag */} {item.level === 'A' ? '超神款' : item.level === 'B' ? '欧皇款' : item.level === 'C' ? '隐藏款' : '普通款'} {getProbability(item)} {/* Name Tag */} {item.name} ); return ( index.toString()} onMomentumScrollEnd={(e) => { const contentOffset = e.nativeEvent.contentOffset; const viewSize = e.nativeEvent.layoutMeasurement; const pageNum = Math.floor(contentOffset.x / viewSize.width); setCurrent(pageNum); }} /> {/* Left/Right Arrows if needed */} {current > 0 && ( )} {current < products.length - 1 && ( )} ); } const styles = StyleSheet.create({ container: { width: '100%', height: 380, // Adjusted height alignItems: 'center', marginTop: 20, }, itemContainer: { width: width, // Full width for paging height: '100%', justifyContent: 'center', alignItems: 'center', }, imageBox: { width: '60%', height: '60%', justifyContent: 'center', alignItems: 'center', }, image: { width: '100%', height: '100%', }, detailsTag: { position: 'absolute', right: 40, bottom: 80, width: 100, height: 60, justifyContent: 'center', alignItems: 'center', }, detailsContent: { alignItems: 'center', justifyContent: 'center', marginTop: 5, }, levelText: { color: '#fff', fontSize: 12, fontWeight: 'bold', textShadowColor: '#000', textShadowOffset: { width: 1, height: 1 }, textShadowRadius: 1, }, probText: { color: '#fff', fontSize: 10, fontWeight: 'bold', textShadowColor: '#000', textShadowOffset: { width: 1, height: 1 }, textShadowRadius: 1, }, nameTag: { position: 'absolute', left: 40, top: 40, width: 40, height: 120, justifyContent: 'center', alignItems: 'center', paddingVertical: 10, }, nameText: { color: '#000', fontSize: 12, fontWeight: 'bold', width: 12, textAlign: 'center', }, arrow: { position: 'absolute', top: '50%', marginTop: -20, width: 40, height: 40, zIndex: 10, }, leftArrow: { left: 10, }, rightArrow: { right: 10, }, arrowImg: { width: '100%', height: '100%', } });