2016-01-24 71 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下的信息。 –