Added dialogs flow typing

This commit is contained in:
Arnaud Vergnet 2020-04-19 19:10:38 +02:00
parent 75b7412eb2
commit b64b68dc8a
3 changed files with 25 additions and 12 deletions

View file

@ -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,
}

View file

@ -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,
}

View file

@ -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<void>, // async function to be executed
title: string,
titleLoading: string,
message: string,
@ -21,18 +23,25 @@ class LoadingConfirmDialog extends React.PureComponent<Props, State> {
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();