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 title: string, titleLoading: string, message: string, } type State = { loading: boolean, } class LoadingConfirmDialog extends React.PureComponent { state = { loading: false, }; 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); }); }; onDismiss = () => { if (!this.state.loading) this.props.onDismiss(); }; render() { return ( {this.state.loading ? this.props.titleLoading : this.props.title} {this.state.loading ? : {this.props.message} } {this.state.loading ? null : } ); } } export default LoadingConfirmDialog;