React-native - TextInput 小数点在 iOS 上显示逗号而不是点

标签 react-native react-native-textinput

某些 iOS 设备似乎显示 , (逗号)而不是 .在小数点上。我相信这与键盘语言/语言环境有关。有什么办法可以强制使用 decimal-pad显示一个 .无论键盘语言/语言环境如何?

<TextInput
    rejectResponderTermination={false}
    style={[
        {
            fontSize: entryValueFontSize,
            height: height,
        },
        calculatorStyles.inputsShared,
        calculatorStyles.amountInput,
        theme.inputsShared,
    ]}
    autoCapitalize={'none'}
    placeholder={entryValueLabel}
    placeholderTextColor={theme.placeholderTextColor}
    keyboardType={'decimal-pad'}
    returnKeyType={'done'}
    defaultValue={''}
    value={isNaN(this.state.entryValue) ? '' : this.state.entryValue}
    onChangeText={(entryValue) => {
        this.onEntryValueChange(entryValue);
    }}
/>
问题:
enter image description here
期望的输出:
enter image description here

最佳答案

无法强制键盘使用逗号。它基于地区,例如捷克语有逗号。我创建的解决方案是在输入逗号后用点替换小数点的逗号

<TextInput
  onChangeText={(entryValue) => {
    // I am passing keyboardType as prop
    if (keyboardType === 'decimal-pad') {
      this.onEntryValueChange(entryValue.replace(',', '.'));
    } else {
      this.onEntryValueChange(entryValue);
    }
  }}
/>

关于React-native - TextInput 小数点在 iOS 上显示逗号而不是点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63420777/

相关文章:

react-native - 如何获取 String of TextInput 中的当前行数?

node.js - 离开屏幕回调 React Navigation Tab Navigator

javascript - 使用 firebase 身份验证和 firestore 添加用户

javascript - ReactJS 中未处理的拒绝

react-native 从文本组件获取选择文本的开始和结束

react-native - 按下 textinput 隐藏模态 react-native-modal

android - 聚焦文本输入时如何处理后退按钮

reactjs - 使用 TypeScript 在 React Native 上传递 refs : (property) React. MutableRefObject<null>.current : null Object is possibly 'null' . ts(2531)

javascript - 一个月内的小时数的数学函数

ios - 如何使用 ES6 语法对 React Native 中的 "Unexpected token, expected ; (44:33)"进行故障排除