AppNavigationContainer.tsx
5.1 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
import React from 'react';
import {
NavigationContainer,
RouteProp,
TabNavigationState,
} from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import {
createStackNavigator,
HeaderStyleInterpolators,
} from '@react-navigation/stack';
import Ionicons from 'react-native-vector-icons/Ionicons';
import {
MainTabParamList,
MainStackParamList,
AuthStackParamList,
} from '../type/Navigation';
import SystemInfo from './SystemInfo';
import DesignList from './DesignList';
import { useDarkMode } from 'react-native-dark-mode';
import { themeForNav } from '../design';
import RNDeviceInfoList from './RNDeviceInfo';
import WebviewScreen from './WebviewScreen';
import { Platform } from 'react-native';
import RNLocalize from './RNLocalize';
import { useI18nStrings } from '../i18n';
import CameraScreen from './CameraScreen';
import Library from './Library';
import ReadableCode from './ReadableCode';
import { useDeepLinking } from '../utility/handleDeepLinking';
import { navigationRef, useMountedRef } from '../utility/rootNavigation';
import ShortcutPage from './ShortcutItem';
import useQuickAction from '../utility/useQuickAction';
import { useReduxState } from '../store/hooks';
import LoginScreen from './Login';
import MeScreen from './Me';
const MainTab = createBottomTabNavigator<MainTabParamList>();
function getTabHeader(
route: RouteProp<MainStackParamList, 'MainTab'> & {
state?: TabNavigationState;
}
) {
const { state } = route;
if (!state) return 'Library';
const { routeNames, index } = state;
const routeName = routeNames[index] as keyof MainTabParamList;
return routeName;
}
const Home = () => {
return (
<MainTab.Navigator
screenOptions={({ route }) => {
const routeName = route.name;
return {
tabBarIcon: ({ focused, size, color }) => {
switch (routeName) {
case 'SystemInfo':
return (
<Ionicons
size={size}
color={color}
name={
focused
? 'ios-information-circle'
: 'ios-information-circle-outline'
}
/>
);
case 'DesignList':
return (
<Ionicons
size={size}
color={color}
name={'ios-color-palette'}
/>
);
case 'Library':
return (
<Ionicons
size={size}
color={color}
name={focused ? 'ios-list-box' : 'ios-list'}
/>
);
case 'Me':
return (
<Ionicons size={size} color={color} name={'ios-person'} />
);
default:
break;
}
},
};
}}
>
<MainTab.Screen name="Library" component={Library} />
<MainTab.Screen name="SystemInfo" component={SystemInfo} />
<MainTab.Screen name="DesignList" component={DesignList} />
<MainTab.Screen name="Me" component={MeScreen} />
</MainTab.Navigator>
);
};
const MainStack = createStackNavigator<MainStackParamList>();
const AuthStack = createStackNavigator<AuthStackParamList>();
const Container = () => {
const inDarkMode = useDarkMode();
const strings = useI18nStrings();
const user = useReduxState('user');
useMountedRef();
useDeepLinking();
useQuickAction();
return (
<NavigationContainer
ref={navigationRef}
theme={inDarkMode ? themeForNav.dark : themeForNav.light}
>
{user.token ? (
<MainStack.Navigator
screenOptions={{
headerStyleInterpolator: HeaderStyleInterpolators.forUIKit,
headerTruncatedBackTitle: strings.navigation.back,
}}
>
<MainStack.Screen
name="MainTab"
component={Home}
options={({ route }) => {
return { headerTitle: getTabHeader(route) };
}}
/>
<MainStack.Screen
name="RNDeviceInfoList"
component={RNDeviceInfoList}
/>
<MainStack.Screen
name="WebviewScreen"
component={WebviewScreen}
options={({ navigation, route }) => ({
// FIXME: https://github.com/react-native-community/react-native-webview/issues/575#issuecomment-587267906
animationEnabled: Platform.OS === 'ios',
})}
/>
<MainStack.Screen name="RNLocalize" component={RNLocalize} />
<MainStack.Screen name="RNCamera" component={CameraScreen} />
<MainStack.Screen name="RNCode" component={ReadableCode} />
<MainStack.Screen name="ShortcutItem" component={ShortcutPage} />
</MainStack.Navigator>
) : (
<AuthStack.Navigator>
<AuthStack.Screen name="Login" component={LoginScreen} />
</AuthStack.Navigator>
)}
</NavigationContainer>
);
};
export default Container;