-
Notifications
You must be signed in to change notification settings - Fork 17
/
ActionSheetManager.js
67 lines (56 loc) · 1.37 KB
/
ActionSheetManager.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
// @flow
import React from 'react';
import RootSiblings from 'react-native-root-siblings';
import ActionSheet from './ActionSheet';
export default class ActionSheetManager {
constructor() {
this.props = [];
}
setCurrent(props: Object, callback?: Function = () => {}): void {
if (!props) {
return;
}
this.currentActionSheet = new RootSiblings(
<ActionSheet {...props} />,
callback,
);
}
create(props: Object, callback?: Function = () => {}): void {
this.setCurrent(props, callback);
this.props.push(props);
}
update = (props: Object, callback?: Function = () => {}): void => {
this.props[this.props.length - 1] = props;
this.currentActionSheet.update(
<ActionSheet {...props} />,
callback,
);
}
show = (options: Object, callback?: Function = () => {}): void => {
const props = {
...options,
show: true,
onHide: () => {
callback();
this.hide();
},
};
this.create(props, callback);
}
hide = (callback?: Function = () => {}): void => {
const props = this.props.pop();
if (!props) {
callback();
return;
}
this.update({
...props,
show: false,
onHide: () => {
callback();
this.currentActionSheet.destroy();
this.setCurrent(this.props[this.props.length] - 1);
},
});
}
}