/
AlertContainer.native.tsx
67 lines (62 loc) · 1.49 KB
/
AlertContainer.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
61
62
63
64
65
66
67
/* tslint:disable:jsx-no-multiline-js */
import React from 'react';
import { ScrollView, Text, TextStyle } from 'react-native';
import Modal from './Modal.native';
import { Action } from './PropsType';
export interface AlertContainerProps {
title: React.ReactNode;
content: React.ReactNode;
actions: Action<TextStyle>[];
onAnimationEnd?: (visible: boolean) => void;
}
export default class AlertContainer extends React.Component<
AlertContainerProps,
any
> {
constructor(props: AlertContainerProps) {
super(props);
this.state = {
visible: true,
};
}
onClose = () => {
this.setState({
visible: false,
});
}
render() {
const { title, actions, content, 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.then) {
res.then(() => {
this.onClose();
});
} else {
this.onClose();
}
};
return button;
});
return (
<Modal
transparent
title={title}
visible={this.state.visible}
footer={footer}
onAnimationEnd={onAnimationEnd}
bodyStyle={{
marginTop: 8,
alignItems: 'center',
}}
>
<ScrollView>
<Text>{content}</Text>
</ScrollView>
</Modal>
);
}
}