-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
77 lines (66 loc) · 2.32 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
/* eslint-disable prettier/prettier */
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import React, { useEffect, useState } from 'react';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { NavigationContainer } from '@react-navigation/native';
import SignUpScreen from './Screens/SignUpScreen';
import BottomNavigation from './Screens/BottomNavigation';
import LoginScreen from './Screens/LoginScreen';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { Provider } from 'react-redux';
import store from './src/store';
const Stack = createNativeStackNavigator();
const App = () => {
const [isLoggediN, updateLoggedIn] = useState<boolean | null>(null);
useEffect(() => {
const fetchCredentials = async () => {
try {
const storedEmail = await AsyncStorage.getItem('Email');
if(storedEmail?.length !== undefined){
updateLoggedIn(true);
console.log('isLN', isLoggediN);
console.log('storedEmail?.length', storedEmail?.length);
}
else{
updateLoggedIn(false);
console.log('storedEmail?.length !== undefined', storedEmail === null);
}
console.log('Stored email:', storedEmail);
console.log('isLoggediN', isLoggediN);
console.log('abc', isLoggediN !== true);
} catch (error) {
console.error('Error fetching tasks', error);
}
};
fetchCredentials();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
if (isLoggediN === null) {
return null;
}
// if (initialRoute === undefined) {
// return (
// <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
// <ActivityIndicator size="large" color="#0000ff" />
// <Text>Loading...</Text>
// </View>
// );
// }
return (
<Provider store={store}>
<NavigationContainer>
<Stack.Navigator screenOptions={{ headerShown: false }} initialRouteName={isLoggediN ? 'BottomTab' : 'Login'}>
<Stack.Screen name="BottomTab" component={BottomNavigation} />
<Stack.Screen name="SignUp" component={SignUpScreen} />
<Stack.Screen name="Login" component={LoginScreen} />
</Stack.Navigator>
</NavigationContainer>
</Provider>
);
};
export default App;