-
Notifications
You must be signed in to change notification settings - Fork 0
navigator
brainpoint edited this page Mar 2, 2017
·
2 revisions
'use strict';
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, } from 'react-native';
import { Navigator } from 'react-componet'
let Route = Navigator.Route;
class app extends Component {
// router配置可查看 react-router
routeConfig(){
return (
<Route path="/" component={IndexView}>
<Route path="about" component={AboutView} >
<Route path="inbox" component={InboxView}/>
<Route path="messages/:id" component={MessageView} />
</Route>
<Route path="*" component={_404View}/>
</Route>
);
}
render() {
return (
<Navigator
defaultTitle={{ text: 'Title', }}
defaultLeftButton={{ text: 'Back', }}
defaultRightButton={{ text: 'Forward', onPress:()=> Navigator.pop() }}
defaultBarTintColor='#2112'
configureScene={Navigator.SceneConfigs.FloatFromBottom}
>
{/* route 可嵌套定义. */}
{this.routeConfig()}
</Navigator>
);
}
}Navigator对象只能全局一个, 可使用静态方法
- Navigator.SceneConfigs.PushFromRight (默认)
- Navigator.SceneConfigs.FloatFromRight
- Navigator.SceneConfigs.FloatFromLeft
- Navigator.SceneConfigs.FloatFromBottom
- Navigator.SceneConfigs.FloatFromBottomAndroid
- Navigator.SceneConfigs.FadeAndroid
- Navigator.SceneConfigs.HorizontalSwipeJump
- Navigator.SceneConfigs.HorizontalSwipeJumpFromRight
- Navigator.SceneConfigs.VerticalUpSwipeJump
- Navigator.SceneConfigs.VerticalDownSwipeJump
Navigator.Route: 可以包含如下的属性.
{
component: PropTypes.node,
barTitle: this.PropTypes.defaultTitle // 当无此属性时使用defaultBarTitle属性.
barLeftButton: this.PropTypes.defaultLeftButton // 当无此属性时使用defaultBarLeftButton属性.
barRightButton: this.PropTypes.defaultRightButton // 当无此属性时使用defaultBarRightButton属性.
barTintColor: this.PropTypes.defaultBarTintColor// 当无此属性时使用defaultBarTintColor属性.
barHidden: PropTypes.bool.
translucent: PropTypes.bool // 是否半透明(仅ios)
configureScene: Navigator.SceneConfigs.FloatFromBottom // 动画信息
}- Route可以嵌套定义.但要严格按照父子顺序排序, 便于系统查找上下级关系.
- 当地址是 /:id 此方式带参数的时, route.params.xxx 为参数.
- 地址的查询参数 ?xx= 可以在 , route.query.xxx 中查询
默认的标题, 当页面不指定标题时使用默认标题. 可以为如下类型数据:
1.属性对象
{
text: PropTypes.string,
tintColor: PropTypes.string,
image: Image.propTypes.source (仅ios)
style: PropTypes.object,
}2.或者为react元素,如<Text></Text>
导航条的默认左/右按钮, 当页面不指定标题时使用默认按钮; 可以为如下类型数据:
1.属性对象
{
text: PropTypes.string.isRequired,
tintColor: PropTypes.string,
onPress: PropTypes.func, /* 方法形式为 function(navigator),
如果对象存在属性 onLeftButtonPress/onRightButtonPress 则使用属性指定的方法,
否则才使用此属性指定的方法;
寻找按钮事件的顺序为: navigator.onLeftButtonPress > route.barLeftButton.onPress > defaultBarLeftButton.onPress
如果任何事件都没有, leftButton默认为pop()后退.*/
style: PropTypes.object,
}2.或者为react元素,如<Text></Text>
如果为true则, 左按钮text自动为上一页面的标题, 忽略defaultLeftButton.text; 但不忽略route的leftButton.text
导航条背景色
是否隐藏导航条
动画信息. 默认为 Navigator.SceneConfigs.FloatFromBottom
压入一个页面
- path: 新页面的地址
- props: 可以包含如下的属性. 可以覆盖route配置中的数据.
{
barTitle: this.PropTypes.defaultTitle // 当无此属性时使用defaultBarTitle属性.
barLeftButton: this.PropTypes.defaultLeftButton // 当无此属性时使用defaultBarLeftButton属性.
barRightButton: this.PropTypes.defaultRightButton // 当无此属性时使用defaultBarRightButton属性.
barTintColor: this.PropTypes.defaultBarTintColor// 当无此属性时使用defaultBarTintColor属性.
barHidden: PropTypes.bool.
translucent: PropTypes.bool // 是否半透明(仅ios)
configureScene: Navigator.SceneConfigs.FloatFromBottom // 动画信息
passProps: PropTypes.object // 可将属性传递给页面
}使用一个route替换当前页面
使用一个route替换stack前的一个页面
回到前一个页面
回到最顶层的页面
回到指定的页面
清除stack,并使用一个页面替换
设置导航栏的状态.
设置导航栏的状态.
当前页面的导航按钮的事件处理函数. 形式为 function(ev), 在其他组件中绑定导航处理事件时,最好在componentWillMount中绑定
当前页面的完成加载后的事件处理函数. 形式为 function(route), 在其他组件中绑定导航处理事件时,最好在componentWillMount中绑定
是否允许回退手势.