-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
85 lines (74 loc) · 2.64 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
import React from 'react'
import { Font, AppLoading} from 'expo'
import { Provider } from 'react-redux'
import {StatusBar, View, StyleSheet} from 'react-native'
import createStore from './src/utils/store'
import MainNavigator from './src/screens/MainNavigator'
import {STATUS_BAR_HEIGHT} from './src/utils/constants'
import getTheme from './native-base-theme/components'
import material from './native-base-theme/variables/material'
import { StyleProvider, Root } from 'native-base'
import {getCurrentUser} from "./src/api/auth"
import {getFeaturedVideo} from "./src/api/video";
const styles = StyleSheet.create({
statusBar: {
height: STATUS_BAR_HEIGHT,
}
})
const CustomStatusBar = ({backgroundColor, ...props}) => (
<View style={[styles.statusBar, { backgroundColor: '#3F51B5' }]}>
<StatusBar barStyle="light-content" translucent backgroundColor="#3F51B5" {...props} />
</View>
)
export default class App extends React.Component {
state = {
isReady: false,
error: null,
currentUser: null,
featuredVideo: null,
}
async componentDidMount () {
await Font.loadAsync({
'roboto': require('./assets/fonts/Roboto.ttf'),
'roboto-medium': require('./assets/fonts/Roboto_medium.ttf'),
'roboto-mono-bold': require('./assets/fonts/Roboto_Mono_Bold.ttf'),
'niramid-regular': require('./assets/fonts/Niramit-Regular.ttf'),
'niramid-medium': require('./assets/fonts/Niramit-Medium.ttf'),
'niramid-bold': require('./assets/fonts/Niramit-Bold.ttf'),
})
const userResponse = await getCurrentUser()
const videoResponse = await getFeaturedVideo()
this.setState({
currentUser: userResponse.email ? userResponse : null,
featuredVideo: videoResponse.data ? videoResponse.data : null,
isReady: true,
})
}
render () {
const {isReady, currentUser, featuredVideo} = this.state
if (!isReady) return <AppLoading />
const store = createStore({
auth: { current: currentUser },
video: {
list: {
data: [],
fetching: false,
error: null,
hasMore: true,
},
featured: featuredVideo
}
})
const RenderedMainNavigator = MainNavigator({ loggedIn: Boolean(currentUser) })
return (
<Provider store={store}>
<StyleProvider style={getTheme(material)}>
<Root>
<CustomStatusBar />
<RenderedMainNavigator />
</Root>
</StyleProvider>
</Provider>
)
}
}