UNPKG

@uiw/react-native

Version:
51 lines 1.47 kB
import React from 'react'; import { StyleSheet, TextInput } from 'react-native'; import { styles as ControlStyle } from './ControlValue'; var Width; (function (Width) { Width[Width["small"] = 50] = "small"; Width[Width["default"] = 70] = "default"; Width[Width["large"] = 100] = "large"; })(Width || (Width = {})); function ShowValue(props) { const { size, value, textInput, color, disabled, width, onChange } = props; const endCallback = () => { if (value === '' || isNaN(parseFloat(value))) { onChange('min'); return; } onChange(parseFloat(value)); textInput.current && textInput.current.blur(); }; return <TextInput editable={disabled} // 禁用 keyboardType="numeric" value={value} onChangeText={text => { let i = text.indexOf('.'); i = text.indexOf('.', i + 1); if (i === -1) { onChange(text); } }} onSubmitEditing={endCallback} onEndEditing={endCallback} ref={textInput} style={[ControlStyle.elementCenter, ControlStyle.textWeight, ControlStyle[size], styles.border, { paddingVertical: 0, fontSize: ControlStyle[`${size}Text`].fontSize - 8, textAlign: 'center', borderColor: color.borderColor || color.color, color: color.valueColor || color.color, width: width ?? Width[size] }]} />; } const styles = StyleSheet.create({ border: { borderWidth: 1, borderLeftWidth: 0, borderRightWidth: 0 } }); export default ShowValue;