在React Native中按下Android后退按钮时如何防止键盘关闭?

时间:2019-05-19 11:22:17

标签: android react-native keyboard back-button

您可以使用BackHandler在本机反应中覆盖Android后退按钮功能。但是,当键盘打开并且按下后退按钮而不是进入hardwareBackPress侦听器时,键盘将关闭。

1 个答案:

答案 0 :(得分:0)

解决方案可能是这样

state = { keyboardopen: false };

BackHandler.removeEventListener("hardwareBackPress", this.handleBackPress);

Keyboard.addListener(
  "keyboardDidShow",

  () => this.setState({ keyboardopen: !keyboardopen })
);

handleBackPress = () => {
  if (keyboardopen) {
    // do some thing
  } else {
    //do some thing else
  }
};