refactor(App, navigation): migrate to Expo Router and clean up navigation structure
- Updated App entry point to utilize Expo Router, simplifying the navigation setup. - Removed legacy navigation components and services to streamline the codebase. - Adjusted package.json to reflect the new entry point and updated dependencies for compatibility. - Enhanced overall application structure by consolidating navigation logic and improving maintainability.
This commit is contained in:
@@ -26,8 +26,8 @@ import {
|
||||
Platform,
|
||||
} from 'react-native';
|
||||
import { SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context';
|
||||
import { useNavigation, useIsFocused } from '@react-navigation/native';
|
||||
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
||||
import { useRouter } from 'expo-router';
|
||||
import { useIsFocused } from '@react-navigation/native';
|
||||
import { useBottomTabBarHeight } from '@react-navigation/bottom-tabs';
|
||||
import { MaterialCommunityIcons } from '@expo/vector-icons';
|
||||
import { colors, spacing, fontSizes, shadows, borderRadius } from '../../theme';
|
||||
@@ -43,9 +43,9 @@ import {
|
||||
useMarkAsRead,
|
||||
useMessageManagerConversations,
|
||||
} from '../../stores';
|
||||
import { Avatar, Text, EmptyState, ResponsiveContainer } from '../../components/common';
|
||||
import { Avatar, Text, EmptyState, ResponsiveContainer, AppBackButton } from '../../components/common';
|
||||
import { useResponsive, useBreakpointGTE } from '../../hooks/useResponsive';
|
||||
import { RootStackParamList, MessageStackParamList } from '../../navigation/types';
|
||||
import * as hrefs from '../../navigation/hrefs';
|
||||
// 导入 EmbeddedChat 组件用于桌面端双栏布局
|
||||
import { EmbeddedChat } from './components/EmbeddedChat';
|
||||
import { ConversationListRow } from './components/ConversationListRow';
|
||||
@@ -54,9 +54,6 @@ import { NotificationsScreen } from './NotificationsScreen';
|
||||
// 导入扫码组件
|
||||
import { QRCodeScanner } from '../../components/business/QRCodeScanner';
|
||||
|
||||
type NavigationProp = NativeStackNavigationProp<RootStackParamList>;
|
||||
type MessageNavProp = NativeStackNavigationProp<MessageStackParamList>;
|
||||
|
||||
// 系统通知会话特殊ID
|
||||
const SYSTEM_MESSAGE_CHANNEL_ID = '-1';
|
||||
|
||||
@@ -76,7 +73,7 @@ interface SearchResultItem {
|
||||
* 支持响应式双栏布局
|
||||
*/
|
||||
export const MessageListScreen: React.FC = () => {
|
||||
const navigation = useNavigation<NavigationProp & MessageNavProp>();
|
||||
const router = useRouter();
|
||||
const isFocused = useIsFocused();
|
||||
const insets = useSafeAreaInsets();
|
||||
// 在大屏幕模式下不使用 Bottom Tab Navigator,所以不需要 tabBarHeight
|
||||
@@ -286,22 +283,25 @@ export const MessageListScreen: React.FC = () => {
|
||||
setSelectedConversation(conversation);
|
||||
} else if (conversation.type === 'group' && conversation.group) {
|
||||
// 群聊 - 窄屏下导航
|
||||
(navigation as any).navigate('Chat', {
|
||||
conversationId: String(conversation.id),
|
||||
groupId: String(conversation.group.id),
|
||||
groupName: conversation.group.name,
|
||||
isGroupChat: true,
|
||||
});
|
||||
router.push(
|
||||
hrefs.hrefChat({
|
||||
conversationId: String(conversation.id),
|
||||
groupId: String(conversation.group.id),
|
||||
groupName: conversation.group.name,
|
||||
isGroupChat: true,
|
||||
})
|
||||
);
|
||||
} else {
|
||||
// 私聊 - 窄屏下导航
|
||||
const currentUserId = useAuthStore.getState().currentUser?.id;
|
||||
const otherUser = conversation.participants?.find(p => String(p.id) !== String(currentUserId));
|
||||
(navigation as any).navigate('Chat', {
|
||||
conversationId: String(conversation.id),
|
||||
userId: otherUser ? String(otherUser.id) : undefined,
|
||||
userName: otherUser?.nickname || otherUser?.username,
|
||||
isGroupChat: false,
|
||||
});
|
||||
router.push(
|
||||
hrefs.hrefChat({
|
||||
conversationId: String(conversation.id),
|
||||
userId: otherUser ? String(otherUser.id) : undefined,
|
||||
isGroupChat: false,
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -311,12 +311,12 @@ export const MessageListScreen: React.FC = () => {
|
||||
|
||||
// 创建群聊
|
||||
const handleCreateGroup = () => {
|
||||
(navigation as any).navigate('CreateGroup');
|
||||
router.push(hrefs.hrefGroupCreate());
|
||||
};
|
||||
|
||||
// 主动加群
|
||||
const handleJoinGroup = () => {
|
||||
(navigation as any).navigate('JoinGroup');
|
||||
router.push(hrefs.hrefGroupJoin());
|
||||
};
|
||||
|
||||
const handleOpenActionMenu = () => {
|
||||
@@ -581,12 +581,13 @@ export const MessageListScreen: React.FC = () => {
|
||||
const conversation = await createConversation(String(user.id));
|
||||
|
||||
if (conversation) {
|
||||
(navigation as any).navigate('Chat', {
|
||||
conversationId: String(conversation.id),
|
||||
userId: String(user.id),
|
||||
userName: user.nickname || user.username,
|
||||
isGroupChat: false,
|
||||
});
|
||||
router.push(
|
||||
hrefs.hrefChat({
|
||||
conversationId: String(conversation.id),
|
||||
userId: String(user.id),
|
||||
isGroupChat: false,
|
||||
})
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('创建会话失败:', error);
|
||||
@@ -660,9 +661,7 @@ export const MessageListScreen: React.FC = () => {
|
||||
const renderSearchMode = () => (
|
||||
<View style={styles.searchModeContainer}>
|
||||
<View style={styles.searchInputContainer}>
|
||||
<TouchableOpacity onPress={handleCloseSearch}>
|
||||
<MaterialCommunityIcons name="arrow-left" size={22} color="#666" />
|
||||
</TouchableOpacity>
|
||||
<AppBackButton onPress={handleCloseSearch} iconColor="#666" />
|
||||
<TextInput
|
||||
style={styles.searchInput}
|
||||
placeholder={activeSearchTab === 'chat' ? '搜索聊天记录' : '搜索用户'}
|
||||
|
||||
Reference in New Issue
Block a user