How Do I handle Hardware back button of android to screen which I given to navigation.navigate in react native

蓝咒 提交于 2021-02-11 13:25:27

问题


I am new to react native. I want that when I press android Hardware back button. I navigate to page or screen which name I have given To that navigation.navigate

I have made this

constructor(props) {
    super(props)
    this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
}

componentDidMount() {
    BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonClick);
}

componentDidUnmount() {
    BackHandler.removeEventListener('hardwareBackPress', this.handleBackButtonClick);
}

handleBackButtonClick() {
    this.props.navigation.navigate("Browse");
    return true;
}

But using this code Its only navigate to previous screen from which I have come. I want to navigate to "browse" screen. please help. thanks

来源:https://stackoverflow.com/questions/66061426/how-do-i-handle-hardware-back-button-of-android-to-screen-which-i-given-to-navig

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!