forked from expo/expo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHomeApp.js
123 lines (108 loc) · 3.37 KB
/
HomeApp.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
import { AppLoading, Asset, Constants, Font } from 'expo';
import React from 'react';
import { ActivityIndicator, Linking, Platform, StatusBar, StyleSheet, View } from 'react-native';
import url from 'url';
import { ActionSheetProvider } from '@expo/react-native-action-sheet';
import { Ionicons, MaterialIcons } from '@expo/vector-icons';
import { Assets as StackAssets } from 'react-navigation-stack';
import jwtDecode from 'jwt-decode';
import Navigation from './navigation/Navigation';
import HistoryActions from './redux/HistoryActions';
import SessionActions from './redux/SessionActions';
import SettingsActions from './redux/SettingsActions';
import LocalStorage from './storage/LocalStorage';
import MenuView from './menu/MenuView';
import Store from './redux/Store';
import addListenerWithNativeCallback from './utils/addListenerWithNativeCallback';
function cacheImages(images) {
return images.map(image => Asset.fromModule(image).downloadAsync());
}
// Download and cache stack assets, don't block loading on this though
Asset.loadAsync(StackAssets);
export default class App extends React.Component {
state = {
isReady: false,
};
componentDidMount() {
this._initializeStateAsync();
}
_isExpoHost = host => {
return (
host === 'exp.host' ||
host === 'expo.io' ||
host === 'exp.direct' ||
host === 'expo.test' ||
host.endsWith('.exp.host') ||
host.endsWith('.expo.io') ||
host.endsWith('.exp.direct') ||
host.endsWith('.expo.test')
);
};
_isThirdPartyHosted = urlToCheck => {
if (!urlToCheck) {
return false;
}
const urlComponents = url.parse(urlToCheck);
const host = urlComponents.host;
if (!host) {
return false;
}
return !this._isExpoHost(host);
};
_initializeStateAsync = async () => {
try {
Store.dispatch(SettingsActions.loadSettings());
Store.dispatch(HistoryActions.loadHistory());
await LocalStorage.migrateNuxStateToNativeAsync();
const storedSession = await LocalStorage.getSessionAsync();
if (storedSession) {
Store.dispatch(SessionActions.setSession(storedSession));
}
if (Platform.OS === 'ios') {
await Promise.all([Font.loadAsync(Ionicons.font)]);
} else {
await Promise.all([Font.loadAsync(Ionicons.font), Font.loadAsync(MaterialIcons.font)]);
}
} catch (e) {
// ..
} finally {
this.setState({ isReady: true }, async () => {
if (Platform.OS == 'ios') {
// if expo client is opened via deep linking, we'll get the url here
const initialUrl = await Linking.getInitialURL();
if (initialUrl) {
Linking.openURL(initialUrl);
}
}
});
}
};
render() {
if (!this.state.isReady) {
return <AppLoading />;
}
return (
<View style={styles.container}>
<ActionSheetProvider>
<Navigation />
</ActionSheetProvider>
{Platform.OS === 'ios' && <StatusBar barStyle="default" />}
{Platform.OS === 'android' && <View style={styles.statusBarUnderlay} />}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
statusBarUnderlay: {
height: Constants.statusBarHeight,
backgroundColor: 'rgba(0,0,0,0.2)',
position: 'absolute',
top: 0,
left: 0,
right: 0,
},
});