This repository has been archived by the owner on Nov 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RNPopoverIOS.ios.js
125 lines (117 loc) · 3.3 KB
/
RNPopoverIOS.ios.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
import React, { Component, Children } from 'react';
import PropTypes from 'prop-types';
import {
NativeEventEmitter,
NativeModules,
StyleSheet,
View,
Text,
requireNativeComponent,
Platform,
Animated,
I18nManager
} from 'react-native';
const RNPopoverHostView = requireNativeComponent('RNPopoverHostView');
const RNPopoverHostViewManager = NativeModules.RNPopoverHostViewManager;
const side = I18nManager.isRTL ? 'right' : 'left';
const styles = StyleSheet.create({
popover: {
position: 'absolute',
overflow: 'hidden',
opacity: 0,
backgroundColor: 'transparent'
},
container: {
position: 'absolute',
[side]: 0,
top: 0
}
});
export default class extends Component {
static displayName = 'Popover';
static propTypes = {
/**
* The `visible` prop determines whether your popover is visible.
*/
visible: PropTypes.bool,
/**
* The `animated` prop determines whether present or dismiss popover use animation.
*/
animated: PropTypes.bool,
/**
* The `cancelable` prop determines whether dismiss popover when clicking the out space.
*/
cancelable: PropTypes.bool,
/**
* The `popoverBackgroundColor` prop set popover back ground color. Like '#FFF'
*/
popoverBackgroundColor: PropTypes.string,
/**
* The `sourceViewReactTag` prop is the reactTag of The view containing the anchor rectangle for the popover
*/
sourceViewReactTag: PropTypes.number,
/**
* The `sourceViewTag` prop is the tag of The view containing the anchor rectangle for the popover
*/
sourceViewTag: PropTypes.number,
/**
* The `sourceViewGetterTag` prop is the tag of The view getter which containing the anchor rectangle for the popover
*/
sourceViewGetterTag: PropTypes.number,
/**
* The `sourceViewNativeID` prop is the nativeID of The view containing the anchor rectangle for the popover
*/
sourceViewNativeID: PropTypes.string,
/**
* The `sourceRect` prop is the rectangle in the specified view in which to anchor the popover.
*/
sourceRect: PropTypes.array,
/**
* The arrow directions that you prefer for the popover.
*
* 0: up
* 1: down
* 2: left
* 3: right
*
* Like [0, 1, 2, 3]
*/
permittedArrowDirections: PropTypes.array,
/**
* The preferred size for the view controller’s view. Like [200, 200]
*/
preferredContentSize: PropTypes.array,
/**
* The `onShow` prop allows passing a function that will be called once the popover has been shown.
*/
onShow: PropTypes.func,
/**
* The `onHide` prop allows passing a function that will be called once the popover has been hidden.
*/
onHide: PropTypes.func
};
static defaultProps = {
visible: true,
sourceViewTag: -1,
sourceViewGetterTag: -1,
sourceViewReactTag: -1
};
static dismiss = (reactTag, animated = true) => {
return RNPopoverHostViewManager.dismiss(reactTag, animated);
};
render() {
const { visible, children } = this.props;
if (visible === false) {
return null;
}
return (
<RNPopoverHostView
style={styles.popover}
{...this.props}>
<View style={styles.container}>
{children}
</View>
</RNPopoverHostView>
);
}
}