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

问题

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

vue.js实现


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 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 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...

你可能感兴趣的:(weex,android,io,vue.js)