-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
120 lines (106 loc) · 3.77 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
import {
PTSans_400Regular,
PTSans_700Bold,
useFonts,
} from "@expo-google-fonts/pt-sans";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import React, { useEffect, useState } from "react";
import { ActivityIndicator, StatusBar, View } from "react-native";
import "react-native-gesture-handler";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { ThemeProvider } from "styled-components/native";
import { PugText, PugTextInput } from "./components/Text/Text";
import { AppProvider, useAppContext } from "./context/AppContext";
import { FeedProvider } from "./context/FeedContext";
import TabNavigation from "./navigation/TabNavigation/TabNavigation";
import ServerScreen from "./screens/ServerScreen/ServerScreen";
import WebViewScreen from "./screens/WebViewScreen/WebViewScreen";
import { RootStackParamList } from "./screens/types";
import TootScreen from "./screens/TootScreen/TootScreen";
const AppContent = () => {
const { theme } = useAppContext();
const [initialRoute, setInitialRoute] = useState<
keyof RootStackParamList | undefined
>(undefined);
const [loading, setLoading] = useState(true);
const Stack = createNativeStackNavigator<RootStackParamList>();
const { setAppParam } = useAppContext();
useEffect(() => {
const checkUserAuthentication = async () => {
const userInfo = await AsyncStorage.getItem("userInfo");
try {
if (userInfo) {
const parsedUserInfo = JSON.parse(userInfo);
setAppParam("username", parsedUserInfo.username);
setAppParam("avatar", parsedUserInfo.avatar);
setAppParam("apiBaseUrl", parsedUserInfo.serverUrl);
setAppParam("accessToken", parsedUserInfo.accessToken);
setInitialRoute("TabNavigation");
} else {
setInitialRoute("Server");
}
} catch (error) {
console.error("Error checking user authentication:", error);
setInitialRoute("Server");
} finally {
setLoading(false);
}
};
checkUserAuthentication();
}, [loading]);
if (loading) {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<ActivityIndicator size="large" color="#0000ff" />
</View>
);
}
return (
<ThemeProvider theme={theme}>
<StatusBar
barStyle={
theme.backgroundColor === "#1C1C1E" ? "light-content" : "dark-content"
}
/>
<NavigationContainer>
<Stack.Navigator
initialRouteName={initialRoute}
screenOptions={{ headerShown: false }}
>
<Stack.Screen name="TabNavigation" component={TabNavigation} />
<Stack.Screen name="Server" component={ServerScreen} />
<Stack.Screen name="WebView" component={WebViewScreen} />
</Stack.Navigator>
</NavigationContainer>
</ThemeProvider>
);
};
const App = () => {
const [fontsLoaded] = useFonts({
PTSans_400Regular,
PTSans_700Bold,
});
if (!fontsLoaded) {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<ActivityIndicator size="large" color="#0000ff" />
</View>
);
}
PugText.defaultProps = PugText.defaultProps || {};
PugText.defaultProps.style = { fontFamily: "PTSans_400Regular" };
PugTextInput.defaultProps = PugTextInput.defaultProps || {};
PugTextInput.defaultProps.style = { fontFamily: "PTSans_400Regular" };
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<AppProvider>
<FeedProvider>
<AppContent />
</FeedProvider>
</AppProvider>
</GestureHandlerRootView>
);
};
export default App;