-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
124 lines (107 loc) · 2.02 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
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
'use strict';
//react-native modal
import React, {
PropTypes,
Animated,
Dimensions,
StyleSheet,
View
} from 'react-native';
let {
width,
height
} = Dimensions.get('window');
export default class PopWindow extends React.Component{
static propTypes = {
style: PropTypes.object,
duration: PropTypes.number,
children: PropTypes.node.isRequired
};
static defaultProps = {
duration: 300
};
constructor(props, context){
super(props, context);
this.state = {
animVal: new Animated.Value(height),
isPopShow: false,
isPopNeedRemove: true,
...this._getStateFromProps(this.props)
};
}
shouldComponentUpdate(nextProps, nextState, context){
return true;
}
componentWillReceiveProps(newProps){
let newState = this._getStateFromProps(newProps);
this.setState(newState);
}
componentWillUnmount(){
clearTimeout(this.timer);
}
_getStateFromProps(props){
let {
style,
duration,
children
} = props;
return {
style,
duration,
children
};
}
_getChildren(){
return this.state.children;
}
show(){
this.setState({
isPopShow: true,
isPopNeedRemove: false
});
Animated.timing(this.state.animVal, {
toValue: 0,
duration: this.state.duration,
easing: Animated.timing.linear
}).start();
}
hide(){
this.setState({
isPopShow: false
});
//wait for the animation end, then remove
this.timer = setTimeout(() => {
this.setState({
isPopNeedRemove: true
});
}, this.state.duration);
Animated.timing(this.state.animVal, {
toValue: height,
duration: this.state.duration,
easing: Animated.timing.linear
}).start();
}
isShow(){
return this.state.isPopShow;
}
render(){
return this.state.isPopNeedRemove ? null : (
<Animated.View style={[styles.animated, {
transform: [{
translateY: this.state.animVal
}]
}, this.state.style]}>
{this._getChildren()}
</Animated.View>
);
}
};
let styles = StyleSheet.create({
animated: {
width: width,
height: height,
position: 'absolute',
left: 0,
bottom: 0
}
});