-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
97 lines (89 loc) 路 3.33 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
import React from "react";
import { NavigationContainer } from "@react-navigation/native";
import { Provider as ReduxProvider } from "react-redux";
import { createStackNavigator } from "@react-navigation/stack";
import * as eva from "@eva-design/eva";
import { EvaIconsPack } from "@ui-kitten/eva-icons";
import { ApplicationProvider, IconRegistry } from "@ui-kitten/components";
import { HomeScreen } from "./src/screens/HomeScreen";
import { Store, useSelector } from "./src/utils/redux/Store";
import { LoginScreen } from "./src/screens/LoginScreen";
import { default as Colors } from "./src/theme/Colors.json";
import { RegisterScreen } from "./src/screens/RegisterScreen";
import { checkPreviousSession } from "./src/utils/helpers/SessionHelper";
import { ErrorModalInjector } from "./src/components/ModalError";
import { SuccessModalInjector } from "./src/components/ModalSuccess";
import { DeepLinking } from "./src/components/DeepLinking";
import { ActivateScreen } from "./src/screens/ActivateScreen";
import { ActivationModalInjector } from "./src/components/ModalActivation";
import { LogoutScreen } from "./src/screens/LogoutScreen";
import { BackHandler } from "react-native";
const Stack = createStackNavigator();
function RootStack() {
const isAuthenticated = useSelector((state) => state.auth.isAuthenticated);
const activation = useSelector((state) => state.auth.activation);
const error = useSelector((state) => state.globalError);
const success = useSelector((state) => state.globalSuccess);
const [loading, setLoading] = React.useState(true);
React.useEffect(() => {
const handleBackButton = () => {
return true;
};
BackHandler.addEventListener("hardwareBackPress", handleBackButton);
return () => {
BackHandler.removeEventListener("hardwareBackPress", handleBackButton);
};
}, []);
React.useEffect(() => {
const checkSession = async () => {
try {
await checkPreviousSession();
} finally {
setLoading(false);
}
};
checkSession();
}, []);
const LogoutScreenWrapper = ({ ...props }) => {
return <LogoutScreen {...props} loading={loading} />;
};
return (
<>
<IconRegistry icons={EvaIconsPack} />
<ApplicationProvider {...eva} theme={{ ...eva.light, ...Colors }}>
{!!error.name && (
<ErrorModalInjector title={error.name} message={error.message} />
)}
{!!success.name && (
<SuccessModalInjector
title={success.name}
message={success.message}
/>
)}
<NavigationContainer>
<Stack.Navigator
initialRouteName={
loading ? "Logout" : isAuthenticated ? "Home" : "Login"
}
headerMode="none"
>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen name="Register" component={RegisterScreen} />
<Stack.Screen name="Logout" component={LogoutScreenWrapper} />
<Stack.Screen name="Activate" component={ActivateScreen} />
</Stack.Navigator>
</NavigationContainer>
</ApplicationProvider>
</>
);
}
export class App extends React.Component {
render() {
return (
<ReduxProvider store={Store}>
<RootStack />
</ReduxProvider>
);
}
}