android - React Native Android Hardware Back 按钮无法正常工作
问题描述
登录屏幕.js
this.props.navigator.push({
screen: "auxxa.LandingScreen",
passProps: { login: true },
overrideBackPress: true,
navigatorStyle: {
navBarHidden: true
}
});
LandingScreen.js
constructor(props) {
super(props);
this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
// this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
this.state = {
size: { width, height },
tileData: null,
isLoading: true,
user_id: null,
refetching: false,
access_token: null
};
}
componentWillMount() {
BackHandler.addEventListener(
"hardwareBackPress",
this.handleBackButtonClick
);
}
handleBackButtonClick() {
console.log("check login " + this.props.login);
if (this.backPressed && this.backPressed > 0) {
if (this.props.login) {
console.log("login");
RNExitApp.exitApp();
} else {
console.log("root");
this.props.navigator.popToRoot({ animated: false });
return false;
}
}
this.backPressed = 1;
this.props.navigator.showSnackbar({
text: "Press one more time to exit",
duration: "long"
});
return true;
}
componentDidMount() {
BackHandler.removeEventListener(
"hardwareBackPress",
this.handleBackButtonClick
);
}
我使用Wix 的 react-native-navigation 来进行应用导航。这里我附加了登录屏幕和登录屏幕。成功登录后应用导航到登录屏幕。之后我点击返回按钮它将返回登录屏幕。我需要避免那个。我该怎么做?我试图退出应用程序。但它也无法正常工作。如果有人知道这一点,请帮助我。在此先感谢。
解决方案
在 handleBackButtonClick 函数中使用此调用,为什么要删除 componentDidMount 中的侦听器?
this.props.navigator.resetTo({ screen: 'example.ScreenThree'})
.
推荐阅读
- ios - 使用位码构建框架
- c# - 当我将鼠标悬停在 ListView 对象上时,我想显示一个窗口(覆盖)
- spring-boot - 如何运行完全符合 FIPS 的 Spring Boot 应用程序
- java - CORS 问题 - 对预检请求的响应未通过访问控制检查:
- javascript - HTML 表格不与 HTML 表格一起打印
- python - 'ValueError: day is out of range for month' 因为数据中所有月份的所有日期都有 31 天
- daml - 前模型样本中引用的“da”工具是什么?
- r - geom_smooth 只在我的图例中添加线条,而不是情节本身
- php - 在 Windows 10 上的 apache2.4 上启动 laravel 应用程序
- glib - Libqmi - glib 回调函数没有被调用