Login React Native + Firebase with error using "SwitchNavigator"

0

error (undefined is not a function (near '... (0, _reactNavigation.SwitchNavigator) ...')) when compiling application. >

I need to log in to the "Main" screen.

import React from 'react'
import { StyleSheet, Platform, Image, Text, View } from 'react-native'
import { SwitchNavigator } from 'react-navigation'

// import the different screens
import Loading from './Loading'
import SignUp from './SignUp'
import Login from './Login'
import Main from './Main'

// create our app's navigation stack
const App = SwitchNavigator(
  {
    Loading,
    SignUp,
    Login,
    Main
  },
  {
    initialRouteName: 'Loading'
  }
)

export default App
    
asked by anonymous 30.11.2018 / 11:44

1 answer

0

First you have to use createSwitchNavigator and not SwitchNavigator according to the switch navigator you have to use combining 2 navigators + switch to make authentication flows follow below example of how to use it

import { createSwitchNavigator, createStackNavigator } from 'react-navigation';
import Loading from './Loading'
import SignUp from './SignUp'
import Login from './Login'
import Main from './Main'

const NaoLogado = createStackNavigator({
  Login,
  SignUp,
  Loading,
}, {
  initialRouteName: 'Loading',
})

const Logado = createStackNavigator({
  Main
}, {
  initialRouteName: 'Main',
});

const criarNavigator = (condicao) => createSwitchNavigator({
  NaoLogado,
  Logado
}, {
  initialRouteName: condicao ? 'Logado' : 'NaoLogado'
});

export default criarNavigator
// No componente tu pode fazer assim

render() {
  const Router = criarNavigator(valor);

  return <Router />
}

If you are using version 3.0 of the react-navigation you will have to use it like this using% react-navigation%:

const criarNavigator = (condicao) => 
  createAppContainer(
    createSwitchNavigator(
      ...
    ),
  )
    
24.12.2018 / 15:24