-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
158 lines (142 loc) · 3.2 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
'use strict';
var React = require('react-native');
var deviceScreen = require('Dimensions').get('window');
var Tween = require('react-native-tween-animation');
var {
StyleSheet,
View,
Component,
TouchableWithoutFeedback,
} = React;
import utils from './utils';
class Modal extends Component {
constructor (props) {
super(props);
this.state = {
modalUnderlay: {
top: deviceScreen.height,
opacity: 0
},
modal: {
top: deviceScreen.height
},
modalWrapper: {
height: 0
}
};
}
_showModalWrapper () {
this.setState({
modalWrapper: {
height: deviceScreen.height
},
modalUnderlay: {
top: 0
}
});
}
_hideModalWrapper () {
this.setState({
modalWrapper: {
height: 0
},
modalUnderlay: {
top: deviceScreen.height
}
});
}
_showModal () {
this.modalTween = new Tween({
start: {
top: deviceScreen.height,
},
end: {
top: 20,
},
duration: (this.props.hasOwnProperty('duration')) ? (
this.props.duration
) : 500,
tween: (this.props.hasOwnProperty('tween')) ? (
this.props.tween
) : 'easeOutBack',
frame: (tweenFrame) => this.setState({
modal: tweenFrame
})
});
}
show () {
if(this.props.hideStatusBar !== false)
utils.setHidden(true);
this._showModalWrapper();
this.underlayTween = new Tween({
start: {
opacity: 0,
},
end: {
opacity: 0.6,
},
duration: 200,
tween: 'easeInQuad',
frame: (tweenFrame) => this.setState({
modalUnderlay: tweenFrame
}),
done: () => {
this._showModal();
}
});
}
close () {
if(this.props.hideStatusBar !== false)
utils.setHidden(false);
this.modalTween.reverse(() => {});
this.underlayTween.reverse(() => {
this._hideModalWrapper();
});
}
renderChildren () {
return React.cloneElement(
this.props.children,
{closeModal: this.close.bind(this)}
);
}
render () {
return (
<View style={[styles.modalWrapper, this.state.modalWrapper]}>
<TouchableWithoutFeedback onPress={this.props.closeOnTouch === true ? this.close.bind(this) : null}>
<View style={[styles.modalUnderlay, this.state.modalUnderlay]}></View>
</TouchableWithoutFeedback>
<View style={[styles.modal, this.state.modal, this.props.modalStyle]}>
{this.renderChildren()}
</View>
</View>
);
}
};
var styles = StyleSheet.create({
modalWrapper: {
position: 'absolute',
width: deviceScreen.width,
height: deviceScreen.height,
left: 0,
top: 0,
backgroundColor: 'transparent'
},
modalUnderlay: {
position: 'absolute',
width: deviceScreen.width,
height: deviceScreen.height,
left: 0,
backgroundColor: '#000'
},
modal: {
position: 'absolute',
width: deviceScreen.width-40,
height: deviceScreen.height-40,
left: 20,
backgroundColor: '#fff',
opacity: 1,
borderRadius: 4,
overflow: 'hidden'
}
});
module.exports = Modal;