You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

314 lines
8.9 KiB

import React, { useCallback } from 'react';
import {
View,
Text,
StyleSheet,
ScrollView,
TouchableOpacity,
SafeAreaView,
InteractionManager
} from 'react-native';
import Ionicons from '@expo/vector-icons/Ionicons';
import { useNavigation } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
2 months ago
import { useTranslation } from 'react-i18next';
2 months ago
// 为图标定义类型
type IconProps = {
name: string;
size: number;
color: string;
};
2 months ago
// 图标组件辅助函数 - 使用React.memo优化渲染
const IconComponent = React.memo(({ name, size, color }: IconProps) => {
const Icon = Ionicons as any;
return <Icon name={name} size={size} color={color} />;
});
export const HomeScreen = () => {
const navigation = useNavigation<NativeStackNavigationProp<any>>();
2 months ago
const { t } = useTranslation();
// 导航到搜索页面 - 使用useCallback优化函数引用
const navigateToSearch = useCallback(() => {
// 使用InteractionManager延迟执行导航操作,确保当前交互和动画已完成
InteractionManager.runAfterInteractions(() => {
navigation.navigate('Search');
});
}, [navigation]);
return (
<SafeAreaView style={styles.container}>
2 months ago
{/* 搜索栏 */}
<View style={styles.searchContainer}>
<TouchableOpacity
style={styles.searchBar}
activeOpacity={0.7}
onPress={navigateToSearch}
>
<IconComponent name="search-outline" size={20} color="#999" />
2 months ago
<Text style={styles.searchPlaceholder}>{t('searchProducts')}</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.cameraButton}>
<IconComponent name="camera-outline" size={24} color="#333" />
</TouchableOpacity>
</View>
<ScrollView
showsVerticalScrollIndicator={false}
keyboardShouldPersistTaps="handled"
>
2 months ago
{/* 横幅 */}
<View style={styles.bannerContainer}>
<Text style={styles.bannerText}>banner picture</Text>
</View>
2 months ago
{/* 服务选项 */}
<View style={styles.serviceContainer}>
<TouchableOpacity style={styles.serviceItem}>
<View style={styles.serviceIconBg}>
<Text style={styles.serviceIcon}>🚢</Text>
</View>
2 months ago
<Text style={styles.serviceText}>{t('shipping')}</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.serviceItem}>
<View style={styles.serviceIconBg}>
<Text style={styles.serviceIcon}>💰</Text>
</View>
2 months ago
<Text style={styles.serviceText}>{t('quote')}</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.serviceItem}>
<View style={styles.serviceIconBg}>
<Text style={styles.serviceIcon}>📱</Text>
</View>
2 months ago
<Text style={styles.serviceText}>{t('tiktok')}</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.serviceItem}>
<View style={styles.serviceIconBg}>
<Text style={[styles.serviceIcon, {color: 'red'}]}></Text>
</View>
2 months ago
<Text style={styles.serviceText}>{t('howToBuy')}</Text>
</TouchableOpacity>
</View>
2 months ago
{/* 分类按钮 */}
<View style={styles.categoryContainer}>
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
contentContainerStyle={styles.categoryScrollContent}
>
<TouchableOpacity style={[styles.categoryButton, styles.categoryActive]}>
2 months ago
<Text style={[styles.categoryText, styles.categoryActiveText]}>{t('all')}</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.categoryButton}>
2 months ago
<Text style={styles.categoryText}>{t('electronics')}</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.categoryButton}>
2 months ago
<Text style={styles.categoryText}>{t('clothing')}</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.categoryButton}>
2 months ago
<Text style={styles.categoryText}>{t('home')}</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.categoryButton}>
2 months ago
<Text style={styles.categoryText}>{t('beauty')}</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.categoryButton}>
2 months ago
<Text style={styles.categoryText}>{t('kids')}</Text>
</TouchableOpacity>
</ScrollView>
</View>
2 months ago
{/* 产品网格 */}
<View style={styles.productGrid}>
2 months ago
{/* 产品1 */}
<View style={styles.productCard}>
<View style={styles.productImageContainer}>
<Text style={styles.placeholderText}>product picture</Text>
</View>
<View style={styles.productInfo}>
<Text style={styles.productPrice}>$29.99</Text>
<Text style={styles.productTitle} numberOfLines={2}>
Wireless Bluetooth Earbuds
</Text>
<Text style={styles.productSales}>Monthly Sales: 1,234</Text>
</View>
</View>
2 months ago
{/* 产品2 */}
<View style={styles.productCard}>
<View style={styles.productImageContainer}>
<Text style={styles.placeholderText}>product picture</Text>
</View>
<View style={styles.productInfo}>
<Text style={[styles.productPrice, {color: '#ff6600'}]}>19.99</Text>
<Text style={styles.productTitle} numberOfLines={2}>
Portable Power Bank 10000
</Text>
<Text style={styles.productSales}>Monthly Sales: 2,350</Text>
</View>
</View>
{/* More products */}
<View style={styles.productCard}>
<View style={styles.productImageContainer}>
<Text style={styles.placeholderText}>product picture</Text>
</View>
</View>
<View style={styles.productCard}>
<View style={styles.productImageContainer}>
<Text style={styles.placeholderText}>product picture</Text>
</View>
</View>
</View>
</ScrollView>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#f5f5f5',
},
safeArea: {
flex: 1,
},
searchContainer: {
flexDirection: 'row',
paddingHorizontal: 15,
paddingVertical: 10,
backgroundColor: '#fff',
alignItems: 'center',
},
searchBar: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
backgroundColor: '#f0f0f0',
borderRadius: 20,
paddingHorizontal: 15,
height: 40,
},
searchPlaceholder: {
flex: 1,
marginLeft: 8,
fontSize: 16,
},
cameraButton: {
marginLeft: 10,
padding: 5,
},
bannerContainer: {
height: 180,
backgroundColor: '#e0e0e0',
marginHorizontal: 15,
marginTop: 15,
borderRadius: 8,
alignItems: 'center',
justifyContent: 'center',
},
bannerText: {
color: '#999',
fontSize: 20,
},
serviceContainer: {
flexDirection: 'row',
justifyContent: 'space-around',
backgroundColor: '#fff',
marginHorizontal: 15,
marginTop: 15,
borderRadius: 12,
padding: 15,
},
serviceItem: {
alignItems: 'center',
},
serviceIconBg: {
width: 50,
height: 50,
borderRadius: 25,
backgroundColor: '#f0f0f0',
justifyContent: 'center',
alignItems: 'center',
marginBottom: 8,
},
serviceIcon: {
fontSize: 24,
},
serviceText: {
fontSize: 14,
color: '#333',
},
categoryContainer: {
marginTop: 15,
paddingVertical: 10,
backgroundColor: '#fff',
},
categoryScrollContent: {
paddingHorizontal: 10,
},
categoryButton: {
paddingHorizontal: 20,
paddingVertical: 10,
borderRadius: 20,
marginHorizontal: 5,
backgroundColor: '#f0f0f0',
},
categoryActive: {
backgroundColor: '#ff6600',
},
categoryText: {
color: '#666',
fontWeight: '500',
},
categoryActiveText: {
color: '#fff',
},
productGrid: {
flexDirection: 'row',
flexWrap: 'wrap',
padding: 10,
justifyContent: 'space-between',
},
productCard: {
width: '48%',
backgroundColor: '#fff',
borderRadius: 8,
marginBottom: 15,
overflow: 'hidden',
},
productImageContainer: {
height: 150,
backgroundColor: '#e0e0e0',
alignItems: 'center',
justifyContent: 'center',
},
placeholderText: {
color: '#999',
fontSize: 16,
},
productInfo: {
padding: 10,
},
productPrice: {
fontSize: 18,
fontWeight: 'bold',
color: '#ff6600',
marginBottom: 5,
},
productTitle: {
fontSize: 14,
color: '#333',
marginBottom: 5,
},
productSales: {
fontSize: 12,
color: '#999',
}
});