forked from vergnet/application-amicale
Added dialogs flow typing
This commit is contained in:
parent
75b7412eb2
commit
b64b68dc8a
3 changed files with 25 additions and 12 deletions
|
@ -1,9 +1,11 @@
|
||||||
|
// @flow
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {Button, Dialog, Paragraph, Portal} from 'react-native-paper';
|
import {Button, Dialog, Paragraph, Portal} from 'react-native-paper';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
visible: boolean,
|
visible: boolean,
|
||||||
onDismiss: Function,
|
onDismiss: () => void,
|
||||||
title: string,
|
title: string,
|
||||||
message: string,
|
message: string,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// @flow
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import i18n from "i18n-js";
|
import i18n from "i18n-js";
|
||||||
import {ERROR_TYPE} from "../../utils/WebData";
|
import {ERROR_TYPE} from "../../utils/WebData";
|
||||||
|
@ -5,7 +7,7 @@ import AlertDialog from "./AlertDialog";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
visible: boolean,
|
visible: boolean,
|
||||||
onDismiss: Function,
|
onDismiss: () => void,
|
||||||
errorCode: number,
|
errorCode: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
|
// @flow
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {ActivityIndicator, Button, Dialog, Paragraph, Portal} from 'react-native-paper';
|
import {ActivityIndicator, Button, Dialog, Paragraph, Portal} from 'react-native-paper';
|
||||||
import i18n from "i18n-js";
|
import i18n from "i18n-js";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
visible: boolean,
|
visible: boolean,
|
||||||
onDismiss: Function,
|
onDismiss: () => void,
|
||||||
onAccept: Function, // async function to be executed
|
onAccept: () => Promise<void>, // async function to be executed
|
||||||
title: string,
|
title: string,
|
||||||
titleLoading: string,
|
titleLoading: string,
|
||||||
message: string,
|
message: string,
|
||||||
|
@ -21,18 +23,25 @@ class LoadingConfirmDialog extends React.PureComponent<Props, State> {
|
||||||
loading: false,
|
loading: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the dialog into loading state and closes it when operation finishes
|
||||||
|
*/
|
||||||
onClickAccept = () => {
|
onClickAccept = () => {
|
||||||
this.setState({loading: true});
|
this.setState({loading: true});
|
||||||
this.props.onAccept()
|
this.props.onAccept().then(this.hideLoading);
|
||||||
.then(() => {
|
|
||||||
//Wait for fade out animations to finish before hiding loading
|
|
||||||
setTimeout(() => {
|
|
||||||
this.setState({loading: false})
|
|
||||||
}, 200);
|
|
||||||
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 = () => {
|
onDismiss = () => {
|
||||||
if (!this.state.loading)
|
if (!this.state.loading)
|
||||||
this.props.onDismiss();
|
this.props.onDismiss();
|
||||||
|
|
Loading…
Reference in a new issue