【发布时间】:2021-04-09 15:30:45
【问题描述】:
我在每次按下输入键盘的按钮和当前页面首次加载时触发 onSubmitEditing 时遇到问题(该部分特别令人费解)。 TextInput 代码如下:
const TimerInput = () => {
const [ value, onChangeText ] = React.useState('');
return (
<TextInput
style={{
backgroundColor: ColorScheme.Orange.e,
borderRadius: 10,
borderWidth: 0,
fontSize: 25,
height: 60,
textAlign: 'center',
shadowColor: 'gray',
shadowRadius: 10,
width: '80%',
}}
keyboardType = 'number-pad'
onSubmitEditing = {FormatTime(value)}
onChangeText = { text => onChangeText(text) }
placeholder = { ' Hours : Minutes : Seconds ' }
returnKeyType = 'done'
value = {value}
/>
);
}
FormatTime 函数只是在我试图弄清楚这一点时写入控制台:
FormatTime = () => {
return (
console.log('test')
);
}
我希望实现的行为是仅在按下“完成”按钮关闭输入键盘时才运行 FormatTime。老实说,我不完全确定 TextInput 是如何工作的(即我对“值”和“文本”之间的区别感到非常困惑),所以我可能在这里遗漏了一些明显的东西。非常感谢您的帮助。
【问题讨论】:
标签: react-native textinput react-native-textinput