react-native 页面切换的实现

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
'use strict';
var React = require('react-native');
var {
    AppRegistry,
    Component,
    StyleSheet,
    Text,
    View,
    TouchableOpacity,
    ListView,
    NavigatorIOS,
    TouchableHighlight,
} = React;

var dazhongdemo=React.createClass({
    OnRightButtonPress:function(){
      this.refs.nav.push({
          title:'设置',
          component:ForRightScene      //点击导航右侧的按钮跳转到的页面
      })
    },
    render:function() {
        return (
            <NavigatorIOS ref="nav"
                          style={styles.container}
                initialRoute={{
                component: HomeScene,//在NavigatorIOS中显示的第一个组件
                title: '主页',//组件的标题
                rightButtonTitle:'下一页',//导航工具栏右侧按钮显示的文本
                onRightButtonPress:this.OnRightButtonPress//当点金右侧按钮时执行的函数
                }}
            />
        );
    },
});
//实现第一个页面HomeScene
var HomeScene=React.createClass({
    onPress:function(){
      this.props.navigator.push({
          title:'个人中心',
          component:ForTouchScene
      });
    },
    render:function(){
         return (
            <View style={[styles.scene,{backgroundColor:'#DAF6FF'}]}>
                <TouchableHighlight onPress={this.onPress}>
                    <Text>点击进入个人中心</Text>
                </TouchableHighlight>
            </View>
        );
    },
});
//实现设置页面
var ForRightScene=React.createClass({
    render:function(){
        return(
            <View style={[styles.scene,{backgroundColor:'#FFF1E8'}]}>
                <Text>设置页面</Text>
            </View>
        )
    },
});
//实现个人中心页面
var ForTouchScene=React.createClass({
    render:function(){
        return(
        <View style={[styles.scene,{backgroundColor:'#ECF6E8'}]}>
            <Text>个人中心</Text>
        </View>
        )
    },
});

var styles = StyleSheet.create({
    container: {
        flex: 1,
    },
    scene: {
        padding: 10,
        paddingTop:74,
        flex: 1,
    },
});

AppRegistry.registerComponent('dazhongdemo', () => dazhongdemo);
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值