react-native navigator

react-native 的导航器是比较复杂的概念,这里记录一下

renderImages: function() {
    return (
        <NavigatorIOS style={styles.navigator}
        initialRoute={{
            component: MyView,
            title: 'My View Title',
            passProps: { myProp: 'foo' },
            backButtonTitle: 'Custom Back',
            rightButtonTitle: 'Cancel',
            leftButtonTitle: 'back',
        }}/>
    );
  },

上面这段代码,当renderImages方法被触发的时候,导航器就会加载MyView视图

下面是MyView的定义:

var MyView = React.createClass({
    render: function(){
        return (
            <ScrollView contentContainerStyle={[styles.contentContainer]}>
                <View style={styles.flexContainer}>
                    <TouchableHighlight onPress={this.bigImage} style={{flex:1,height:100}}>
                        <Image style={styles.logo} source={{uri: 'http://facebook.github.io/react/img/logo_og.png'}} />
                    </TouchableHighlight>     
                </View>
             </ScrollView>

        );
    }

});

这样一个的视图

根据这个,其实可以创造出更深一层
增加bigImage方法查看大图

bigImage : function(){
        this.props.navigator.push({
            title: 'title',
            component: NavigatorIOSExample,
            rightButtonTitle: 'test1',
            leftButtonTitle: 'back2',
            onLeftButtonPress:() => this.props.navigator.pop(),
            onRightButtonPress:()=> AlertIOS.alert(
                'Foo Title',
                this.props.myProp
            )
        });
    },

此外可以看出onLeftButtonPress方法的作用是返回上个视图,
另外,可以通过passProps属性来进行view之间的参数传递

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值