import React from 'react'; import { SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, Image, TouchableOpacity, View, DeviceEventEmitter } from 'react-native'; import FastImage from 'react-native-fast-image'; import { TextInput } from 'react-native-gesture-handler'; import Animated, { useAnimatedStyle, useSharedValue, withSpring, withTiming } from 'react-native-reanimated'; import { BjInstanceActualMeasurementResearchTableRow } from '../../database/Instance'; import { colors, deepCopy, handleDismissKeyboard, isEmpty, onePx, px2dp, toastShort } from '../../utils'; import { BjTypeActualMeasurementResearchTableRow } from '../../utils/types'; interface Props { } interface State { row: BjTypeActualMeasurementResearchTableRow } interface TypeResearch { name: string type: string } const GroundDiameterDialog = () => { const containerRef = React.useRef(null); const delayTimer = React.useRef(null); const delayTimer1 = React.useRef(null); const overlayOpacity = useSharedValue(0.1); const layoutScaleValue = useSharedValue(1); const [tempRow, setTempRow] = React.useState(deepCopy(BjInstanceActualMeasurementResearchTableRow)); const showToastListener = React.useRef(null); const hideToastListener = React.useRef(null); const tempKey = React.useRef(null); React.useEffect(() => { overlayOpacity.value = withTiming(0.2); layoutScaleValue.value = withSpring(0); showToastListener.current = DeviceEventEmitter.addListener('show-ground-diameter-dialog', (a) => { tempKey.current = a.key; console.log("a.row", a.row) setTempRow(deepCopy(a.row)); delayTimer.current = setTimeout(() => { handleShowToast() }, 0); }); hideToastListener.current = DeviceEventEmitter.addListener('hide-ground-diameter-dialog', (a) => { handleHideToast() }); return () => { delayTimer.current && clearTimeout(delayTimer.current); delayTimer1.current && clearTimeout(delayTimer1.current); showToastListener.current && showToastListener.current?.remove(); hideToastListener.current && hideToastListener.current?.remove(); } }, []); const handleShowToast = () => { requestAnimationFrame(() => { containerRef.current.setNativeProps({ style: { width: '100%', height: '100%' } }) delayTimer1.current = setTimeout(() => { overlayOpacity.value = 0.52; layoutScaleValue.value = 1; }, 0); }) }; const handleHideToast = () => { delayTimer.current = setTimeout(() => { containerRef.current.setNativeProps({ style: { width: 0, height: 0 } }) }, 240); overlayOpacity.value = 0.1; layoutScaleValue.value = 0; handleDismissKeyboard(); } const handleComfirmToast = () => { DeviceEventEmitter.emit('on-ground-diameter-dialog-finish', { key: tempKey.current, tempRow: tempRow }) handleHideToast(); } const overlayAnimatedStyle = useAnimatedStyle(() => { return { opacity: withTiming(overlayOpacity.value, { duration: 240 }) } }); const toastBodyAnimatedStyle = useAnimatedStyle(() => { return { transform: [ { scale: withSpring(layoutScaleValue.value, { stiffness: 96 }), } ], opacity: withTiming(layoutScaleValue.value, { duration: 120 }), } }) const _onTextChange = (propName, text) => { let _tempRow = tempRow; let testText = text.replace(/[^\d^\.]+/g, ''); let arr1 = testText.split('.'); if (arr1.length > 2) { return toastShort("只能输入一个小数点"); } else { if (arr1[1] && arr1[1].length > 2) { return toastShort("只能输入一个小数点后两位数"); } } _tempRow[propName] = testText; setTempRow(deepCopy(_tempRow)) }; return ( 地径(cm) 最小 _onTextChange('minGroundDiameter', text)} /> 平均 _onTextChange('averageGroundDiameter', text)} /> 最大 _onTextChange('maxGroundDiameter', text)} /> 取消 确定 ) }; const styles = StyleSheet.create({ overlay: { position: 'absolute', top: 0, bottom: 0, left: 0, right: 0, width: '100%', height: '100%', backgroundColor: '#000', zIndex: -1 }, container: { position: 'absolute', top: 0, bottom: 0, left: 0, right: 0, zIndex: 999, width: 0, height: 0, overflow: 'hidden' }, content: { position: 'relative', width: '100%', height: '100%', flex: 1, justifyContent: 'center', alignItems: 'center', // backgroundColor: 'red' }, toastBody: { width: px2dp(300), minHeight: px2dp(200), backgroundColor: '#fff', borderRadius: px2dp(8), elevation: 12, justifyContent: 'space-between', alignItems: 'center', paddingVertical: px2dp(12) }, dialogHeader: { width: px2dp(268), height: px2dp(32), borderBottomWidth: 1, borderBottomColor: '#909399', flexDirection: 'row', justifyContent: 'center', alignItems: 'center', paddingHorizontal: px2dp(2) }, dialogHeaderRight: { flexDirection: 'row', justifyContent: 'flex-end', alignItems: 'center' }, footer: { width: px2dp(272), flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginTop: px2dp(24) }, footerLeftBtn: { width: px2dp(133), height: px2dp(36), borderRadius: px2dp(18), justifyContent: 'center', alignItems: 'center', backgroundColor: '#00D38F58', borderTopRightRadius: px2dp(3), borderBottomRightRadius: px2dp(3), }, footerRightBtn: { width: px2dp(133), height: px2dp(36), borderRadius: px2dp(18), justifyContent: 'center', alignItems: 'center', backgroundColor: colors.themeColor, borderTopLeftRadius: px2dp(3), borderBottomLeftRadius: px2dp(3) }, selectItem: { flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', borderBottomWidth: 1, borderBottomColor: '#303133', paddingTop: px2dp(16) }, selectItemName: { fontSize: 16, color: '#303133', marginLeft: px2dp(3) }, group: { width: px2dp(268), backgroundColor: '#f2f5f8', paddingHorizontal: px2dp(8), borderRadius: px2dp(3), marginTop: px2dp(12), paddingVertical: px2dp(6), }, groupRow: { width: '100%', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', marginBottom: px2dp(8) }, groupTitle: { fontSize: 15, color: '#303133', marginBottom: px2dp(5) }, groupHeader: { }, item: { height: px2dp(42), flex: 1, // backgroundColor: 'red' }, itemTitle: { fontSize: 14, color: '#303133' }, itemInput: { width: '100%', height: px2dp(24), lineHeight: px2dp(24), justifyContent: 'center', alignItems: 'center' } }) export default GroundDiameterDialog;