简体   繁体   English

React Native + react-native-router-flux:如何将hideNavBar应用于仅一个 <Scene/> ?

[英]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. 在使用react-native-router-flux的React Native中,我有两个<Scene/> ,当我将hideNavBar应用于第一个Login ,即使它们处于同一级别,它也适用于第二个Home How can I apply hideNavBar to only one <Scene/> , Login ? 如何将hideNavBar应用于仅一个<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>
    )
  }
}

I am not sure about the reason. 我不确定原因。 Probably it persists some state parameters accross diferent actions/PUSH . 它可能会在不同的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. 从该路径开始,可以看到NavBar。 It is appropriate if your Login only appears once throughout your scene flow. 如果您的登录名在整个场景流程中仅出现一次,则是合适的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM