refactor(navigation): replace direct navigation with navigation service
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:
@@ -31,6 +31,7 @@ import { groupService } from '../../../../services/groupService';
|
||||
import { userManager } from '../../../../stores/userManager';
|
||||
import { groupManager } from '../../../../stores/groupManager';
|
||||
import { RootStackParamList } from '../../../../navigation/types';
|
||||
import { navigationService } from '../../../../infrastructure/navigation/navigationService';
|
||||
import {
|
||||
GroupMessage,
|
||||
PanelType,
|
||||
@@ -1039,9 +1040,9 @@ export const useChatScreen = () => {
|
||||
// 点击头像跳转到用户主页
|
||||
const handleAvatarPress = useCallback((userId: string) => {
|
||||
if (userId && userId !== currentUserId) {
|
||||
navigation.navigate('UserProfile' as any, { userId: String(userId) });
|
||||
navigationService.navigate('UserProfile', { userId: String(userId) });
|
||||
}
|
||||
}, [navigation, currentUserId]);
|
||||
}, [currentUserId]);
|
||||
|
||||
// 长按头像@用户
|
||||
const handleAvatarLongPress = useCallback((senderId: string, nickname: string) => {
|
||||
@@ -1113,8 +1114,7 @@ export const useChatScreen = () => {
|
||||
conversationId: conversationId || undefined,
|
||||
});
|
||||
} else if (otherUser?.id) {
|
||||
const rootNavigation = navigation.getParent();
|
||||
rootNavigation?.navigate('UserProfile' as any, { userId: String(otherUser.id) });
|
||||
navigationService.navigate('UserProfile', { userId: String(otherUser.id) });
|
||||
}
|
||||
}, [navigation, isGroupChat, routeGroupId, otherUser]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user