import { View, Text, ScrollView } from '@tarojs/components' import './new_modal.scss' import React, { useEffect, useRef, useState } from 'react'; import { ModalType } from '@/utils/types'; import Taro from '@tarojs/taro'; import { vibrate } from '@/utils/tools'; import { MainColorType } from '@/context/themes/color'; let ModalRN, Animated if (process.env.TARO_ENV == 'rn') { ModalRN = require("react-native").Modal Animated = require("react-native").Animated } export default function NewModal(props: { children: React.ReactNode, title?: string, btnTitle?: string, dismiss: Function, confirm?: Function, themeColor?: string, cancelCatchMove?: boolean, themeIsWhite?: boolean }) { const [isDismiss, setIsDismiss] = useState(false) let animation, animatedStyle; if (process.env.TARO_ENV == 'rn') { animation = useRef(new Animated.Value(0)).current; animatedStyle = { transform: [ { translateY: animation.interpolate({ inputRange: [0, 1], outputRange: [300, 0], }), }, ], }; } useEffect(() => { if (process.env.TARO_ENV == 'rn') { startAnimation() } }, []) const startAnimation = () => { Animated.spring(animation, { toValue: 1, duration: 50, useNativeDriver: true, }).start(); }; const endAnimation = () => { Animated.spring(animation, { toValue: 0, duration: 50, useNativeDriver: true, }).start(); console.log('end') }; //阻止中间内容点击事件穿透 function click(e) { if (process.env.TARO_ENV == 'weapp') { e.stopPropagation() } vibrate() } function onClick() { } function longPress(e) { if (process.env.TARO_ENV == 'weapp') { e.stopPropagation() } } function dismiss() { setIsDismiss(true) setTimeout(() => { props.dismiss() }, 250) } function rndismiss() { endAnimation() setTimeout(() => { props.dismiss() }, 250) } global.dismissModal = dismiss; if (process.env.TARO_ENV == 'rn') { return { rndismiss() }}> { props.children } } return { if (process.env.TARO_ENV == 'weapp') { e.stopPropagation() }; dismiss() }}> {props.title} { props.children } { props.confirm && props.confirm() }} style={{ backgroundColor: props.themeColor ?? MainColorType.fast }}>{props.btnTitle ?? '确定'} }