-
Notifications
You must be signed in to change notification settings - Fork 431
Expand file tree
/
Copy pathAppNavigator.js
More file actions
409 lines (378 loc) · 11.9 KB
/
AppNavigator.js
File metadata and controls
409 lines (378 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
/**
* React Navigation v6 based router
* Replaces react-native-router-flux implementation
*/
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { StatusBar, Platform } from 'react-native';
import { SafeAreaProvider } from 'react-native-safe-area-context';
// Import all screen components
import DynamicPage from '../components/DynamicPage';
import LoginPage from '../components/LoginPage';
import LoginWebPage from '../components/LoginWebPage';
import MyPage from '../components/MyPage';
import PersonInfoPage from '../components/PersonInfoPage';
import PhotoPage from '../components/PhotoPage';
import AboutPage from '../components/AboutPage';
import NotifyPage from '../components/NotifyPage';
import IssueDetail from '../components/IssueDetailPage';
import VersionPage from '../components/ReleasePage';
import PersonPage from '../components/PersonPage';
import CodeDetailPage from '../components/CodeDetailPage';
import SettingPage from '../components/SettingPage';
import RepositoryDetail from '../components/RepositoryDetailPage';
import PushDetailPage from '../components/PushDetailPage';
import TrendPage from '../components/TrendPage';
import WebPage from '../components/WebPage';
import SearchPage from '../components/SearchPage';
import ListPage from '../components/ListPage';
import WelcomePage from '../components/WelcomePage';
// Import modal components
import TextInputModal from '../components/common/CommonTextInputModal';
import CommentConfirmModal from '../components/common/CommonConfirmModal';
import LoadingModal from '../components/common/LoadingModal';
import CommonOptionModal from '../components/common/CommonOptionModal';
// Import custom components
import TabIcon from '../components/widget/TabIcon';
import DrawerFilter from '../components/widget/SearchDrawerFilter';
import CustomBackButton from '../components/widget/CustomBackButton';
import CustomDrawerButton from '../components/widget/CustomDrawerButton';
import SearchButton from '../components/widget/CustomSearchButton';
import CommonIconButton from '../components/common/CommonIconButton';
// Import utilities and styles
import styles from '../style';
import I18n from '../style/i18n';
import * as Constant from '../style/constant';
import BackUtils from '../utils/backUtils';
import { CommonMoreRightBtnPress, RepositoryDetailRightBtnPress } from '../utils/actionUtils';
import { screenWidth, drawerWidth } from '../style/index';
import NavigationService from './NavigationService';
// Create navigators
const Stack = createStackNavigator();
const Tab = createBottomTabNavigator();
const Drawer = createDrawerNavigator();
const ModalStack = createStackNavigator();
// Default screen options
const getDefaultScreenOptions = () => ({
headerStyle: styles.navigationBar,
headerTitleStyle: { color: Constant.titleTextColor },
headerLeft: () => <CustomBackButton />,
});
// Tab Screen Component
function MainTabScreen() {
return (
<Tab.Navigator
screenOptions={{
tabBarStyle: {
height: Constant.tabBarHeight,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: Constant.tabBackgroundColor,
},
tabBarShowLabel: false,
headerStyle: styles.navigationBar,
headerTitleStyle: { color: Constant.titleTextColor },
headerRight: () => <SearchButton />,
}}
>
<Tab.Screen
name="DynamicPage"
component={DynamicPage}
options={{
title: I18n('tabDynamic'),
tabBarIcon: (props) => <TabIcon {...props} tabIconName="tabDynamic" />,
}}
/>
<Tab.Screen
name="TrendPage"
component={TrendPage}
options={{
title: I18n('tabRecommended'),
tabBarIcon: (props) => <TabIcon {...props} tabIconName="tabRecommended" />,
}}
/>
<Tab.Screen
name="MyPage"
component={MyPage}
options={{
title: I18n('tabMy'),
tabBarIcon: (props) => <TabIcon {...props} tabIconName="tabMy" />,
}}
/>
</Tab.Navigator>
);
}
// Search Drawer Component
function SearchDrawer() {
return (
<Drawer.Navigator
drawerContent={(props) => <DrawerFilter {...props} />}
screenOptions={{
drawerPosition: 'right',
drawerStyle: {
width: drawerWidth,
},
headerLeft: () => <CustomBackButton />,
headerShown: true,
}}
>
<Drawer.Screen
name="SearchPageInner"
component={SearchPage}
options={{
title: I18n('search'),
headerStyle: styles.navigationBar,
headerTitleStyle: { color: Constant.titleTextColor },
headerRight: () => <CustomDrawerButton />,
}}
/>
</Drawer.Navigator>
);
}
// Main Stack Navigator
function MainStack() {
const defaultScreenOptions = getDefaultScreenOptions();
return (
<Stack.Navigator
initialRouteName="WelcomePage"
screenOptions={defaultScreenOptions}
>
{/* Welcome Screen */}
<Stack.Screen
name="WelcomePage"
component={WelcomePage}
options={{ headerShown: false }}
/>
{/* Login Stack */}
<Stack.Screen
name="LoginPage"
component={LoginPage}
options={{ headerShown: false }}
/>
<Stack.Screen
name="LoginWebPage"
component={LoginWebPage}
options={{
title: I18n('Login'),
}}
/>
{/* Main App with Tabs */}
<Stack.Screen
name="MainTabs"
component={MainTabScreen}
options={{ headerShown: false }}
/>
{/* Individual Screens */}
<Stack.Screen
name="PersonPage"
component={PersonPage}
options={({ route }) => ({
headerRight: () => (
<CommonIconButton
data={{
needRightBtn: true,
rightBtn: 'ellipsis-horizontal-outline',
iconType: 2,
rightBtnPress: (params) => CommonMoreRightBtnPress(params),
...route.params,
}}
/>
),
})}
/>
<Stack.Screen
name="SettingPage"
component={SettingPage}
options={{ title: I18n('setting') }}
/>
<Stack.Screen
name="ListPage"
component={ListPage}
options={({ route }) => ({
headerRight: () => <CommonIconButton data={route.params} />,
})}
/>
<Stack.Screen
name="SearchPage"
component={SearchDrawer}
options={{
headerShown: false,
}}
/>
<Stack.Screen
name="RepositoryDetail"
component={RepositoryDetail}
options={({ route }) => ({
headerRight: () => (
<CommonIconButton
data={{
needRightBtn: true,
rightBtn: 'ellipsis-horizontal-outline',
iconType: 2,
rightBtnPress: (params) => RepositoryDetailRightBtnPress(params),
...route.params,
}}
/>
),
})}
/>
<Stack.Screen
name="IssueDetail"
component={IssueDetail}
options={({ route }) => ({
headerRight: () => (
<CommonIconButton
data={{
needRightBtn: true,
rightBtn: 'ellipsis-horizontal-outline',
iconType: 2,
rightBtnPress: (params) => CommonMoreRightBtnPress(params),
...route.params,
}}
/>
),
})}
/>
<Stack.Screen
name="PushDetailPage"
component={PushDetailPage}
options={({ route }) => ({
headerRight: () => (
<CommonIconButton
data={{
needRightBtn: true,
rightBtn: 'ellipsis-horizontal-outline',
iconType: 2,
rightBtnPress: (params) => CommonMoreRightBtnPress(params),
...route.params,
}}
/>
),
})}
/>
<Stack.Screen
name="VersionPage"
component={VersionPage}
options={({ route }) => ({
headerRight: () => <CommonIconButton data={route.params} />,
})}
/>
<Stack.Screen
name="NotifyPage"
component={NotifyPage}
options={({ route }) => ({
title: I18n('notify'),
headerRight: () => <CommonIconButton data={route.params} />,
})}
/>
<Stack.Screen
name="CodeDetailPage"
component={CodeDetailPage}
options={({ route }) => ({
title: I18n('notify'),
headerRight: () => (
<CommonIconButton
data={{
needRightBtn: true,
rightBtn: 'ellipsis-horizontal-outline',
iconType: 2,
rightBtnPress: (params) => CommonMoreRightBtnPress(params),
...route.params,
}}
/>
),
})}
/>
<Stack.Screen
name="AboutPage"
component={AboutPage}
options={{ title: I18n('about') }}
/>
<Stack.Screen
name="PersonInfoPage"
component={PersonInfoPage}
options={{ title: I18n('about') }}
/>
<Stack.Screen
name="WebPage"
component={WebPage}
options={{ headerShown: false }}
/>
<Stack.Screen
name="PhotoPage"
component={PhotoPage}
options={{ headerShown: false }}
/>
</Stack.Navigator>
);
}
// Root Modal Stack Navigator
function RootNavigator() {
return (
<ModalStack.Navigator
screenOptions={{ presentation: 'modal', headerShown: false }}
>
<ModalStack.Screen name="Main" component={MainStack}
options={{
presentation: 'transparentModal', // 设置为透明模态
cardStyle: { backgroundColor: 'transparent' }, // 确保卡片背景透明
}}
/>
<ModalStack.Screen name="LoadingModal" component={LoadingModal}
options={{
presentation: 'transparentModal', // 设置为透明模态
cardStyle: { backgroundColor: 'transparent' }, // 确保卡片背景透明
}}
/>
<ModalStack.Screen name="TextInputModal" component={TextInputModal}
options={{
presentation: 'transparentModal', // 设置为透明模态
cardStyle: { backgroundColor: 'transparent' }, // 确保卡片背景透明
}}
/>
<ModalStack.Screen name="ConfirmModal" component={CommentConfirmModal}
options={{
presentation: 'transparentModal', // 设置为透明模态
cardStyle: { backgroundColor: 'transparent' }, // 确保卡片背景透明
}}
/>
<ModalStack.Screen name="OptionModal" component={CommonOptionModal}
options={{
presentation: 'transparentModal', // 设置为透明模态
cardStyle: { backgroundColor: 'transparent' }, // 确保卡片背景透明
}}
/>
</ModalStack.Navigator>
);
}
// Main Navigation Container
export default function AppNavigator() {
const navigationRef = React.useRef(null);
const onReady = () => {
NavigationService.setNavigatorRef(navigationRef.current);
};
const onStateChange = (state) => {
const currentRouteName = state?.routes[state.index]?.name;
NavigationService.setCurrentRoute({ name: currentRouteName });
};
return (
<SafeAreaProvider>
<StatusBar
hidden={false}
backgroundColor={'transparent'}
translucent
barStyle={'light-content'}
/>
<NavigationContainer
ref={navigationRef}
onReady={onReady}
onStateChange={onStateChange}
>
<RootNavigator />
</NavigationContainer>
</SafeAreaProvider>
);
}