-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
160 lines (148 loc) · 4.29 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import React, { PureComponent, Fragment } from 'react'
import { Image, Easing, Platform, Dimensions, StyleSheet, View, Animated, BackHandler } from 'react-native'
import { Asset, Font, SplashScreen } from 'expo'
import { Provider as ReduxProvider } from 'react-redux'
import NativeTachyons from 'react-native-style-tachyons'
import { PersistGate } from 'redux-persist/integration/react'
import { store, persistor } from 'store'
import App from 'screens/App'
import { customStyles, colors } from 'styles'
import { purgeStoredState } from 'redux-persist'
import * as Animatable from 'react-native-animatable'
import { wrap } from 'react-native-style-tachyons'
console.disableYellowBox = true
// Styles
NativeTachyons.build({
rem: 18,
clsPropName: "cls",
colors: {
palette: {
...colors,
}
},
customStyles: {
...customStyles,
}
}, StyleSheet)
// persistor.purge() uncomment this to empty your localstorage
export default wrap (
class Khimera extends PureComponent {
state = {
ready: false,
splashAnimation: new Animated.Value(0),
splashAnimationComplete: false,
}
componentDidMount() {
this._loadAsync()
Platform.OS === 'android' && BackHandler.addEventListener('hardwareBackPress', () => true)
}
_loadAsync = async () => {
try {
await this._loadResourcesAsync()
} catch (e) {
console.warn(e)
} finally {
this._handleFinishLoading()
}
}
_loadResourcesAsync = async () => {
return Promise.all([
Asset.loadAsync([
require('./assets/splash.png'),
require('./assets/images/permission.png'),
require('./assets/images/pairing.png'),
require('./assets/images/success.png'),
require('./assets/images/intro.png'),
require('./assets/images/profiles.png'),
require('./assets/images/emotion.png'),
require('./assets/images/translate.png'),
require('./assets/images/learn.png'),
require('./assets/images/data.png'),
require('./assets/images/empty_data.png'),
]),
Font.loadAsync({
'text': require('./assets/fonts/Lato-Regular.ttf'),
'textItalic': require('./assets/fonts/Lato-Italic.ttf'),
'textBold': require('./assets/fonts/Lato-Bold.ttf'),
'textLogo': require('./assets/fonts/Dosis-Regular.ttf'),
}),
])
}
_handleFinishLoading = () => {
this.setState({ ready: true })
}
_animateOut = () => {
SplashScreen.hide()
Animated.timing(this.state.splashAnimation, {
toValue: Dimensions.get('window').width * -1,
duration: 750,
useNativeDriver: true,
}).start(() => {
this.setState({ splashAnimationComplete: true });
})
}
_handleAnimatableSplashRef = ref => this.view = ref
_maybeRenderLoadingImage = () => {
if (this.state.splashAnimationComplete) {
return null
}
return (
<Animated.View
cls="absolute bg-yellow-100 aic jcc "
style={{
top: 0,
left: 0,
bottom: 0,
right: 0,
backgroundColor: '#F5FF86',
opacity: this.state.splashAnimation.interpolate({
inputRange: [0, 1],
outputRange: [1, 0],
}),
transform: [{
translateX: this.state.splashAnimation.interpolate({
inputRange: [0, 1],
outputRange: [-1, 0],
}),
}]
}}>
<Animated.Image
source={require('./assets/splash.png')}
style={{
width: undefined,
height: undefined,
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
resizeMode: 'contain',
transform: [{
scale: this.state.splashAnimation.interpolate({
inputRange: [0, 1],
outputRange: [0, 0]
}),
}]
}}
onLoadEnd={this._animateOut}
/>
</Animated.View>
)
}
render() {
if (this.state.ready === false ) {
return <View />
}
return (
<View cls="flx-i">
<ReduxProvider store={store}>
<PersistGate loading={null} persistor={persistor}>
<App />
</PersistGate>
</ReduxProvider>
{this._maybeRenderLoadingImage()}
</View>
)
}
}
)