//@ts-nocheck import React, { Component } from 'react' import { View, Text, StyleSheet, TouchableHighlight, TextInput, ScrollView, Animated, Easing, KeyboardAvoidingView } from 'react-native' import { px2dp, onePx, colors, toastShort, isEmpty, filterSqlRows } from './../../utils'; interface Props { width?: string long?: string onConfirm?: Function, title?: string leftTitle?: string rightTitle?: string maxSizeLimit?: number leftPlaceHolder?: string leftValue?: string rightValue?: string rightPlaceHolder?: string descText1?: string descText2?: string }; export default class KitSetCustomBlockSizeToast extends Component { constructor(props) { super(props); this.state = { opacity: new Animated.Value(0), number1: "", number2: "", loading: false, codeExist: false }; this.active = false; this.show = this.show.bind(this) } public delayTimer = null; public delayTimer1 = null; public inputRef = null; componentWillUnmount() { this.delayHide && clearTimeout(this.delayHide); this.delayTimer && clearTimeout(this.delayTimer); this.inputRef && clearTimeout(this.inputRef); this.setState = (state, callback) => { return; } } show = ({ leftValue, rightValue }) => { if (leftValue && rightValue) { this.setState({ number1: leftValue, number2: rightValue }) } this.toast.setNativeProps({ style: { width: '100%', height: '100%', zIndex: 999 } }) Animated.timing( this.state.opacity, { toValue: 0.32, duration: 250, easing: Easing.in(), useNativeDriver: true } ).start(); this.delayTimer = setTimeout(() => { this.inputRef && this.inputRef.focus(); }, 200); } hide = () => { this.active = false; Animated.timing( this.state.opacity, { toValue: 0, duration: 100, easing: Easing.in(), useNativeDriver: true } ).start(); this.delayHide = setTimeout(() => { this.toast.setNativeProps({ style: { width: 0, height: 0, zIndex: -1 } }) }, 100); }; handleClose() { const { type } = this.props; const { onConfirm, leftTitle, rightTitle, leftPlaceHolder, rightPlaceHolder } = this.props; const { number1, number2 } = this.state; if (isEmpty(number1)) { return toastShort(leftPlaceHolder) } if (isEmpty(number2)) { return toastShort(rightPlaceHolder) } onConfirm && onConfirm({ containerLong: number1, containerWidth: number2 }) this.hide(); } firstNumberChange(text) { const { maxSizeLimit } = this.props; const { number1 } = this.state; 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("只能输入一个小数点后两位数"); } } if (Number(testText) > maxSizeLimit) { toastShort(`最大可输入${maxSizeLimit}`) this.setState({ number1 }) } else { this.setState({ number1: testText }) } }; onSecondNumberChange(text) { const { maxSizeLimit } = this.props; const { number2 } = this.state; 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("只能输入一个小数点后两位数"); } } if (Number(testText) > maxSizeLimit) { toastShort(`最大可输入${maxSizeLimit}`) this.setState({ number2 }) } else { this.setState({ number2: testText }) } }; render() { const { title = "", leftTitle = "", rightTitle = "", existText = "", leftPlaceHolder = "", rightPlaceHolder, maxSizeLimit = 20, descText1, descText2 } = this.props; const { number1, number2, loading, codeExist } = this.state; return ( this.toast = c} style={styles.alertContainer}> {title} this.inputRef = c} style={[styles.alertBodyInput, { flex: 1 }]} placeholder={leftPlaceHolder} keyboardType={'numeric'} maxLength={6} value={number1 ? number1 + '' : ''} onChangeText={this.firstNumberChange.bind(this)} /> m {/* 支持数字1-{maxSizeLimit} */} x m {/* 支持数字1-{maxSizeLimit} */} {descText1 ? descText1 : ''} {descText2 ? descText2 : ''} this.hide()} > 取消 this.handleClose()} > 确定 ) } } const styles = StyleSheet.create({ alertContainer: { position: 'absolute', width: '0%', height: '0%', justifyContent: 'center', alignItems: 'center', overflow: 'hidden', zIndex: -1 }, alertOverlay: { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, width: '100%', height: '100%', backgroundColor: '#000' }, alertContent: { width: px2dp(320), backgroundColor: '#fff', borderRadius: px2dp(8), justifyContent: 'space-between', alignItems: 'center', overflow: 'hidden' }, alertHeader: { width: '100%', justifyContent: 'center', alignItems: 'center', // backgroundColor: '#999', paddingTop: px2dp(18) }, alertBody: { width: '100%', height: px2dp(142), justifyContent: 'flex-start', alignItems: 'center', paddingHorizontal: px2dp(18), paddingTop: px2dp(16), }, alertBodyTop: { width: '100%', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }, alertBodyTopRight: { flex: 1, height: px2dp(24), flexDirection: 'row', justifyContent: 'flex-end', alignItems: 'center' }, alertBodyCenter: { flex: 1, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', paddingBottom: px2dp(2) }, alertBodyCenterHalf: { flex: 1, justifyContent: 'flex-start', alignItems: 'flex-start' }, alertBodyInput: { // width: '100%', flex: 1, height: px2dp(36), borderWidth: 1, borderColor: '#e9e9e9', borderRadius: px2dp(4), paddingHorizontal: px2dp(6), paddingVertical: px2dp(0), fontSize: 14, color: colors.blackColor }, title: { fontSize: 16, color: '#000', fontWeight: '600', lineHeight: 25, textAlign: 'center', letterSpacing: 0.8 }, borderTop: { borderBottomColor: '#d2d2d2', borderBottomWidth: onePx, width: px2dp(280), height: 1, }, alertFooter: { width: '100%', height: px2dp(52), justifyContent: 'center', alignItems: 'center', flexDirection: 'row', }, btn: { flex: 1, height: '100%', justifyContent: 'center', alignItems: 'center' }, border: { width: 1, height: px2dp(32), borderRightColor: '#d2d2d2', borderRightWidth: onePx }, testLine: { width: px2dp(24), justifyContent: 'center', alignItems: 'center', // backgroundColor: 'red', // marginTop: px2dp(-24) } })