import React, { useState, useEffect } from 'react'; import { View, Text, TouchableOpacity, Dimensions, Animated, } from 'react-native'; import { Close, Done } from '../../assetComponents/icons'; import styles, { iconSize } from './styles'; type ModalType = 'Success' | 'Error'; type Props = { visible: boolean; setVisible: Function; title?: string; text?: string; modalType?: ModalType; leftButtonText?: string; rightButtonText?: string; onRightButtonPress?: Function; }; const { height, width } = Dimensions.get('screen'); const ModalComponent: React.FC = ({ visible = false, setVisible = () => {}, title = 'Default', text = 'Default', modalType = 'Success', leftButtonText = 'Cancel', rightButtonText = 'Default', onRightButtonPress = () => {}, }) => { const [modal] = useState(new Animated.Value(height)); function start() { Animated.spring(modal, { toValue: height * 0.5 - 50, useNativeDriver: true, }).start(); } function hide() { Animated.timing(modal, { toValue: height + 200, duration: 300, useNativeDriver: true, }).start(); setVisible(false); } useEffect(() => { if (visible) start(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [visible]); return ( hide()} /> {modalType === 'Success' ? ( ) : ( )} {title} {text} {leftButtonText} onRightButtonPress()} > {rightButtonText} ); }; export default ModalComponent;