From b64b68dc8afdb025fd449aa5f243b5b127c8ca81 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Sun, 19 Apr 2020 19:10:38 +0200 Subject: [PATCH] Added dialogs flow typing --- src/components/Dialogs/AlertDialog.js | 4 ++- src/components/Dialogs/ErrorDialog.js | 4 ++- .../Dialogs/LoadingConfirmDialog.js | 29 ++++++++++++------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/components/Dialogs/AlertDialog.js b/src/components/Dialogs/AlertDialog.js index 05516d7..a79efc7 100644 --- a/src/components/Dialogs/AlertDialog.js +++ b/src/components/Dialogs/AlertDialog.js @@ -1,9 +1,11 @@ +// @flow + import * as React from 'react'; import {Button, Dialog, Paragraph, Portal} from 'react-native-paper'; type Props = { visible: boolean, - onDismiss: Function, + onDismiss: () => void, title: string, message: string, } diff --git a/src/components/Dialogs/ErrorDialog.js b/src/components/Dialogs/ErrorDialog.js index 3fc708b..f357a5f 100644 --- a/src/components/Dialogs/ErrorDialog.js +++ b/src/components/Dialogs/ErrorDialog.js @@ -1,3 +1,5 @@ +// @flow + import * as React from 'react'; import i18n from "i18n-js"; import {ERROR_TYPE} from "../../utils/WebData"; @@ -5,7 +7,7 @@ import AlertDialog from "./AlertDialog"; type Props = { visible: boolean, - onDismiss: Function, + onDismiss: () => void, errorCode: number, } diff --git a/src/components/Dialogs/LoadingConfirmDialog.js b/src/components/Dialogs/LoadingConfirmDialog.js index e8aeeb6..8c7d48a 100644 --- a/src/components/Dialogs/LoadingConfirmDialog.js +++ b/src/components/Dialogs/LoadingConfirmDialog.js @@ -1,11 +1,13 @@ +// @flow + import * as React from 'react'; import {ActivityIndicator, Button, Dialog, Paragraph, Portal} from 'react-native-paper'; import i18n from "i18n-js"; type Props = { visible: boolean, - onDismiss: Function, - onAccept: Function, // async function to be executed + onDismiss: () => void, + onAccept: () => Promise, // async function to be executed title: string, titleLoading: string, message: string, @@ -21,18 +23,25 @@ class LoadingConfirmDialog extends React.PureComponent { loading: false, }; + /** + * Set the dialog into loading state and closes it when operation finishes + */ onClickAccept = () => { this.setState({loading: true}); - this.props.onAccept() - .then(() => { - //Wait for fade out animations to finish before hiding loading - setTimeout(() => { - this.setState({loading: false}) - }, 200); - - }); + this.props.onAccept().then(this.hideLoading); }; + /** + * Waits for fade out animations to finish before hiding loading + * @returns {TimeoutID} + */ + hideLoading = () => setTimeout(() => { + this.setState({loading: false}) + }, 200); + + /** + * Hide the dialog if it is not loading + */ onDismiss = () => { if (!this.state.loading) this.props.onDismiss();