当退格和TextInput的长度= 0时,我如何获得事件?



这是我的代码React native:从" React "import {View, StyleSheet, textput} from "react-native"

const UselessTextInput = () => {
const [text, onChangeText] = React.useState("");
const [number, onChangeNumber] = React.useState(null);
return (
<View>
<TextInput
style={styles.input}
onChangeText={onChangeText}
value={text}
/>
</View>
);
};
const styles = StyleSheet.create({
input: {
height: 40,
margin: 12,
borderWidth: 1,
},
});
export default UselessTextInput;
链接博览会:https://snack.expo.dev/@robocon321/textinput

使用onKeyPress

onKeyPress={({ nativeEvent }) => {
if (nativeEvent.key === 'Backspace') {
alert("Backspace is pressed")
} 
}}

try snack here

工作于ios &android

android上的备注!

注意:Android只处理软键盘的输入,不处理硬件键盘的输入。

soft keyboard(屏幕键盘或软件键盘)类似手机或平板电脑屏幕上的键盘。
hardware keyboard(外置键盘)像USB键盘(android支持),但你可以忽略它。

最新更新