How to disable the back button on certain React Navigation routes with React Native

Asked

Viewed 566 times

2

Hi, I’m working with React Navigation and I’m having problems regarding the "back" button on certain screens.

My Navigator is as follows:

import React from 'react'
import { FluidNavigator } from 'react-navigation-fluid-transitions'

import SplashScreen from '../../screens/SplashScreen'
import LoginScreen from '../../screens/LoginScreen'
import RegisterCodeScreen from '../../screens/RegisterScreen/RegisterCodeScreen'
import RegisterEmailScreen from '../../screens/RegisterScreen/RegisterEmailScreen'
import RegisterInfoScreen from '../../screens/RegisterScreen/RegisterInfoScreen'
import LanScreen from '../../screens/LanScreen'

export default Navigator = FluidNavigator({
  SplashScreen: { screen: SplashScreen },
  LoginScreen: { screen: LoginScreen, },
  RegisterEmailScreen: { screen: RegisterEmailScreen },
  RegisterCodeScreen: { screen: RegisterCodeScreen },
  RegisterInfoScreen: { screen: RegisterInfoScreen },
  LanScreen: { screen: LanScreen }
});

I need to block the "back" only on the screens LoginScreen and LanScreen and for that (at the moment) I am using the resource below:

export defaut class LoginScreen extends React.Component {

  componentDidMount() {
    BackHandler.addEventListener('hardwareBackPress', () => true);
  }

  // ....

}

The problem is that using Backhandler causes it to disable on all routes and I don’t want it... How to solve?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.