-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
129 lines (111 loc) · 2.76 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
import React from 'react';
import {
Animated,
Easing,
Platform,
StatusBar,
StyleSheet,
Text,
View,
} from 'react-native';
import { Header } from 'react-navigation';
import BackboneEvents from 'backbone-events-standalone';
import Banner from './components/common/Banner';
import SplashNavigator from './components/splash/SplashNavigator';
import Colors from './constants/Colors';
import UIConstants from './constants/UIConstants';
// global event bus
window.EventBus = BackboneEvents.mixin({});
// Remove dynamic typing of text sizes (iOS only)
Text.defaultProps.allowFontScaling = false;
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
bannerType: '',
bannerMessage: '',
showerBanner: false,
}
this.animatedValue = new Animated.Value(0);
window.showBanner = this.showBanner;
}
showBanner = (type, message) => {
this.setState({
bannerType: type,
bannerMessage: message,
showBanner: true,
}, () => {
this.animatedValue.setValue(0);
Animated.timing(
this.animatedValue,
{
toValue: 1,
duration: UIConstants.animations.normal,
easing: Easing.linear,
}
).start(() => {
setTimeout(this._hideBanner, 5000);
});
});
}
_hideBanner = () => {
this.animatedValue.setValue(1);
Animated.timing(
this.animatedValue,
{
toValue: 0,
duration: UIConstants.animations.normal,
easing: Easing.linear,
}
).start(() => {
this.setState({
showBanner: false,
});
});
}
render() {
const bannerTop = this.animatedValue.interpolate({
inputRange: [0, 1],
outputRange: [30, 0],
});
return (
<View style={styles.container}>
<SplashNavigator style={styles.splash}/>
{ this.state.showBanner ?
<Animated.View
style={[
styles.bannerWrapper,
{
top: bannerTop,
opacity: this.animatedValue,
}
]}>
<Banner
style={styles.banner}
type={this.state.bannerType}
message={this.state.bannerMessage}
onPress={this._hideBanner}
/>
</Animated.View>
: null
}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
splash: {
flex: 1,
paddingTop: (Platform.OS === 'android') ? StatusBar.currentHeight : 0,
backgroundColor: Colors.main,
},
bannerWrapper: {
position: 'absolute',
padding: 10,
marginTop: (Platform.OS === 'android') ? StatusBar.currentHeight + Header.HEIGHT : Header.HEIGHT,
maxWidth: '100%',
},
});