-
Notifications
You must be signed in to change notification settings - Fork 39
/
fade_in_view.js
54 lines (46 loc) · 1.09 KB
/
fade_in_view.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
'use strict';
var React = require('react');
var ReactNative = require('react-native');
var { Animated, Dimensions, StyleSheet, View } = ReactNative;
var window = Dimensions.get('window');
var FadeInView = React.createClass({
getInitialState: function() {
return {
fadeAnim: new Animated.Value(0)
};
},
componentDidMount() {
this._animate(this.props);
},
componentWillReceiveProps: function(newProps) {
this._animate(newProps);
},
_animate(newProps){
return Animated.timing(this.state.fadeAnim, {
toValue: newProps.visible ? 0.7 : 0,
duration: 300
}).start();
},
render: function() {
return (
<Animated.View style={[styles.overlay,
{opacity: this.state.fadeAnim},
{backgroundColor: this.props.backgroundColor || 'black' }
]}>
{this.props.children}
</Animated.View>
);
}
});
var styles = StyleSheet.create({
overlay: {
top: 0,
bottom: 0,
left: 0,
right: 0,
height: window.height,
width: window.width,
position: 'absolute'
}
});
module.exports = FadeInView;