forked from Luccifer/FB-Source-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModalWindows.js.txt
130 lines (114 loc) · 3.05 KB
/
ModalWindows.js.txt
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
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule RKModal
* @flow
*/
'use strict';
var Portal = require('Portal');
var React = require('React');
var ReactChildren = require('ReactChildren');
var StyleSheet = require('StyleSheet');
var TouchableWithoutFeedback = require('TouchableWithoutFeedback');
var View = require('View');
/**
* Displays given contents on top of everything else in the application UI.
*
* The `isOpen` property determines whether to show or hide the modal.
*
* ```
* return (
* <Modal
* onRequestClose={() => this.setState({ isModalOpen: false })}
* isOpen={this.state.isModalOpen}>
* <View ...
* </Modal>
* );
* ```
*/
var Modal = React.createClass({
_tag: '',
propTypes: {
/**
* The contents of the modal
*/
children: React.PropTypes.any,
/**
* If true, the modal will be rendered
*/
isOpen: React.PropTypes.bool.isRequired,
/**
* Style applied to the immediate wrapper of inner content.
*/
contentContainerStyle: View.propTypes.style,
/**
* Style of the overlay view covering the whole screen.
* It is transparent by default.
*/
fullscreenContainerStyle: View.propTypes.style,
/**
* Called when the area anywhere outside the contents is tapped
*/
onRequestClose: React.PropTypes.func,
},
getDefaultProps: function(): Object {
return {
isOpen: false,
};
},
componentWillMount: function() {
this._tag = Portal.allocateTag();
if (this.props.isOpen) {
Portal.showModal(this._tag, this._createModal(this.props));
}
},
componentWillUnmount: function() {
Portal.closeModal(this._tag);
},
componentWillReceiveProps: function(newProps: Object) {
if (newProps.isOpen) {
// Even if already shown, showModal will re-render
// which is useful for updating the modal.
Portal.showModal(this._tag, this._createModal(newProps));
} else {
Portal.closeModal(this._tag);
}
},
_createModal: function(newProps: Object) {
var fullscreenContainerStyles = [
styles.fullscreenContainer,
this.props.fullscreenContainerStyle,
];
var children = newProps.children;
// If there are multiple children we need to wrap them in a View.
// This is because Touchable needs a single child.
var hasMultipleChildren = ReactChildren.count(children) > 1;
var content = hasMultipleChildren ?
<View style={this.props.contentContainerStyle}>
{children}
</View> :
children;
return (
<TouchableWithoutFeedback key={this._tag} onPress={this.props.onRequestClose}>
<View style={fullscreenContainerStyles}>
<TouchableWithoutFeedback>
{content}
</TouchableWithoutFeedback>
</View>
</TouchableWithoutFeedback>
);
},
render: function(): any {
return null;
}
});
var styles = StyleSheet.create({
fullscreenContainer: {
position: 'absolute',
left: 0,
top: 0,
right: 0,
bottom: 0,
},
});
module.exports = Modal;