/
OperationContainer.native.tsx
60 lines (56 loc) · 1.4 KB
/
OperationContainer.native.tsx
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
import React from 'react';
import { TextStyle } from 'react-native';
import Modal from './Modal.native';
import modalStyle from './style/index.native';
import { Action } from './PropsType';
export interface OperationContainerProps {
actions: Action<TextStyle>[];
onAnimationEnd?: (visible: boolean) => void;
}
export default class OperationContainer extends React.Component<
OperationContainerProps,
any
> {
constructor(props: OperationContainerProps) {
super(props);
this.state = {
visible: true,
};
}
onClose = () => {
this.setState({
visible: false,
});
}
render() {
const { actions, onAnimationEnd } = this.props;
const footer = actions.map(button => {
// tslint:disable-next-line:only-arrow-functions
const orginPress = button.onPress || function() {};
button.onPress = () => {
const res = orginPress();
if (res && (res as any).then) {
(res as any).then(() => {
this.onClose();
});
} else {
this.onClose();
}
};
return button;
});
return (
<Modal
operation
transparent
maskClosable
visible={this.state.visible}
onClose={this.onClose}
onAnimationEnd={onAnimationEnd}
style={modalStyle.operationContainer}
bodyStyle={modalStyle.operationBody}
footer={footer}
/>
);
}
}