refactor(ImageGallery, HomeScreen, PostService, UserStore): streamline post type handling and improve tab navigation
Some checks failed
Frontend CI / build-and-push-web (push) Successful in 2m37s
Frontend CI / ota-android (push) Has been cancelled
Frontend CI / build-android-apk (push) Has been cancelled

- Updated ImageGallery to manage loading states more effectively and prevent unnecessary updates.
- Refactored HomeScreen to remove the 'recommend' post type, simplifying the post type options.
- Adjusted PostService and UserStore to eliminate references to 'recommend', ensuring consistency across the application.
- Enhanced tab navigation in SimpleMobileTabNavigator to optimize rendering and manage mounted tabs more efficiently.
- Improved error handling and loading states in various components for better user experience.
This commit is contained in:
lafay
2026-03-24 05:18:22 +08:00
parent 357c1d4995
commit 48339384d2
9 changed files with 72 additions and 34 deletions

View File

@@ -178,6 +178,12 @@ export function SimpleMobileTabNavigator() {
const insets = useSafeAreaInsets();
const messageUnreadCount = useTotalUnreadCount();
const [activeTab, setActiveTab] = useState<TabName>('HomeTab');
const [mountedTabs, setMountedTabs] = useState<Record<TabName, boolean>>({
HomeTab: true,
MessageTab: false,
ScheduleTab: false,
ProfileTab: false,
});
// 初始化 MessageManager
useEffect(() => {
@@ -186,12 +192,21 @@ export function SimpleMobileTabNavigator() {
// 处理 Tab 切换
const handleTabPress = useCallback((tabName: TabName) => {
setMountedTabs((prev) => {
if (prev[tabName]) {
return prev;
}
return {
...prev,
[tabName]: true,
};
});
setActiveTab(tabName);
}, []);
// 渲染当前 Tab 内容
const renderTabContent = () => {
switch (activeTab) {
// 根据 Tab 名称渲染对应内容
const renderTabView = (tabName: TabName) => {
switch (tabName) {
case 'HomeTab':
return <HomeScreen />;
case 'MessageTab':
@@ -276,7 +291,24 @@ export function SimpleMobileTabNavigator() {
<View style={styles.container}>
{/* 内容区域 */}
<View style={styles.content}>
{renderTabContent()}
{(Object.keys(mountedTabs) as TabName[]).map((tabName) => {
if (!mountedTabs[tabName]) {
return null;
}
const isActive = activeTab === tabName;
return (
<View
key={tabName}
style={[
styles.tabScreen,
!isActive && styles.tabScreenHidden,
]}
pointerEvents={isActive ? 'auto' : 'none'}
>
{renderTabView(tabName)}
</View>
);
})}
</View>
{/* Tab Bar */}
@@ -334,6 +366,13 @@ const styles = StyleSheet.create({
},
content: {
flex: 1,
position: 'relative',
},
tabScreen: {
...StyleSheet.absoluteFillObject,
},
tabScreenHidden: {
display: 'none',
},
bottomSpacer: {
backgroundColor: 'transparent',