RN开发-Navigator

  1、在入口组件render方法中返回<Navigator>
            let defaultName = 'Welcome';
            let defaultCompenent = Welcome;            
            <Navigator
                initialRoute={{name:defaultName,component:defaultCompenent}}
                /*configureScene={
                    (route) => {
                        //页面转跳动画 node_modules/react-native/Libraries/CustomComponent/navigate/
                        return Navigator.SceneConfig.VerticalDownSwipeJump;
                    }
                }*/
                renderScene={
                    (route,navigator)=>{
                        let Component = route.component;
                        return <Component {...route.params} navigator={navigator}></Component>;
                    }
                }
            />
        2、在Welcom组件的点击事件中修改转跳页面信息并添加参数
            pressButton(){
                const {navigator} = this.props;                
                const self = this;
                /* 上文中,<Component {...route.params} navigator={navigator} 中传递了navigator作为props */
                if(navigator){
                    navigator.push({
                        name: 'Detail',
                        component: Detail,                
                        params:{
                            author:this.state.author,
                            user:this.props.user,
                            getResult: function(res){
                                self.setState({
                                    result:res
                                })
                            }
                        }
                    })
                }
            }
        3、在Detail组件中携带参数返回
            (1)、接收参数
                //生命周期方法
                componentDidMount(){
                    this.setState({
                        author:this.props.author,
                        user:this.props.user
                    });
                }
            (2)、携带参数返回
                backButton(){
                    const {navigator} = this.props;
                    
                    if(this.props.getResult){
                        let result = USER_MODELS[1];
                        this.props.getResult(result);
                    }
                    
                    if(navigator){
                        // 入栈出栈,把当前页面pop掉
                        navigator.pop();
                    }
                }
       

转载于:https://www.cnblogs.com/farmerkids/p/5972212.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值