简体   繁体   English

TextInput 在 React Native 中不显示数字

[英]TextInput not Showing number in React Native

i have set textinput keyboardtype to numeric but i cannot change number when i click on increment and decrement button.我已将 textinput keyboardtype 设置为数字,但当我单击递增和递减按钮时无法更改数字。 when i set number it disappears.当我设置数字时它消失了。 it only take number with quotes how can i have number in inputtext?它只需要带引号的数字我怎么能在输入文本中有数字?

  const [textval, setTextval] = useState('0');

 const handleminmax = minmax => {
if (minmax === 'min') {
  setTextval(oldval => Number(oldval) - 1);
} else if (minmax === 'max') {
  setTextval(oldval => Number(oldval) + 
1);
}
};

<Icon
    name={'caretleft'}
    size={14}
    color={'grey'}
    onPress={() => {
      handleminmax('min');
    }}
  />
<TextInput
    theme={{roundness: 10}}
    value={isEmpty(value) ? textval : textval}
    error={onerror}
    keyboardType={'numeric'}
    onBlur={onblur}
    outlineColor={'#CFCFCF'}
    secureTextEntry={secureTextEntry}
    placeholder={placeholder}
    style={[
      {
        backgroundColor: bgColor ?? '#f0f0f0',
        width: width ?? 50,
        borderColor: bc ?? 'grey',
        borderWidth: bw ?? 1,
        borderRadius: br ?? 12,
        padding: padding ?? 5,
        color: color ?? APP_SECONDARY_COLOR,
        fontWeight: fw ?? 'bold',
        textAlign: 'center',
        fontSize: 18,
      },
      StylesTextInput,
    ]}
    mode={mode ? mode : 'outlined'}
    onChangeText={onchange}
  />
<Icon
    name={'caretright'}
    size={14}
    color={'grey'}
    onPress={() => {
      handleminmax('max');
    }}

Try Converting the Numeric Value into String Before Displaying in Textinput Component在 Textinput 组件中显示之前尝试将数值转换为字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM