【发布时间】:2021-09-25 02:22:43
【问题描述】:
我正在尝试在react native 中制作这个OTP (6 digits) 输入框。
会发生什么 - 当用户按下任何键(backspace 键除外)时,它应该跳到下一个框,当用户按下 backspace 键时,它应该回到上一个框。
到目前为止,它在iOS 上运行良好,然后当我检查Android 时,它根本不会跳转到下一个框。我在网上查了一下,发现Android不支持onKeyPress。没有onKeyPress,我怎样才能使它适用于android?我应该使用onChange 吗?但是我怎么知道用户是否按下了backspace?
<TextInput
editable={editable}
value={input_1}
style={styles.inputBox}
keyboardType='number-pad'
ref={box_1}
// onChange={({ text }) => {
// setInput_1(text);
// }}
onFocus={() => {
}}
onKeyPress={({ nativeEvent }) => {
if (nativeEvent.key === 'Backspace') {
box1.current.focus();
} else {
focus(1);
}
}}
/>
谢谢。
【问题讨论】:
标签: javascript android react-native textinput