-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathFadeInView.js
55 lines (47 loc) · 1.12 KB
/
FadeInView.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
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Animated } from 'react-native';
class FadeInView extends Component {
constructor() {
super();
this.state = {
viewOpacity: new Animated.Value(0),
};
}
componentDidMount() {
const { viewOpacity } = this.state;
const { onFadeComplete, duration = 500 } = this.props;
Animated.timing(
viewOpacity,
{
toValue: 1,
duration,
useNativeDriver: false,
},
).start(onFadeComplete || (() => {}));
}
render() {
const { viewOpacity } = this.state;
const { style } = this.props;
return (
<Animated.View style={[{ opacity: viewOpacity }].concat(style || [])}>
{this.props.children}
</Animated.View>
);
}
}
FadeInView.propTypes = {
onFadeComplete: PropTypes.func,
duration: PropTypes.number,
style: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string,
PropTypes.object,
PropTypes.array,
]),
children: PropTypes.oneOfType([
PropTypes.array,
PropTypes.object,
]).isRequired,
};
export default FadeInView;