加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native navigator

发布时间:2020-12-15 05:21:07 所属栏目:百科 来源:网络整理
导读:react-native 的导航器是比较复杂的概念,这里记录一下 renderImages: function() { return ( NavigatorIOS style = {styles.navigator} initialRoute = {{ component : MyView , title : ' My View Title ', passProps : { myProp : ' foo ' }, backButtonT

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之间的参数传递

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读