From 8413b9dfa07460f7a05811598b806c1df211c72f Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 16 May 2025 15:01:52 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E9=AA=A8=E6=9E=B6=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/screens/HomeScreen.tsx | 110 ++++++++++++++++++++++++++++++++----- 1 file changed, 97 insertions(+), 13 deletions(-) diff --git a/app/screens/HomeScreen.tsx b/app/screens/HomeScreen.tsx index d470078..cec2b6f 100644 --- a/app/screens/HomeScreen.tsx +++ b/app/screens/HomeScreen.tsx @@ -52,6 +52,61 @@ type CategoryContentType = { [key: string]: SubcategoryItem[]; }; +// 懒加载图片组件 - 改进版本 +const LazyImage = React.memo( + ({ + uri, + style, + resizeMode, + }: { + uri: string; + style: any; + resizeMode: any; + }) => { + const [isLoaded, setIsLoaded] = useState(false); + const [hasError, setHasError] = useState(false); + + const onLoad = useCallback(() => { + setIsLoaded(true); + }, []); + + const onError = useCallback(() => { + setHasError(true); + setIsLoaded(true); // Also mark as loaded on error to remove placeholder + }, []); + + return ( + + {/* Show placeholder while image is loading */} + {!isLoaded && !hasError && ( + + )} + + {/* Show error state if image failed to load */} + {hasError && ( + + + + 加载失败 + + + )} + + {/* Actual image */} + + + ); + } +); + // 产品骨架屏组件 - 用于加载状态 const ProductSkeleton = React.memo(() => { // 创建动画值 @@ -303,19 +358,30 @@ export const HomeScreen = () => { activeOpacity={0.9} style={styles.beautyProductCard1} > - + + {item.product_image_urls && item.product_image_urls.length > 0 ? ( + + ) : ( + + + + )} + {userStore.user?.user_id && ( - - VIP - - {userStore.user?.vip_level} - - + + + VIP + + {userStore.user?.vip_level} + + + )} - +