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'; import { useTranslation } from 'react-i18next'; // 为图标定义类型 type IconProps = { name: string; size: number; color: string; }; // 图标组件辅助函数 - 使用React.memo优化渲染 const IconComponent = React.memo(({ name, size, color }: IconProps) => { const Icon = Ionicons as any; return ; }); export const HomeScreen = () => { const navigation = useNavigation>(); const { t } = useTranslation(); // 导航到搜索页面 - 使用useCallback优化函数引用 const navigateToSearch = useCallback(() => { // 使用InteractionManager延迟执行导航操作,确保当前交互和动画已完成 InteractionManager.runAfterInteractions(() => { navigation.navigate('Search'); }); }, [navigation]); return ( {/* 搜索栏 */} {t('searchProducts')} {/* 横幅 */} banner picture {/* 服务选项 */} 🚢 {t('shipping')} 💰 {t('quote')} 📱 {t('tiktok')} {t('howToBuy')} {/* 分类按钮 */} {t('all')} {t('electronics')} {t('clothing')} {t('home')} {t('beauty')} {t('kids')} {/* 产品网格 */} {/* 产品1 */} product picture $29.99 Wireless Bluetooth Earbuds Monthly Sales: 1,234 {/* 产品2 */} product picture €19.99 Portable Power Bank 10000 Monthly Sales: 2,350 {/* More products */} product picture product picture ); }; 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', } });