From 9a77578b9bb443ecbea8f7f23c95498355adc93a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Thu, 9 Jan 2020 15:55:39 +0800 Subject: [PATCH] android head node logic changed --- .../src/main/java/pub/doric/DoricContext.java | 31 ++++++++++++++----- .../java/pub/doric/plugin/PopoverPlugin.java | 11 ++++--- 2 files changed, 29 insertions(+), 13 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 47035492..c11216c6 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricContext.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricContext.java @@ -53,25 +53,40 @@ public class DoricContext { private String extra; private JSONObject initParams; private IDoricDriver doricDriver; - private final Map mHeadNodes = new HashMap<>(); + private final Map> mHeadNodes = new HashMap<>(); - public Collection allHeadNodes() { - return mHeadNodes.values(); + public Collection allHeadNodes(String type) { + return mHeadNodes.get(type).values(); } - public void addHeadNode(ViewNode viewNode) { - mHeadNodes.put(viewNode.getId(), viewNode); + public void addHeadNode(String type, ViewNode viewNode) { + Map map = mHeadNodes.get(type); + if (map != null) { + map.put(viewNode.getId(), viewNode); + } else { + map = new HashMap<>(); + map.put(viewNode.getId(), viewNode); + mHeadNodes.put(type, map); + } } - public void removeHeadNode(ViewNode viewNode) { - mHeadNodes.remove(viewNode.getId()); + public void removeHeadNode(String type, ViewNode viewNode) { + Map map = mHeadNodes.get(type); + if (map != null) { + map.remove(viewNode.getId()); + } } public ViewNode targetViewNode(String id) { if (id.equals(mRootNode.getId())) { return mRootNode; } - return mHeadNodes.get(id); + for (Map map : mHeadNodes.values()) { + if (map.containsKey(id)) { + return map.get(id); + } + } + return null; } protected DoricContext(Context context, String contextId, String source, String extra) { 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 da01f65a..4f347bd7 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,6 +1,5 @@ package pub.doric.plugin; -import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; @@ -26,6 +25,8 @@ import pub.doric.utils.ThreadMode; */ @DoricPlugin(name = "popover") public class PopoverPlugin extends DoricJavaPlugin { + private static final String TYPE = "popover"; + private FrameLayout mFullScreenView; public PopoverPlugin(DoricContext doricContext) { @@ -53,7 +54,7 @@ public class PopoverPlugin extends DoricJavaPlugin { node.init(new FrameLayout.LayoutParams(0, 0)); node.blend(jsObject.getProperty("props").asObject()); mFullScreenView.addView(node.getNodeView()); - getDoricContext().addHeadNode(node); + getDoricContext().addHeadNode(TYPE, node); return null; } }, ThreadMode.UI).setCallback(new AsyncResult.Callback() { @@ -120,9 +121,9 @@ public class PopoverPlugin extends DoricJavaPlugin { } private void dismissViewNode(ViewNode node) { - getDoricContext().removeHeadNode(node); + getDoricContext().removeHeadNode(TYPE, node); mFullScreenView.removeView(node.getNodeView()); - if (getDoricContext().allHeadNodes().isEmpty()) { + if (getDoricContext().allHeadNodes(TYPE).isEmpty()) { ViewGroup decorView = (ViewGroup) getDoricContext().getRootNode().getNodeView().getRootView(); decorView.removeView(mFullScreenView); mFullScreenView = null; @@ -130,7 +131,7 @@ public class PopoverPlugin extends DoricJavaPlugin { } private void dismissPopover() { - for (ViewNode node : getDoricContext().allHeadNodes()) { + for (ViewNode node : getDoricContext().allHeadNodes(TYPE)) { dismissViewNode(node); } }