隨着react-navigation的逐漸穩定,navigator光榮退休react
導航器也能夠當作是一個普通的React組件,你能夠經過導航器渲染通用元素,例如可配置的標題欄和選項卡欄bash
Screen navigation prop(屏幕導航屬性)
:經過navigation能夠完成屏幕之間的調度操做,例如打開另外一個屏幕Screen navigaionOptions(屏幕導航屬性)
:經過navigationOptions能夠定製導航器顯示屏幕的方式(例如:頭部標題,選項卡標籤等)const SomeNav=createStackNavigator/createBottomTabNavigator/createMaterialTopTabNavigator({})
<SomeNav
screenProps={xxx}
ref={nav=>navigation=nav;}
onNavigationStateChange=(prevState,newState,action)=>{}
/>
複製代碼
當導航器中的屏幕被打開時,他會收到一個navigation prop, navigation prop是整個導航環節中的關鍵一員ui
當且僅當navigator是stacknavigation時,this.props.navigation上有一些特殊功能this
navigation.navigate({routeName,params,action,key})
或navigation.navigate(routeName,params,action)
export const AppStacknavigator=createStackNavigator({
HomeScreen:{
screen:HomeScreen
},
Page1:{
screen:Page1
}
})
class HomeScreen extends React.Component{
render(){
const {navigate}=this.props.navigation;
return (
<View>
<Text>This is HomeScreen</Text>
<Button
onPress={()=>navigate('Page1',{name:"Devio"})}
title="Go to Page1"
/>
</View>
)
}
}
class Page1 extends React.Component{
render(){
const {navigate}=this.props.navigation;
return (
<View>
<Text>Page1</Text>
</View>
)
}
}
複製代碼
能夠經過this.props.state.params來獲取經過setParams()/navigation.navigate()傳遞的參數spa