2016-01-24 67 views

回答

0

你可以使用这样的:

<Navigator 
    initialRoute={{name: 'My First Scene', index: 0}} 
    renderScene={(route, navigator) => { 
    return <Page navigator={navigator} name={route.name} index={route.index}/> }} 
    navigationBar={ 
    <Navigator.NavigationBar routeMapper={NavigationBarRouteMapper} />} 
/> 

var NavigationBarRouteMapper = { 
    LeftButton(route, navigator, index, navState) { 
    if(index > 0) { 
     return (
     <TouchableHighlight style={{marginTop: 10}} onPress={() => { 
      if (index > 0) { 
       navigator.pop(); 
      } 
     }}> 
     <Text>Back</Text> 
    </TouchableHighlight> 
)} else { 
return null} 
}, 
    RightButton(route, navigator, index, navState) { 
    return null; 
    }, 
    Title(route, navigator, index, navState) { 
    return <Text>My Title</Text> 
    } 
}; 

Here是阵营本地导航栏示例项目文件夹:https://github.com/facebook/react-native/blob/master/Examples/UIExplorer/Navigator/NavigationBarSample.js

两个其他的方式来了解这个:

  1. 下载React Native并在UI Explorer project运行Navigator Examples(这本身是一个很酷的PLA以了解所有本地模块/组件)。

  2. Here与实施的导航栏一个RNPlay项目。

+0

谢谢,这是有帮助!但是在你的导航映射器中,你怎么知道使用属性'LeftButton','RightButton'和'Title',以及那些参数? – ffxsam

+0

当然,退房https://github.com/facebook/react-native/blob/master/Libraries/CustomComponents/Navigator/NavigatorNavigationBar.js。看看这些proptypes。另外https://github.com/facebook/react-native/tree/master/Libraries/CustomComponents/Navigator获取更多有关Navigator下的信息。 –