Preventing hardware back button android for React Native

后端 未结 9 1626
醉梦人生
醉梦人生 2020-12-08 19:05

I want to prevent the user from going back to the previous screen. So I added code, but this does not work. Are there any solutions for this? The alert pop up is seen but \"

9条回答
  •  悲&欢浪女
    2020-12-08 19:16

    If you are using react-natigation then you need to use BackHandler instead of BackAndroid

    import { BackHandler } from 'react-native';
    
    // code
    
    componentDidMount() {
      BackHandler.addEventListener('backPress');
    }
    
    // some more code
    
    componentWillUnmount() {
      BackHandler.removeEventListener('backPress');
    }
    

提交回复
热议问题