如果创建大写字母,则 TextInput 值上的 toLowerCase 会创建重复文本 [英] toLowerCase on TextInput value is creating duplicate text if capital letter created
问题描述
这个很有趣.
我创建了一个 TextInput,它接受一个值,然后将其小写,将其添加到状态,并将其设置为默认值.在我的 android 物理设备上,如果您强制使用大写字母(自动大写设置为无),然后快速点击其他字母,它将复制并添加额外的文本.
I created a TextInput that takes a value, then lower cases it, adds it to state, and sets it as the default value. On my android physical device, if you force a capital letter ( autocapitalize is set to none), and then quickly tap other letters, it will duplicate and add extra text.
有没有办法避免这种情况?
Is there a way to avoid this?
这是小吃https://snack.expo.io/Hk1reKHJ4
在你的安卓或模拟器上运行它,点击键盘上的大写按钮,点击其他几个字母,再次点击大写,点击其他几个字母,你应该设置这个错误.
Run it on your android or on the simulator, tap the upper case button on the keyboard, tap a few other letters, tap the upper case again, tap a few other letters, and you should set this error.
谢谢!
export default class App extends React.Component {
constructor(props) {
super(props)
this.state = {
text: ''
}
}
render() {
return (
<View style={styles.container}>
<TextInput
style={ styles.inputContainer }
defaultValue={ this.state.text }
autoCapitalize="none"
onChangeText={ value => this.setState({
text: value.trim().toLowerCase()
})}
/>
</View>
);
}
}
推荐答案
不幸的是,这是一个已经开放了几年没有解决方案的问题,您可以查看 这个线程,没有人找到解决方案.在 React Native 团队修复这个 bug 之前有一个临时的解决方法,因为它似乎需要太长时间,请查看 这里.
Unfortunately this is an issue that has been open for a couple of years with no solution, you can check this thread, no one found a solution. There is a temporary workaround until the React Native team fixes this bug as it seems to be taking too long, check it out here.
这篇关于如果创建大写字母,则 TextInput 值上的 toLowerCase 会创建重复文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!