-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
130 lines (107 loc) · 3.22 KB
/
App.js
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
import 'react-native-gesture-handler';
import React,{useEffect} from 'react';
import { View } from 'react-native';
import {
NavigationContainer,
DarkTheme as NavigationDarkTheme,
DefaultTheme as NavigationDefaultTheme
} from '@react-navigation/native';
import {createDrawerNavigator} from '@react-navigation/drawer';
import { ActivityIndicator } from 'react-native-paper';
import {
Provider as PaperProvider ,
DarkTheme as PaperDarkTheme,
DefaultTheme as PaperDefaultTheme
} from 'react-native-paper';
import {DrawerContent} from './screens/DrawerContent';
import DetailsScreen from './screens/DetailsScreen';
import MainTabScreen from './screens/MainTabScreen';
import ContactUs from './screens/ContactUs';
import Settings from './screens/Settings';
import Help from './screens/Help';
import RootStackScreen from './screens/RootStackScreen';
import {AuthContext} from './components/Context';
const Drawer=createDrawerNavigator();
const App=()=>{
const [isLoading,setIsLoading]=React.useState(true);
const [userToken,setUserToken]=React.useState(null);
const [isDarkTheme,setIsDarkTheme]=React.useState(false);
const CustomDefaultTheme={
...NavigationDefaultTheme,
...PaperDefaultTheme,
colors:{
...NavigationDefaultTheme.colors,
...PaperDefaultTheme.colors,
background:'#ffffff',
text:'#333333'
}
}
const CustomDarkTheme={
...NavigationDarkTheme,
...PaperDarkTheme,
colors:{
...NavigationDarkTheme.colors,
...PaperDarkTheme.colors,
background:'#333333',
text:'#ffffff'
}
}
const theme=isDarkTheme ? CustomDarkTheme : CustomDefaultTheme;
//if isDarkTheme is true to CustomDarkTheme them switch to dark mode otherwise set to CustomDefaultTheme
const authContext=React.useMemo(()=>
({
cancelCross:()=>{
setUserToken('asaas');
setIsLoading(false);
},
signIn:()=>{
setUserToken('aaaa');
setIsLoading(false);
},
signOut:()=>{
setUserToken(null);
setIsLoading(false);
},
signUp:()=>{
setUserToken('aaaa');
setIsLoading(false);
},
toggleTheme:()=>{
setIsDarkTheme(isdarkTheme=> !isdarkTheme);
}
})
,[])
// in useMemo i pass an empty array ,[] in last line to pass doesn't run every time , we render the screen
useEffect(()=>{
setTimeout(()=>{
setIsLoading(false)
},1000)
},[]);
if(isLoading){
return(
<View style={{flex:1,justifyContent:"center",alignItems:"center"}} >
<ActivityIndicator size="large"/>
</View>
);
}
return(
<PaperProvider theme={theme}>
<AuthContext.Provider value={authContext}>
<NavigationContainer theme={theme}>
{userToken != null?(
<Drawer.Navigator drawerContent={props => <DrawerContent {...props} />}>
<Drawer.Screen name="HomeDrawer" component={MainTabScreen} />
<Drawer.Screen name="Help" component={Help} />
<Drawer.Screen name="ContactUs" component={ContactUs} />
<Drawer.Screen name="Settings" component={Settings} />
</Drawer.Navigator>
)
:
<RootStackScreen />
}
</NavigationContainer>
</AuthContext.Provider>
</PaperProvider>
)
}
export default App;