refactor(navigation): replace direct navigation with navigation service
Some checks failed
Frontend CI / ota-android (push) Has been cancelled
Frontend CI / build-android-apk (push) Has been cancelled
Frontend CI / build-and-push-web (push) Has been cancelled

Replace direct `navigation.navigate()` and `navigation.getParent()?.navigate()` calls with centralized `navigationService.navigate()` across multiple screens. Convert screen component functions from JSX elements to array-returning functions in RootNavigator to fix React key warnings and improve render consistency.

- HomeScreen: use navigationService for post and user navigation
- PrivateChatInfoScreen: use navigationService for profile navigation
- ChatScreen: use navigationService for avatar press and user profile navigation
- RootNavigator: convert PublicScreens and AuthenticatedScreens to getPublicScreens() and getAuthenticatedScreens() functions returning arrays with proper keys
This commit is contained in:
lafay
2026-03-18 14:52:58 +08:00
parent a8f7e907b6
commit 2321c2dc06
4 changed files with 181 additions and 170 deletions

View File

@@ -35,6 +35,7 @@ import { HomeStackParamList, RootStackParamList } from '../../navigation/types';
import { useResponsive, useResponsiveSpacing } from '../../hooks/useResponsive';
import { SearchScreen } from './SearchScreen';
import { CreatePostScreen } from '../create/CreatePostScreen';
import { navigationService } from '../../infrastructure/navigation/navigationService';
type NavigationProp = NativeStackNavigationProp<HomeStackParamList, 'Home'> & NativeStackNavigationProp<RootStackParamList>;
@@ -343,12 +344,12 @@ export const HomeScreen: React.FC = () => {
// 跳转到帖子详情
const handlePostPress = (postId: string, scrollToComments: boolean = false) => {
navigation.getParent()?.navigate('PostDetail', { postId, scrollToComments });
navigationService.navigate('PostDetail', { postId, scrollToComments });
};
// 跳转到用户主页
const handleUserPress = (userId: string) => {
navigation.getParent()?.navigate('UserProfile', { userId });
navigationService.navigate('UserProfile', { userId });
};
// 点赞帖子