android head node logic changed

This commit is contained in:
王劲鹏 2020-01-09 15:55:39 +08:00 committed by osborn
parent 56852286e3
commit 9a77578b9b
2 changed files with 29 additions and 13 deletions

View File

@ -53,25 +53,40 @@ public class DoricContext {
private String extra;
private JSONObject initParams;
private IDoricDriver doricDriver;
private final Map<String, ViewNode> mHeadNodes = new HashMap<>();
private final Map<String, Map<String, ViewNode>> mHeadNodes = new HashMap<>();
public Collection<ViewNode> allHeadNodes() {
return mHeadNodes.values();
public Collection<ViewNode> 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<String, ViewNode> 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<String, ViewNode> 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<String, ViewNode> map : mHeadNodes.values()) {
if (map.containsKey(id)) {
return map.get(id);
}
}
return null;
}
protected DoricContext(Context context, String contextId, String source, String extra) {

View File

@ -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<Object>() {
@ -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);
}
}