refactor(App, navigation): migrate to Expo Router and clean up navigation structure
All checks were successful
Frontend CI / build-and-push-web (push) Successful in 4m27s
Frontend CI / ota-android (push) Successful in 11m6s
Frontend CI / build-android-apk (push) Successful in 1h16m45s

- 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:
lafay
2026-03-24 14:21:31 +08:00
parent b91e78c921
commit 2ddb9cadd8
111 changed files with 1829 additions and 3214 deletions

View File

@@ -21,8 +21,8 @@ import {
Dimensions,
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { useNavigation, useRoute, RouteProp, useFocusEffect } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { useFocusEffect } from '@react-navigation/native';
import { useLocalSearchParams, useRouter } from 'expo-router';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import * as ImagePicker from 'expo-image-picker';
import { colors, spacing, fontSizes, borderRadius, shadows } from '../../theme';
@@ -39,16 +39,14 @@ import {
JoinType,
} from '../../types/dto';
import { User } from '../../types';
import { RootStackParamList } from '../../navigation/types';
import { firstRouteParam } from '../../navigation/paramUtils';
import * as hrefs from '../../navigation/hrefs';
import { messageManager } from '../../stores/messageManager';
import { groupManager } from '../../stores/groupManager';
import MutualFollowSelectorModal from './components/MutualFollowSelectorModal';
const { width: SCREEN_WIDTH } = Dimensions.get('window');
type NavigationProp = NativeStackNavigationProp<RootStackParamList>;
type GroupInfoRouteProp = RouteProp<RootStackParamList, 'GroupInfo'>;
// 加群方式选项
const JOIN_TYPE_OPTIONS: { value: JoinType; label: string; icon: string; desc: string }[] = [
{ value: 0, label: '允许任何人加入', icon: 'earth', desc: '任何人都可以直接加入群聊' },
@@ -57,9 +55,13 @@ const JOIN_TYPE_OPTIONS: { value: JoinType; label: string; icon: string; desc: s
];
const GroupInfoScreen: React.FC = () => {
const navigation = useNavigation<NavigationProp>();
const route = useRoute<GroupInfoRouteProp>();
const { groupId, conversationId } = route.params;
const router = useRouter();
const { groupId: groupIdParam, conversationId: conversationIdParam } = useLocalSearchParams<{
groupId?: string | string[];
conversationId?: string | string[];
}>();
const groupId = firstRouteParam(groupIdParam) ?? '';
const conversationId = firstRouteParam(conversationIdParam);
const { currentUser } = useAuthStore();
// 响应式布局
@@ -112,6 +114,7 @@ const GroupInfoScreen: React.FC = () => {
// 加载群组信息
const loadGroupInfo = useCallback(async () => {
if (!groupId) return;
try {
setLoading(true);
@@ -138,7 +141,7 @@ const GroupInfoScreen: React.FC = () => {
} catch (error) {
console.error('加载群组信息失败:', error);
Alert.alert('错误', '加载群组信息失败', [
{ text: '确定', onPress: () => navigation.goBack() },
{ text: '确定', onPress: () => router.back() },
]);
} finally {
setLoading(false);
@@ -394,7 +397,7 @@ const GroupInfoScreen: React.FC = () => {
try {
await groupService.dissolveGroup(groupId);
Alert.alert('成功', '群组已解散', [
{ text: '确定', onPress: () => navigation.goBack() },
{ text: '确定', onPress: () => router.back() },
]);
} catch (error: any) {
console.error('解散群组失败:', error);
@@ -420,7 +423,7 @@ const GroupInfoScreen: React.FC = () => {
try {
await groupService.leaveGroup(groupId);
Alert.alert('成功', '已退出群聊', [
{ text: '确定', onPress: () => navigation.goBack() },
{ text: '确定', onPress: () => router.back() },
]);
} catch (error: any) {
console.error('退出群聊失败:', error);
@@ -464,7 +467,7 @@ const GroupInfoScreen: React.FC = () => {
// 跳转到成员管理
const goToMembers = () => {
navigation.navigate('GroupMembers' as any, { groupId });
router.push(hrefs.hrefGroupMembers(groupId));
};
// 获取加群方式文本
@@ -485,8 +488,8 @@ const GroupInfoScreen: React.FC = () => {
Alert.alert('已复制', '群号已复制到剪贴板');
};
const formatGroupNo = (id: string | number) => {
const raw = String(id);
const formatGroupNo = (id: string) => {
const raw = id;
if (raw.length <= 12) return raw;
return `${raw.slice(0, 6)}...${raw.slice(-4)}`;
};