forked from HarvestProfit/react-native-modal-patch
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModal.js
More file actions
160 lines (140 loc) · 3.98 KB
/
Copy pathModal.js
File metadata and controls
160 lines (140 loc) · 3.98 KB
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
159
160
import PropTypes from 'prop-types';
import React from 'react';
import {
ScrollView,
StyleSheet,
View,
Platform,
Modal,
} from 'react-native';
import AppContainer from 'react-native/Libraries/ReactNative/AppContainer';
import RNTModalHostView from './RNTModalHostViewNativeComponent';
/**
* The Modal component is a simple way to present content above an enclosing view.
*
* See https://facebook.github.io/react-native/docs/modal.html
*/
// In order to route onDismiss callbacks, we need to uniquely identifier each
// <Modal> on screen. There can be different ones, either nested or as siblings.
// We cannot pass the onDismiss callback to native as the view will be
// destroyed before the callback is fired.
/* eslint-disable */
let uniqueModalIdentifier = 0;
class iOSModal extends React.Component {
static defaultProps = {
visible: true,
hardwareAccelerated: false,
};
static contextTypes = {
rootTag: PropTypes.number,
};
constructor(props) {
super(props);
// Modal._confirmProps(props);
this._identifier = uniqueModalIdentifier++;
}
static childContextTypes = {
virtualizedList: PropTypes.object,
};
getChildContext() {
// Reset the context so VirtualizedList doesn't get confused by nesting
// in the React tree that doesn't reflect the native component hierarchy.
return {
virtualizedList: null,
};
}
componentWillUnmount() {
if (this.props.onDismiss != null) {
this.props.onDismiss();
}
}
UNSAFE_componentWillReceiveProps(nextProps) {
// Modal._confirmProps(nextProps);
}
static _confirmProps(props) {
if (
props.presentationStyle
&& props.presentationStyle !== 'overFullScreen'
&& props.transparent
) {
console.warn(
`Modal with '${
props.presentationStyle
}' presentation style and 'transparent' value is not supported.`,
);
}
}
// We don't want any responder events bubbling out of the modal.
_shouldSetResponder() {
return true;
}
render() {
if (this.props.visible !== true) {
return null;
}
const containerStyles = {
backgroundColor: this.props.transparent ? 'transparent' : 'white',
};
let { animationType } = this.props;
if (!animationType) {
// manually setting default prop here to keep support for the deprecated 'animated' prop
animationType = 'none';
if (this.props.animated) {
animationType = 'slide';
}
}
let { presentationStyle } = this.props;
if (!presentationStyle) {
presentationStyle = 'fullScreen';
if (this.props.transparent) {
presentationStyle = 'overFullScreen';
}
}
const innerChildren = __DEV__ ? (
<AppContainer rootTag={this.context.rootTag}>
{this.props.children}
</AppContainer>
) : (
this.props.children
);
return (
<RNTModalHostView
animationType={animationType}
presentationStyle={presentationStyle}
transparent={this.props.transparent}
hardwareAccelerated={this.props.hardwareAccelerated}
onRequestClose={this.props.onRequestClose}
onDismiss={this.props.onDismiss}
onShow={this.props.onShow}
statusBarTranslucent={this.props.statusBarTranslucent}
identifier={this._identifier}
style={styles.modal}
onStartShouldSetResponder={this._shouldSetResponder}
supportedOrientations={this.props.supportedOrientations}
onOrientationChange={this.props.onOrientationChange}
>
<ScrollView.Context.Provider value={null}>
<View style={[styles.container, containerStyles]}>
{innerChildren}
</View>
</ScrollView.Context.Provider>
</RNTModalHostView>
);
}
}
const styles = StyleSheet.create({
modal: {
position: 'absolute',
},
container: {
right: 0,
left: 0,
top: 0,
flex: 1,
},
});
if (Platform.OS === 'android') {
module.exports = Modal;
} else {
module.exports = iOSModal;
}