|
@@ -1,11 +1,13 @@
|
|
1
|
+// @flow
|
|
2
|
+
|
1
|
3
|
import * as React from 'react';
|
2
|
4
|
import {ActivityIndicator, Button, Dialog, Paragraph, Portal} from 'react-native-paper';
|
3
|
5
|
import i18n from "i18n-js";
|
4
|
6
|
|
5
|
7
|
type Props = {
|
6
|
8
|
visible: boolean,
|
7
|
|
- onDismiss: Function,
|
8
|
|
- onAccept: Function, // async function to be executed
|
|
9
|
+ onDismiss: () => void,
|
|
10
|
+ onAccept: () => Promise<void>, // async function to be executed
|
9
|
11
|
title: string,
|
10
|
12
|
titleLoading: string,
|
11
|
13
|
message: string,
|
|
@@ -21,18 +23,25 @@ class LoadingConfirmDialog extends React.PureComponent<Props, State> {
|
21
|
23
|
loading: false,
|
22
|
24
|
};
|
23
|
25
|
|
|
26
|
+ /**
|
|
27
|
+ * Set the dialog into loading state and closes it when operation finishes
|
|
28
|
+ */
|
24
|
29
|
onClickAccept = () => {
|
25
|
30
|
this.setState({loading: true});
|
26
|
|
- this.props.onAccept()
|
27
|
|
- .then(() => {
|
28
|
|
- //Wait for fade out animations to finish before hiding loading
|
29
|
|
- setTimeout(() => {
|
30
|
|
- this.setState({loading: false})
|
31
|
|
- }, 200);
|
32
|
|
-
|
33
|
|
- });
|
|
31
|
+ this.props.onAccept().then(this.hideLoading);
|
34
|
32
|
};
|
35
|
33
|
|
|
34
|
+ /**
|
|
35
|
+ * Waits for fade out animations to finish before hiding loading
|
|
36
|
+ * @returns {TimeoutID}
|
|
37
|
+ */
|
|
38
|
+ hideLoading = () => setTimeout(() => {
|
|
39
|
+ this.setState({loading: false})
|
|
40
|
+ }, 200);
|
|
41
|
+
|
|
42
|
+ /**
|
|
43
|
+ * Hide the dialog if it is not loading
|
|
44
|
+ */
|
36
|
45
|
onDismiss = () => {
|
37
|
46
|
if (!this.state.loading)
|
38
|
47
|
this.props.onDismiss();
|