/** * 统一的用户主页组件 * 胡萝卜BBS - 支持两种模式:self(当前用户)和 other(其他用户) * 采用现代卡片式设计,优化视觉层次和交互体验 * 支持桌面端双栏布局 */ import React, { useCallback, useMemo } from 'react'; import { View, RefreshControl, ScrollView, } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; import { NavigationProp } from '@react-navigation/native'; import { colors } from '../../theme'; import { Post } from '../../types'; import { PostCard, TabBar, UserProfileHeader } from '../../components/business'; import { Loading, EmptyState, ResponsiveContainer } from '../../components/common'; import { useResponsive } from '../../hooks'; import { ProfileStackParamList } from '../../navigation/types'; import { useUserProfile, ProfileMode, TABS, TAB_ICONS, sharedStyles } from './useUserProfile'; interface UserProfileScreenProps { mode: ProfileMode; userId?: string; // 仅 other 模式需要 /** 使用 NavigationProp 避免与具体 screen 的 NativeStackNavigationProp 在 setParams 上不兼容 */ profileNavigation?: NavigationProp; // 仅 self 模式需要 } export const UserProfileScreen: React.FC = ({ mode, userId, profileNavigation }) => { const { isDesktop, isTablet } = useResponsive(); const { user, posts, favorites, loading, refreshing, activeTab, setActiveTab, scrollBottomInset, onRefresh, handleFollow, handlePostAction, handleFollowingPress, handleFollowersPress, handleMessage, handleMore, handleSettings, handleEditProfile, isCurrentUser, currentUser, } = useUserProfile({ mode, userId, isDesktop, isTablet, profileNavigation }); // 渲染帖子列表 const renderPostList = useCallback((postList: Post[], emptyTitle: string, emptyDesc: string) => { if (postList.length === 0) { return ( ); } return ( {postList.map((post, index) => { const isPostAuthor = currentUser?.id === post.author?.id; return ( handlePostAction(post, action)} isPostAuthor={isPostAuthor} /> ); })} ); }, [currentUser?.id, handlePostAction, activeTab]); // 渲染内容 const renderContent = useCallback(() => { if (loading) return ; if (activeTab === 0) { return renderPostList( posts, mode === 'self' ? '还没有帖子' : '这个用户还没有发布任何帖子', mode === 'self' ? '分享你的想法,发布第一条帖子吧' : '' ); } if (activeTab === 1) { return renderPostList( favorites, mode === 'self' ? '还没有收藏' : '这个用户还没有收藏任何帖子', mode === 'self' ? '发现喜欢的内容,点击收藏按钮保存' : '' ); } return null; }, [loading, activeTab, posts, favorites, mode, renderPostList]); // 渲染用户信息头部 const renderUserHeader = useMemo(() => { if (!user) return null; return ( ); }, [user, isCurrentUser, handleFollow, handleSettings, handleEditProfile, handleMessage, handleMore, handleFollowingPress, handleFollowersPress]); // 渲染 TabBar 和内容 const renderTabBarAndContent = useMemo(() => ( <> {renderContent()} ), [activeTab, renderContent]); // 未登录/用户不存在状态 if (mode === 'self' && !currentUser) { return ( ); } if (mode === 'other' && !user && !loading) { return ( ); } // 桌面端使用双栏布局 if (isDesktop || isTablet) { return ( {/* 左侧:用户信息 */} } > {renderUserHeader} {/* 右侧:帖子列表 */} {renderTabBarAndContent} ); } // 移动端使用单栏布局 return ( } contentContainerStyle={[sharedStyles.scrollContent, { paddingBottom: scrollBottomInset }]} > {renderUserHeader} {renderTabBarAndContent} ); }; export default UserProfileScreen;