Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[WEEX][Android] Support Downgrade To Full Page Root Instance (#1952)
Browse files Browse the repository at this point in the history
  • Loading branch information
gubaojian authored and YorkShen committed Jan 8, 2019
1 parent 21e9e81 commit 8b9ce52
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
13 changes: 13 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ public class WXSDKInstance implements IWXActivityStateListener,View.OnLayoutChan

private List<String> mLayerOverFlowListeners;

private WXSDKInstance mParentInstance;

public List<String> getLayerOverFlowListeners() {
return mLayerOverFlowListeners;
}
Expand Down Expand Up @@ -1499,6 +1501,14 @@ public void run() {
mWXPerformance.screenRenderTime = System.currentTimeMillis() - mRenderStartTime;
}

public WXSDKInstance getParentInstance() {
return mParentInstance;
}

public void setParentInstance(WXSDKInstance mParentInstance) {
this.mParentInstance = mParentInstance;
}

private void destroyView(View rootView) {
try {
if (rootView instanceof ViewGroup) {
Expand All @@ -1522,6 +1532,9 @@ private void destroyView(View rootView) {

public synchronized void destroy() {
if(!isDestroy()) {
if(mParentInstance != null){
mParentInstance = null;
}
mApmForInstance.onEnd();
if(mRendered) {
WXSDKManager.getInstance().destroyInstance(mInstanceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.taobao.weex.common;

import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.annotation.JSMethod;

/**
Expand All @@ -28,7 +29,13 @@ public class WXInstanceWrap extends WXModule {
@JSMethod
public void error(String type, String code, String info) {
if (mWXSDKInstance != null) {
mWXSDKInstance.onRenderError(type + "|" + code, info);
WXSDKInstance root = mWXSDKInstance;
if(info != null && info.contains("downgrade_to_root")){
while (root.getParentInstance() != null){
root = root.getParentInstance();
}
}
root.onRenderError(type + "|" + code, info);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private static final int getLevel(WXEmbed embed){

private WXSDKInstance createInstance() {
WXSDKInstance sdkInstance = getInstance().createNestedInstance(this);

sdkInstance.setParentInstance(getInstance());
boolean needsAdd = !getAttrs().containsKey("disableInstanceVisibleListener");
if(needsAdd){ //prevent switch off fire viewappear event twice
getInstance().addOnInstanceVisibleListener(this);
Expand Down

0 comments on commit 8b9ce52

Please sign in to comment.