From 96772078444ad465a864b63979b671ebbb7becac Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 24 Dec 2019 16:48:17 +0800 Subject: [PATCH] feat:In Android,after context finished,the popovered view must be removed --- .../src/main/java/pub/doric/DoricContext.java | 17 ++++++++++++++++- .../java/pub/doric/plugin/DoricJavaPlugin.java | 4 ++++ .../java/pub/doric/plugin/PopoverPlugin.java | 14 +++++++++----- doric-demo/src/NavigatorDemo.ts | 4 ++-- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/DoricContext.java b/doric-android/doric/src/main/java/pub/doric/DoricContext.java index 6f7f2800..47035492 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricContext.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricContext.java @@ -26,6 +26,7 @@ import org.json.JSONObject; import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.Callable; import pub.doric.async.AsyncResult; import pub.doric.navbar.IDoricNavBar; @@ -35,6 +36,7 @@ import pub.doric.shader.RootNode; import pub.doric.shader.ViewNode; import pub.doric.utils.DoricConstant; import pub.doric.utils.DoricMetaInfo; +import pub.doric.utils.ThreadMode; /** * @Description: Doric @@ -151,7 +153,16 @@ public class DoricContext { @Override public void onFinish() { - mPluginMap.clear(); + getDriver().asyncCall(new Callable() { + @Override + public Object call() { + for (DoricJavaPlugin javaPlugin : mPluginMap.values()) { + javaPlugin.onTearDown(); + } + mPluginMap.clear(); + return null; + } + }, ThreadMode.UI); } }); } @@ -166,6 +177,10 @@ public class DoricContext { } public void reload(String script) { + for (DoricJavaPlugin javaPlugin : mPluginMap.values()) { + javaPlugin.onTearDown(); + } + mPluginMap.clear(); this.script = script; this.mRootNode.setId(""); getDriver().createContext(mContextId, script, source); diff --git a/doric-android/doric/src/main/java/pub/doric/plugin/DoricJavaPlugin.java b/doric-android/doric/src/main/java/pub/doric/plugin/DoricJavaPlugin.java index 4dffe8c5..f991cdad 100644 --- a/doric-android/doric/src/main/java/pub/doric/plugin/DoricJavaPlugin.java +++ b/doric-android/doric/src/main/java/pub/doric/plugin/DoricJavaPlugin.java @@ -27,4 +27,8 @@ public abstract class DoricJavaPlugin extends DoricContextHolder { public DoricJavaPlugin(DoricContext doricContext) { super(doricContext); } + + public void onTearDown() { + + } } diff --git a/doric-android/doric/src/main/java/pub/doric/plugin/PopoverPlugin.java b/doric-android/doric/src/main/java/pub/doric/plugin/PopoverPlugin.java index 457b168b..da01f65a 100644 --- a/doric-android/doric/src/main/java/pub/doric/plugin/PopoverPlugin.java +++ b/doric-android/doric/src/main/java/pub/doric/plugin/PopoverPlugin.java @@ -1,7 +1,5 @@ package pub.doric.plugin; -import android.app.Activity; -import android.graphics.Color; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; @@ -14,7 +12,6 @@ import com.github.pengfeizhou.jscore.JavaValue; import java.util.concurrent.Callable; import pub.doric.DoricContext; -import pub.doric.async.AsyncCall; import pub.doric.async.AsyncResult; import pub.doric.extension.bridge.DoricMethod; 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, ViewGroup.LayoutParams.MATCH_PARENT)); } - mFullScreenView.setVisibility(View.VISIBLE); mFullScreenView.bringToFront(); String viewId = jsObject.getProperty("id").asString().value(); String type = jsObject.getProperty("type").asString().value(); @@ -127,7 +123,9 @@ public class PopoverPlugin extends DoricJavaPlugin { getDoricContext().removeHeadNode(node); mFullScreenView.removeView(node.getNodeView()); 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); } } + + @Override + public void onTearDown() { + super.onTearDown(); + this.dismissPopover(); + } } diff --git a/doric-demo/src/NavigatorDemo.ts b/doric-demo/src/NavigatorDemo.ts index 3190be23..3701594a 100644 --- a/doric-demo/src/NavigatorDemo.ts +++ b/doric-demo/src/NavigatorDemo.ts @@ -20,7 +20,7 @@ class NaivgatorDemo extends Panel { 'NavbarDemo', 'Counter', 'EffectsDemo', 'ImageDemo', 'LayoutDemo', 'ListDemo', 'ModalDemo', 'NavigatorDemo', - 'NetworkDemo', 'ScrollerDemo', 'SliderDemo', 'Snake', 'StorageDemo'].map(e => + 'NetworkDemo', 'ScrollerDemo', 'SliderDemo', 'Snake', 'StorageDemo', 'PopoverDemo'].map(e => label(e).apply({ height: 50, backgroundColor: colors[0], @@ -28,7 +28,7 @@ class NaivgatorDemo extends Panel { textColor: Color.WHITE, layoutConfig: layoutConfig().just().configWidth(LayoutSpec.MOST), onClick: () => { - navigator(context).push(`assets://demo/${e}.js`, { + navigator(context).push(`assets://src/${e}.js`, { alias: `${e}.js`, extra: { from: "navigatorDemo"