// @flow import * as React from 'react'; import {Avatar, Button, Card, Paragraph, Portal, withTheme} from 'react-native-paper'; import Mascot from "./Mascot"; import * as Animatable from "react-native-animatable"; import {BackHandler, Dimensions, ScrollView, TouchableWithoutFeedback, View} from "react-native"; import type {CustomTheme} from "../../managers/ThemeManager"; type Props = { visible: boolean, theme: CustomTheme, icon: string, title: string, message: string, buttons: { action: { message: string, icon: string | null, color: string | null, onPress: () => void, }, cancel: { message: string, icon: string | null, color: string | null, onPress: () => void, } }, emotion: number, } type State = { shouldShowDialog: boolean; } class MascotPopup extends React.Component { mascotSize: number; windowWidth: number; windowHeight: number; state = { shouldShowDialog: this.props.visible, }; constructor(props: Props) { super(props); this.windowWidth = Dimensions.get('window').width; this.windowHeight = Dimensions.get('window').height; this.mascotSize = Dimensions.get('window').height / 6; } onAnimationEnd = () => { this.setState({ shouldShowDialog: this.props.visible, }) } shouldComponentUpdate(nextProps: Props): boolean { if (nextProps.visible) { this.state.shouldShowDialog = true; } else if (nextProps.visible !== this.props.visible) { setTimeout(this.onAnimationEnd, 300); } return true; } componentDidMount(): * { BackHandler.addEventListener( 'hardwareBackPress', this.onBackButtonPressAndroid ) } onBackButtonPressAndroid = () => { if (this.state.shouldShowDialog) { const cancel = this.props.buttons.cancel; const action = this.props.buttons.action; if (cancel != null) cancel.onPress(); else action.onPress(); return true; } else { return false; } }; getSpeechBubble() { return ( : null} /> {this.props.message} {this.getButtons()} ); } getMascot() { return ( ); } getButtons() { const action = this.props.buttons.action; const cancel = this.props.buttons.cancel; return ( {action != null ? : null} {cancel != null ? : null} ); } getBackground() { return ( ); } render() { if (this.state.shouldShowDialog) { return ( {this.getBackground()} {this.getMascot()} {this.getSpeechBubble()} ) ; } else return null; } } export default withTheme(MascotPopup);