Ly Maneug Ly Maneug - 2 months ago 20
React JSX Question

React Native + react-native-router-flux: How to apply hideNavBar to only one <Scene/>?

In React Native using react-native-router-flux, I have two

<Scene/>
and when I apply
hideNavBar
to the first one,
Login
, it also applies to the second,
Home
even though they are on the same level. How can I apply
hideNavBar
to only one
<Scene/>
,
Login
?

const RouterWithRedux = connect()(Router)
const store = configureStore()

export default class App extends Component {
render() {
return (
<Provider store={store}>
<RouterWithRedux>
<Scene key='root'>
<Scene component={Login} hideNavBar initial={true} key='login' title='Login'/>
<Scene component={Home} key='home' title='Home'/>
</Scene>
</RouterWithRedux>
</Provider>
)
}
}

Answer

I am not sure about the reason. Probably it persists some state parameters accross diferent actions/PUSH. As a workaround, you can always try to be explicit: it worked for me.

const RouterWithRedux = connect()(Router)
const store = configureStore()

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <RouterWithRedux>
          <Scene key='root'>
            <Scene component={Login} hideNavBar initial={true} key='login' title='Login'/>
            <Scene component={Home} hideNavBar={false} key='home' title='Home'/>
          </Scene>
        </RouterWithRedux>
      </Provider>
    )
  }
}

From that route on, NavBar is visible. It is appropriate if your Login only appears once throughout your scene flow.

Comments