-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
81 lines (69 loc) · 1.54 KB
/
index.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
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import {
Animated,
ViewPropTypes,
} from 'react-native';
export default class AnimatedHideView extends PureComponent {
static propTypes = {
visible: PropTypes.bool.isRequired,
duration: PropTypes.number,
unmountOnHide: PropTypes.bool,
animate: PropTypes.bool,
style: ViewPropTypes.style,
children: PropTypes.node.isRequired,
}
static defaultProps = {
duration: 300,
animate: true,
unmountOnHide: false,
style: {},
}
constructor(props) {
super(props);
this.opacity = new Animated.Value(props.visible ? 1 : 0);
}
componentWillUpdate(nextProps) {
if (this.props.visible !== nextProps.visible) {
this.animate();
}
}
animate = () => {
const {
animate,
duration,
visible,
} = this.props;
Animated.timing(this.opacity, {
toValue: visible ? 0 : 1,
duration: animate ? duration : 0,
useNativeDriver: true,
}).start();
}
render() {
const {
unmountOnHide,
visible,
style,
children,
...otherProps
} = this.props;
const renderStyle = {
opacity: this.opacity,
zIndex: visible ? 1 : 0,
};
const pointerEvents = visible ? 'auto' : 'none';
if (unmountOnHide && !visible) {
return null;
}
return (
<Animated.View
pointerEvents={pointerEvents}
style={[renderStyle, style]}
{...otherProps}
>
{children}
</Animated.View>
);
}
}