问问题
1057 次
2 回答
10
这并不总是一种选择,但是,添加:
keyboardType={'ascii-capable'}
到 TextInput 为我修复了它
于 2020-07-17T20:42:48.577 回答
2
事实上,这是 TextInput 的 iOS 实现的一个问题,但我可以为您提供一个解决方法。诀窍是检查 TextInput 的特殊字符值,然后适当地替换这些字符。请参见下面的示例,其中我将每个“-”替换为“--”。
代码
const UselessTextInput = () => {
const [value, setText] = React.useState('-'); // change this to '' to see the difference
function handleTextChange (value) {
var val = value;
// check if value contains special characters
if (value.includes("—")){
//replace values appropriately
val = value.replace("—", "--");
}
//set new text
setText(val);
}
return (
<TextInput
style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
onChangeText={(text) => handleTextChange(text)}
value={value}
/>
);
}
工作示例:
于 2019-09-19T06:09:28.173 回答