-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
129 lines (120 loc) · 3.94 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
import React,{useEffect,useContext} from 'react';
import {
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
Platform,
ToastAndroid
} from 'react-native';
import { NavigationContainer,DarkTheme as NavigationDarkTheme,DefaultTheme as NavigationDefaultTheme } from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import LoginHomeStack from './screens/stackComponent';
import OnboardingScreen from './screens/OnboardScreen';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { SafeAreaProvider,SafeAreaView} from 'react-native-safe-area-context';
import NetInfo from '@react-native-community/netinfo';
import { useTheme } from '@react-navigation/native';
import {ThemeManagerContext} from './components/authContext/AuthContext';
import SplashScreen from 'react-native-splash-screen';
const STATUSBAR_HEIGHT = Platform.OS === 'ios' ? 20 : StatusBar.currentHeight;
const AppStack=createStackNavigator();
export const CustomDefaultTheme = {
...NavigationDefaultTheme,
colors: {
...NavigationDefaultTheme.colors,
primary: 'rgb(255, 45, 85)',
background:'#ffffff',
text:'#333333'
},
};
export const CustomDarkTheme = {
...NavigationDarkTheme,
colors: {
...NavigationDarkTheme.colors,
primary: 'rgb(255, 45, 85)',
background:'#333333',
text:'#ffffff'
},
};
const App=(props) => {
const {isDark}=useContext(ThemeManagerContext);
const [isFirstLaunch,setIsFirstLaunch]=React.useState(true);
const handleConnectivityChange=(connectionInfo)=>{
switch(connectionInfo.type){
case 'none':
return ToastAndroid.show('You are now offline!',ToastAndroid.LONG);
break;
case 'wifi':
return ToastAndroid.show('You are now connected to wifi',ToastAndroid.LONG);
break;
case 'cellular':
return ToastAndroid.show('You are now conneted to cellular',ToastAndroid.LONG);
break;
case 'unknown':
return ToastAndroid.show('You are now have an unknown connection',ToastAndroid.LONG);
break;
default:
break;
}
}
useEffect(()=>{
SplashScreen.hide();
AsyncStorage.getItem('alreadyLaunched').then(value=>{
if(value===null){
AsyncStorage.setItem('alreadyLaunched','true');
setIsFirstLaunch(true);
}else{
setIsFirstLaunch(false);
}
});
NetInfo.fetch()
.then((connectionInfo)=>{
if(connectionInfo.type==='cellular'){
ToastAndroid.show('Intial Network Connectivity Type:'
+ connectionInfo.type+', Connection:'+ connectionInfo.isConnected+', Carrier :'+connectionInfo.details.carrier,
ToastAndroid.LONG)
}else{
ToastAndroid.show('Intial Network Connectivity Type:'
+ connectionInfo.type+', Connection:'+ connectionInfo.isConnected+', Strength :'+connectionInfo.details.strength,
ToastAndroid.LONG)
}
});
window.value=NetInfo.addEventListener(connectionChange=>handleConnectivityChange(connectionChange));
},[isFirstLaunch,window.value]);
if(isFirstLaunch===null){
return null;
}else{
return (
<SafeAreaProvider>
<StatusBar backgroundColor="#004ba0" barStyle="light-content" style={styles.statusBar}/>
<NavigationContainer theme={isDark?CustomDarkTheme:CustomDefaultTheme}>
{
(isFirstLaunch===true)?(
<AppStack.Navigator
headerMode="none"
>
<AppStack.Screen name="Onboarding" component={OnboardingScreen} />
<AppStack.Screen name="Login" component={LoginHomeStack} />
</AppStack.Navigator>
):(
<AppStack.Navigator
headerMode="none"
>
<AppStack.Screen name="Login" component={LoginHomeStack} />
</AppStack.Navigator>
)
}
</NavigationContainer>
</SafeAreaProvider>
);
}
};
const styles=StyleSheet.create({
statusBar:{
flex:0,
height:STATUSBAR_HEIGHT
}
})
export default App;