import * as React from 'react'; import { Animated, StyleSheet, TouchableWithoutFeedback, useWindowDimensions, View, } from 'react-native'; import { g_mask_color } from '../../const'; import { DefaultSlide } from './DefaultSlide'; import { useSimulativeModalAnimation, useSimulativeModalPanResponder, } from './SimuModal.hooks'; import type { SimulativeModalProps } from './types'; /** * Simulate a modal window. */ export function SimulativeModal(props: SimulativeModalProps) { const { modalAnimationType, modalStyle, disableBackgroundClose = false, backgroundColor, backgroundTransparent = false, children, propsRef, onStartShouldSetPanResponder, onFinished, maskStyle, Slide, ...others } = props; const { translateY, startShow, startHide, backgroundOpacity } = useSimulativeModalAnimation(modalAnimationType); const { width, height } = useWindowDimensions(); const [modalVisible, setModalVisible] = React.useState(false); const SlideWrapper = Slide ?? DefaultSlide; if (propsRef) { if (propsRef.current) { propsRef.current.startShow = () => { setModalVisible(true); startShow(); }; propsRef.current.startHide = (onf?: () => void) => { startHide(() => { setModalVisible(false); onf?.(); onFinished?.(); }); }; } } return ( { if (disableBackgroundClose !== true) { startHide(() => setModalVisible(false)); } }} > {children} ); }