-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
131 lines (117 loc) · 3.21 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
131
import React from 'react';
import {
ActivityIndicator,
Button,
StatusBar,
StyleSheet,
View,
} from 'react-native';
import {
createStackNavigator,
createSwitchNavigator,
createAppContainer,
} from 'react-navigation';
import LoginScreen from './src/screens/Login';
import ChatScreen from './src/screens/Chat';
import FriendScreen from './src/screens/Friend';
import QrCodeScreen from './src/screens/QrCode';
import AddFriendScreen from './src/screens/Friend/addFriend';
import RegisterScreen from './src/screens/Register';
import Permissions from 'react-native-permissions';
import AsyncStorage from '@react-native-community/async-storage';
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Welcome to the app!',
};
render() {
return (
<View style={styles.container}>
<Button title="Show me more of the app" onPress={this._showMoreApp} />
<Button title="Actually, sign me out :)" onPress={this._signOutAsync} />
</View>
);
}
_showMoreApp = () => {
this.props.navigation.navigate('Other');
};
_signOutAsync = async () => {
await AsyncStorage.clear();
this.props.navigation.navigate('Auth');
};
}
class OtherScreen extends React.Component {
static navigationOptions = {
title: 'Lots of features here',
};
render() {
return (
<View style={styles.container}>
<Button title="I'm done, sign me out" onPress={this._signOutAsync} />
<StatusBar barStyle="default" />
</View>
);
}
_signOutAsync = async () => {
await AsyncStorage.clear();
this.props.navigation.navigate('Auth');
};
}
class AuthLoadingScreen extends React.Component {
constructor() {
super();
this._bootstrapAsync();
}
// Fetch the token from storage then navigate to our appropriate place
_bootstrapAsync = async () => {
await Permissions.request('camera');
await Permissions.request('photo');
await Permissions.request('location');
const userToken = await AsyncStorage.getItem('userToken');
// This will switch to the App screen or Auth screen and this loading
// screen will be unmounted and thrown away.
this.props.navigation.navigate(userToken ? 'App' : 'Auth');
};
// Render any loading content that you like here
render() {
return (
<View style={styles.container}>
<ActivityIndicator />
<StatusBar barStyle="default" />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
});
const AppStack = createStackNavigator(
{
Chat: ChatScreen,
Friend: FriendScreen,
QrCode: QrCodeScreen,
AddFriend: AddFriendScreen,
},
{initialRouteName: 'Friend', headerMode: 'none'},
);
const AuthStack = createStackNavigator(
{LogIn: LoginScreen, Register: RegisterScreen},
{headerMode: 'none', initialRouteName: 'LogIn'},
);
//GLOBAL.XMLHttpRequest = GLOBAL.originalXMLHttpRequest || GLOBAL.XMLHttpRequest
console.disableYellowBox = true;
export default createAppContainer(
createSwitchNavigator(
{
AuthLoading: AuthLoadingScreen,
App: AppStack,
Auth: AuthStack,
},
{
initialRouteName: 'AuthLoading',
},
),
);