feat:In Android,after context finished,the popovered view must be removed

This commit is contained in:
pengfei.zhou 2019-12-24 16:48:17 +08:00 committed by osborn
parent 5a5e588876
commit 9677207844
4 changed files with 31 additions and 8 deletions

View File

@ -26,6 +26,7 @@ import org.json.JSONObject;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable;
import pub.doric.async.AsyncResult; import pub.doric.async.AsyncResult;
import pub.doric.navbar.IDoricNavBar; import pub.doric.navbar.IDoricNavBar;
@ -35,6 +36,7 @@ import pub.doric.shader.RootNode;
import pub.doric.shader.ViewNode; import pub.doric.shader.ViewNode;
import pub.doric.utils.DoricConstant; import pub.doric.utils.DoricConstant;
import pub.doric.utils.DoricMetaInfo; import pub.doric.utils.DoricMetaInfo;
import pub.doric.utils.ThreadMode;
/** /**
* @Description: Doric * @Description: Doric
@ -151,7 +153,16 @@ public class DoricContext {
@Override @Override
public void onFinish() { public void onFinish() {
getDriver().asyncCall(new Callable<Object>() {
@Override
public Object call() {
for (DoricJavaPlugin javaPlugin : mPluginMap.values()) {
javaPlugin.onTearDown();
}
mPluginMap.clear(); mPluginMap.clear();
return null;
}
}, ThreadMode.UI);
} }
}); });
} }
@ -166,6 +177,10 @@ public class DoricContext {
} }
public void reload(String script) { public void reload(String script) {
for (DoricJavaPlugin javaPlugin : mPluginMap.values()) {
javaPlugin.onTearDown();
}
mPluginMap.clear();
this.script = script; this.script = script;
this.mRootNode.setId(""); this.mRootNode.setId("");
getDriver().createContext(mContextId, script, source); getDriver().createContext(mContextId, script, source);

View File

@ -27,4 +27,8 @@ public abstract class DoricJavaPlugin extends DoricContextHolder {
public DoricJavaPlugin(DoricContext doricContext) { public DoricJavaPlugin(DoricContext doricContext) {
super(doricContext); super(doricContext);
} }
public void onTearDown() {
}
} }

View File

@ -1,7 +1,5 @@
package pub.doric.plugin; package pub.doric.plugin;
import android.app.Activity;
import android.graphics.Color;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
@ -14,7 +12,6 @@ import com.github.pengfeizhou.jscore.JavaValue;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import pub.doric.DoricContext; import pub.doric.DoricContext;
import pub.doric.async.AsyncCall;
import pub.doric.async.AsyncResult; import pub.doric.async.AsyncResult;
import pub.doric.extension.bridge.DoricMethod; import pub.doric.extension.bridge.DoricMethod;
import pub.doric.extension.bridge.DoricPlugin; import pub.doric.extension.bridge.DoricPlugin;
@ -48,7 +45,6 @@ public class PopoverPlugin extends DoricJavaPlugin {
decorView.addView(mFullScreenView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, decorView.addView(mFullScreenView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT)); ViewGroup.LayoutParams.MATCH_PARENT));
} }
mFullScreenView.setVisibility(View.VISIBLE);
mFullScreenView.bringToFront(); mFullScreenView.bringToFront();
String viewId = jsObject.getProperty("id").asString().value(); String viewId = jsObject.getProperty("id").asString().value();
String type = jsObject.getProperty("type").asString().value(); String type = jsObject.getProperty("type").asString().value();
@ -127,7 +123,9 @@ public class PopoverPlugin extends DoricJavaPlugin {
getDoricContext().removeHeadNode(node); getDoricContext().removeHeadNode(node);
mFullScreenView.removeView(node.getNodeView()); mFullScreenView.removeView(node.getNodeView());
if (getDoricContext().allHeadNodes().isEmpty()) { if (getDoricContext().allHeadNodes().isEmpty()) {
mFullScreenView.setVisibility(View.GONE); ViewGroup decorView = (ViewGroup) getDoricContext().getRootNode().getNodeView().getRootView();
decorView.removeView(mFullScreenView);
mFullScreenView = null;
} }
} }
@ -136,4 +134,10 @@ public class PopoverPlugin extends DoricJavaPlugin {
dismissViewNode(node); dismissViewNode(node);
} }
} }
@Override
public void onTearDown() {
super.onTearDown();
this.dismissPopover();
}
} }

View File

@ -20,7 +20,7 @@ class NaivgatorDemo extends Panel {
'NavbarDemo', 'NavbarDemo',
'Counter', 'EffectsDemo', 'ImageDemo', 'LayoutDemo', 'Counter', 'EffectsDemo', 'ImageDemo', 'LayoutDemo',
'ListDemo', 'ModalDemo', 'NavigatorDemo', 'ListDemo', 'ModalDemo', 'NavigatorDemo',
'NetworkDemo', 'ScrollerDemo', 'SliderDemo', 'Snake', 'StorageDemo'].map(e => 'NetworkDemo', 'ScrollerDemo', 'SliderDemo', 'Snake', 'StorageDemo', 'PopoverDemo'].map(e =>
label(e).apply({ label(e).apply({
height: 50, height: 50,
backgroundColor: colors[0], backgroundColor: colors[0],
@ -28,7 +28,7 @@ class NaivgatorDemo extends Panel {
textColor: Color.WHITE, textColor: Color.WHITE,
layoutConfig: layoutConfig().just().configWidth(LayoutSpec.MOST), layoutConfig: layoutConfig().just().configWidth(LayoutSpec.MOST),
onClick: () => { onClick: () => {
navigator(context).push(`assets://demo/${e}.js`, { navigator(context).push(`assets://src/${e}.js`, {
alias: `${e}.js`, alias: `${e}.js`,
extra: { extra: {
from: "navigatorDemo" from: "navigatorDemo"