Weex Android 返回键 页面传值 生命周期

问题

  1. 安卓返回键
  2. 页面之间传参数
  3. Vue页面生命周期

vue.js实现

<template>
//页面根节点
    <div @onAndroidBack="onAndroidBack" @ready="ready" @actived="actived" @deactived="deactived" class="container">
        
    </div>

</template>
<script>
methods: {
            //页面ready 页面传参
            ready(param){
                let p = JSON.stringify(e.param)
                console.log('pageA页面传参数=' + p);
            },
            //页面激活 param 页面传参
            actived(param){
                
            },
            //页面失活
            deactived(){
               
            },
            //
            onAndroidBack(){
                uNavigator.pop();
            },
            onClick(){
                uNavigator.popTo({index:-1,tagCode:"pageb",param:{test:'testB'}},() => {} );
            }
        },
        </script>

Android实现:

public void onBackPressed() {
        WXComponent comp = mInstance.getRootComponent();
        if (comp != null) {
            WXEvent events = comp.getDomObject().getEvents();
            boolean hasBack = events.contains(UConstants.Event.ONANDROIDBACK);
            if (hasBack) {
                WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.ONANDROIDBACK, null, null);
                return;
            }else {
                super.onBackPressed();
            }
        }
        super.onBackPressed();
    }
    
 @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        if (intent == null) {
            return;
        }
        if (intent.getStringExtra("params") != null) {
            String params = intent.getStringExtra("params");
            String backTag = intent.getStringExtra("backTag");
            if (!TextUtils.isEmpty(params)) {
                WXComponent comp = mInstance.getRootComponent();
                if (comp != null) {
                    WXEvent events = comp.getDomObject().getEvents();
                    boolean hasActive = events.contains(UConstants.Event.ACTIVED);
                    if (hasActive) {
                            Map<String, Object> data = new HashMap<>();
                            data.put("param",params);
                            data.put("tagCode", backTag);
                            WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.ACTIVED, data, null);
//                        }
                    }
                }
            }
        }
    }
@Override
    public void onViewCreated(WXSDKInstance wxsdkInstance, View view) {
        super.onViewCreated(wxsdkInstance, view);
        WXComponent comp = mInstance.getRootComponent();
        if (comp != null) {
            WXEvent events = comp.getDomObject().getEvents();
            boolean hasReady = events.contains(UConstants.Event.READY);
            if (hasReady) {
                Map<String, Object> data = new HashMap<>();
                data.put("param", wxInfo.getParam());
                WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.READY, data, null);
            }
        }
        if (!isHasNavBar) {
            setTranslateAnimation(getContainer());
        }
    }
 @Override
    public void onPause() {
        super.onPause();
        WXComponent comp = mInstance.getRootComponent();
        if (comp != null) {
            WXEvent events = comp.getDomObject().getEvents();
            boolean hasDeactived = events.contains(UConstants.Event.DEACTIVED);
            if (hasDeactived) {
                WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.DEACTIVED, null, null);
            }
        }
        if (mIsShakeDetectorStarted && mShakeDetector != null) {
            mShakeDetector.stop();
            mIsShakeDetectorStarted = false;
        }
    }
    @Override
    public void onResume() {
        super.onResume();
        if (!mIsShakeDetectorStarted && mShakeDetector != null) {
            mShakeDetector.start((SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE));
            mIsShakeDetectorStarted = true;
        }
    }

开源:
https://github.com/weexext/we...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值