Browse Source

Added dialogs flow typing

Arnaud Vergnet 4 years ago
parent
commit
b64b68dc8a

+ 3
- 1
src/components/Dialogs/AlertDialog.js View File

@@ -1,9 +1,11 @@
1
+// @flow
2
+
1 3
 import * as React from 'react';
2 4
 import {Button, Dialog, Paragraph, Portal} from 'react-native-paper';
3 5
 
4 6
 type Props = {
5 7
     visible: boolean,
6
-    onDismiss: Function,
8
+    onDismiss: () => void,
7 9
     title: string,
8 10
     message: string,
9 11
 }

+ 3
- 1
src/components/Dialogs/ErrorDialog.js View File

@@ -1,3 +1,5 @@
1
+// @flow
2
+
1 3
 import * as React from 'react';
2 4
 import i18n from "i18n-js";
3 5
 import {ERROR_TYPE} from "../../utils/WebData";
@@ -5,7 +7,7 @@ import AlertDialog from "./AlertDialog";
5 7
 
6 8
 type Props = {
7 9
     visible: boolean,
8
-    onDismiss: Function,
10
+    onDismiss: () => void,
9 11
     errorCode: number,
10 12
 }
11 13
 

+ 19
- 10
src/components/Dialogs/LoadingConfirmDialog.js View File

@@ -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();

Loading…
Cancel
Save