-
Notifications
You must be signed in to change notification settings - Fork 3
/
App.tsx
132 lines (125 loc) · 3.86 KB
/
App.tsx
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
import React, {useEffect, useReducer, useState} from 'react';
import {StatusBar, StyleSheet, Text, View} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import RegisterScreen from './pages/register/Register';
import SetupScreen from './pages/setup/Setup';
import SettingsScreen from './pages/settings/Settings';
import MainScreen from './pages/Main';
import MessagesScreen from './pages/messages/Messages';
import {ModalPortal} from 'react-native-modals';
import {checkUserexists} from './api/tokenManage';
import {serverInfoManage} from './api/realm/realmManage';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
const App = () => {
const [ifloggedin, setifloggedin] = useState(false);
const {getInfo} = serverInfoManage();
console.log('--reload--\n', ifloggedin, '\n--');
/*const isDarkMode = useColorScheme() === 'dark';
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};*/
useEffect(() => {
(async () => {
await checkIfloggedin();
})();
}, []);
const checkIfloggedin = async () => {
const a = await checkUserexists();
const b = await getInfo();
if (a && b) {
setifloggedin(true);
} else {
setifloggedin(false);
}
};
const config = {
screens: {
Setup: {
path: 'auth/:session?',
parse: {
session: (session: String) => `${session}`,
serverAddr: (serverAddr: String) => `${serverAddr}`,
},
},
},
};
const linking = {
prefixes: ['pingheng://'],
config,
};
const Stack = createNativeStackNavigator();
return (
/* <SafeAreaView style={backgroundStyle}>
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
</SafeAreaView>*/
<GestureHandlerRootView style={styles.container}>
<SafeAreaProvider>
<StatusBar animated={true} backgroundColor="rgb(19,20,26)" />
<NavigationContainer
linking={!ifloggedin && linking}
fallback={<Text>処理中...</Text>}>
<Stack.Navigator initialRouteName="Register">
{ifloggedin ? (
<>
<Stack.Screen
name="Main"
component={MainScreen}
options={{headerShown: false}}
/>
<Stack.Screen
name="Settings"
component={SettingsScreen}
options={{headerShown: false}}
/>
<Stack.Screen
name="Messages"
component={MessagesScreen}
options={{headerShown: false}}
/>
</>
) : (
<>
<Stack.Screen
name="Setup"
component={SetupScreen}
options={{headerShown: false}}
initialParams={{checkIfloggedin: checkIfloggedin}}
/>
<Stack.Screen
name="Register"
component={RegisterScreen}
options={{headerShown: false}}
/>
</>
)}
</Stack.Navigator>
<ModalPortal />
</NavigationContainer>
</SafeAreaProvider>
</GestureHandlerRootView>
);
};
const styles = StyleSheet.create({
container: {
backgroundColor: '#fff',
//alignitemあるとなんか動作しない
// alignItems: 'center',
justifyContent: 'center',
width: '100%',
flex: 1,
},
textareaContainer: {
height: 180,
padding: 4,
backgroundColor: '#F5FCFF',
},
textarea: {
textAlignVertical: 'top', // hack android
height: 170,
fontSize: 14,
color: '#333',
},
});
export default App;