This repository has been archived by the owner on Apr 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathApp.js
63 lines (56 loc) · 1.71 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
import Expo, { AppLoading, Asset, Font, Constants } from 'expo'
import React from 'react'
import { Platform, StatusBar, View } from 'react-native'
import { ThemeProvider } from 'styled-components'
import { ApolloProvider } from 'react-apollo'
import { client, theme } from './utils'
import AppNav from './navigation'
export default class App extends React.Component {
state = {
isLoading: true,
}
componentWillMount() {
this._loadAssetsAsync()
}
cacheImages = images => {
return images.map(image => {
if (typeof image === 'string') {
return Image.prefetch(image)
} else {
return Asset.fromModule(image).downloadAsync()
}
})
}
cacheFonts = fonts => {
return fonts.map(font => Font.loadAsync(font))
}
async _loadAssetsAsync() {
const imageAssets = this.cacheImages([
require('./assets/icons/app.png'),
require('./assets/icons/loading.png'),
require('./assets/icons/yaba_logo.png'),
])
const fontAssets = this.cacheFonts([
{ 'os-bold': require('./assets/fonts/OpenSans-Bold.ttf') },
{ 'os-reg': require('./assets/fonts/OpenSans-Regular.ttf') },
{ 'os-lite': require('./assets/fonts/OpenSans-Light.ttf') },
])
await Promise.all([...imageAssets, ...fontAssets])
this.setState({ isLoading: false })
}
render() {
if (this.state.isLoading) {
return <AppLoading />
}
return (
<ThemeProvider theme={theme}>
<ApolloProvider client={client}>
<View style={{ flex: 1 }}>
{Platform.OS === 'ios' && <StatusBar barStyle="light-content" />}
<AppNav screenProps={{ theme }} />
</View>
</ApolloProvider>
</ThemeProvider>
)
}
}