diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx
index 87ebdda..083c942 100644
--- a/app/(tabs)/index.tsx
+++ b/app/(tabs)/index.tsx
@@ -131,18 +131,18 @@ export default function HomeScreen() {
}, [filteredTemplates, setLikeCountStates])
// 状态判断 - 使用 useMemo 缓存
- // 统一 loading 状态:只要有任何一个在加载,就显示 loading
- const isLoading = useMemo(() =>
- categoriesLoading || templatesLoading,
- [categoriesLoading, templatesLoading]
+ // 只在首次加载分类时显示 loading,切换分类时不显示 loading(提升体验)
+ const isInitialLoading = useMemo(() =>
+ categoriesLoading || (templatesLoading && filteredTemplates.length === 0),
+ [categoriesLoading, templatesLoading, filteredTemplates.length]
)
const showEmptyState = useMemo(() =>
- !isLoading && categoriesData?.categories?.length === 0,
- [isLoading, categoriesData?.categories?.length]
+ !isInitialLoading && categoriesData?.categories?.length === 0,
+ [isInitialLoading, categoriesData?.categories?.length]
)
const showEmptyTemplates = useMemo(() =>
- !isLoading && !showEmptyState && filteredTemplates.length === 0,
- [isLoading, showEmptyState, filteredTemplates.length]
+ !isInitialLoading && !showEmptyState && !templatesLoading && filteredTemplates.length === 0,
+ [isInitialLoading, showEmptyState, templatesLoading, filteredTemplates.length]
)
const [refreshing, setRefreshing] = useState(false)
@@ -157,10 +157,10 @@ export default function HomeScreen() {
// 加载更多处理
const handleEndReached = useCallback(() => {
- if (!loadingMore && hasMore && !isLoading) {
+ if (!loadingMore && hasMore && !templatesLoading) {
loadMore()
}
- }, [loadingMore, hasMore, isLoading, loadMore])
+ }, [loadingMore, hasMore, templatesLoading, loadMore])
// 左右滑动切换分类
const handleSwipeLeft = useCallback(() => {
@@ -299,7 +299,7 @@ export default function HomeScreen() {
/>
{/* 标签导航 */}
- {!isLoading && !showEmptyState && (
+ {!isInitialLoading && !showEmptyState && (
handleTabsLayout(e.nativeEvent.layout.y, e.nativeEvent.layout.height)}
style={isSticky ? { opacity: 0, height: tabsHeight } : undefined}
@@ -314,8 +314,8 @@ export default function HomeScreen() {
)}
- {/* 统一的加载状态 */}
- {isLoading && }
+ {/* 统一的加载状态 - 只在首次加载时显示 */}
+ {isInitialLoading && }
{/* 错误状态 */}
{categoriesError && (
@@ -335,7 +335,7 @@ export default function HomeScreen() {
), [
activatesData?.activities,
handleActivityPress,
- isLoading,
+ isInitialLoading,
showEmptyState,
isSticky,
tabsHeight,
@@ -369,8 +369,8 @@ export default function HomeScreen() {
[filteredTemplates]
)
- // 只有在非加载状态且有数据时才显示列表
- const showTemplateList = !isLoading && !showEmptyState && !showEmptyTemplates
+ // 只有在非首次加载状态且有数据时才显示列表
+ const showTemplateList = !isInitialLoading && !showEmptyState && !showEmptyTemplates
return (
@@ -386,7 +386,7 @@ export default function HomeScreen() {
/>
{/* 吸顶标签导航 */}
- {isSticky && !isLoading && !showEmptyState && (
+ {isSticky && !isInitialLoading && !showEmptyState && (
{
+ if (item.template?.id) {
+ router.push({
+ pathname: '/templateDetail' as any,
+ params: { id: item.template.id },
+ })
+ }
+ }}
>
{
+ if (item.template?.id) {
+ router.push({
+ pathname: '/templateDetail' as any,
+ params: { id: item.template.id },
+ })
+ }
+ }}
>
(null)
const [drawerVisible, setDrawerVisible] = useState(false)
@@ -56,14 +53,6 @@ export default function TemplateDetailScreen() {
}
}, [templateDetail])
- // Initialize like and favorite status
- useEffect(() => {
- if (templateId) {
- checkLiked()
- checkFavorited()
- }
- }, [templateId, checkLiked, checkFavorited])
-
const handleStartCreating = useCallback(() => {
// Navigate to generateVideo page if no form schema
if (!templateDetail?.formSchema?.startNodes || templateDetail.formSchema.startNodes.length === 0) {
@@ -236,23 +225,6 @@ export default function TemplateDetailScreen() {
- {/* Social Action Bar */}
- {templateId && (
-
-
-
- )}
-
{/* Upload Drawer - 移到最外层以确保从屏幕底部弹出 */}