react-native - TextInput 从右到左输入数字并自动添加零以进行货币输入
问题描述
我正在尝试TextInput
通过从右到左输入数字并在用户输入时自动添加零来实现。任何想法如何正确实施?
预期的行为应该是这样的。
我现在拥有的:
constructor(props) {
super(props);
this.state = {
payrate: '',
};
}
handleTextChange = (text) => {
const newAmount = parseFloat(text/100);
this.setState({
payrate: newAmount,
})
<TextInput
autoFocus
style={[styles.textInput]}
value={payrate}
placeholder="0.00"
maxLength={9}
keyboardType="numeric"
placeholderTextColor="#adecf5"
onChangeText={this.handleTextChange}
underlineColorAndroid='rgba(0,0,0,0)'
autoCapitalize="none"
selection={{start: cursor, end: cursor}}
/>
解决方案
我们为此使用 react-native-masked-text,效果很好。https://github.com/benhurott/react-native-masked-text/blob/master/README.md
推荐阅读
- c# - 无法与 Http2And3 一起启动 Kestrel
- javascript - 从另一个组件重新渲染反应组件的正确方法
- angular - 使用 Angular 问题打破子元素
- c# - DisplayPromptAsync hangs on Uno Platform for Xamarin Forms WASM
- android - 如何删除perfetto写的痕迹
- python - ImportError:无法导入名称“download_url_to_file”
- git - git - 如何安全地存储 https 连接的用户名和密码?
- elasticsearch - Elasticsearch 无痛返回错误的长值
- python - Django F() 和 ExpressionWrapper
- c# - 内存数据库提供程序中的实体框架奇怪的行为