From 33336b0873aca11cb01bccf186efa7b306315467 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Fri, 29 Nov 2019 10:00:29 +0800 Subject: [PATCH] feat:add Popover for Android step1 --- .../src/main/java/pub/doric/DoricContext.java | 19 +++++++++++ .../bridge/DoricBridgeExtension.java | 4 +++ .../java/pub/doric/plugin/ModalPlugin.java | 12 +++---- .../java/pub/doric/plugin/NetworkPlugin.java | 3 +- .../java/pub/doric/plugin/PopoverPlugin.java | 32 +++++++++++++++++++ .../java/pub/doric/plugin/StoragePlugin.java | 12 +++---- js-framework/src/ui/panel.ts | 3 ++ 7 files changed, 67 insertions(+), 18 deletions(-) create mode 100644 Android/doric/src/main/java/pub/doric/plugin/PopoverPlugin.java diff --git a/Android/doric/src/main/java/pub/doric/DoricContext.java b/Android/doric/src/main/java/pub/doric/DoricContext.java index fd1971e0..6fa6b06b 100644 --- a/Android/doric/src/main/java/pub/doric/DoricContext.java +++ b/Android/doric/src/main/java/pub/doric/DoricContext.java @@ -22,6 +22,7 @@ import com.github.pengfeizhou.jscore.JSONBuilder; import org.json.JSONObject; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -30,6 +31,7 @@ import pub.doric.navbar.IDoricNavBar; import pub.doric.navigator.IDoricNavigator; import pub.doric.plugin.DoricJavaPlugin; import pub.doric.shader.RootNode; +import pub.doric.shader.ViewNode; import pub.doric.utils.DoricConstant; import pub.doric.utils.DoricMetaInfo; @@ -47,6 +49,23 @@ public class DoricContext { private String script; private JSONObject initParams; private IDoricDriver doricDriver; + private final Map mHeadNodes = new HashMap<>(); + + public Collection allHeadNodes() { + return mHeadNodes.values(); + } + + public void addHeadNode(ViewNode viewNode) { + mHeadNodes.put(viewNode.getId(), viewNode); + } + + public void removeHeadNode(ViewNode viewNode) { + mHeadNodes.remove(viewNode.getId()); + } + + public ViewNode targetViewNode(String id) { + return mHeadNodes.get(id); + } protected DoricContext(Context context, String contextId, String source) { this.mContext = context; diff --git a/Android/doric/src/main/java/pub/doric/extension/bridge/DoricBridgeExtension.java b/Android/doric/src/main/java/pub/doric/extension/bridge/DoricBridgeExtension.java index 49464ca8..e968a96d 100644 --- a/Android/doric/src/main/java/pub/doric/extension/bridge/DoricBridgeExtension.java +++ b/Android/doric/src/main/java/pub/doric/extension/bridge/DoricBridgeExtension.java @@ -58,6 +58,10 @@ public class DoricBridgeExtension { return new JavaValue(false); } DoricMethod doricMethod = method.getAnnotation(DoricMethod.class); + if (doricMethod == null) { + DoricLog.e("Cannot find DoricMethod annotation in class:%s,method:%s", module, methodName); + return new JavaValue(false); + } Callable callable = new Callable() { @Override public JavaValue call() throws Exception { diff --git a/Android/doric/src/main/java/pub/doric/plugin/ModalPlugin.java b/Android/doric/src/main/java/pub/doric/plugin/ModalPlugin.java index 18dcd2f9..845a387f 100644 --- a/Android/doric/src/main/java/pub/doric/plugin/ModalPlugin.java +++ b/Android/doric/src/main/java/pub/doric/plugin/ModalPlugin.java @@ -50,9 +50,8 @@ public class ModalPlugin extends DoricJavaPlugin { } @DoricMethod(thread = ThreadMode.UI) - public void toast(JSDecoder decoder) { + public void toast(JSObject jsObject) { try { - JSObject jsObject = decoder.decode().asObject(); String msg = jsObject.getProperty("msg").asString().value(); JSValue gravityVal = jsObject.getProperty("gravity"); int gravity = Gravity.BOTTOM; @@ -77,9 +76,8 @@ public class ModalPlugin extends DoricJavaPlugin { } @DoricMethod(thread = ThreadMode.UI) - public void alert(JSDecoder decoder, final DoricPromise promise) { + public void alert(JSObject jsObject, final DoricPromise promise) { try { - JSObject jsObject = decoder.decode().asObject(); JSValue titleVal = jsObject.getProperty("title"); JSValue msgVal = jsObject.getProperty("msg"); JSValue okBtn = jsObject.getProperty("okLabel"); @@ -109,9 +107,8 @@ public class ModalPlugin extends DoricJavaPlugin { @DoricMethod(thread = ThreadMode.UI) - public void confirm(JSDecoder decoder, final DoricPromise promise) { + public void confirm(JSObject jsObject, final DoricPromise promise) { try { - JSObject jsObject = decoder.decode().asObject(); JSValue titleVal = jsObject.getProperty("title"); JSValue msgVal = jsObject.getProperty("msg"); JSValue okBtn = jsObject.getProperty("okLabel"); @@ -152,9 +149,8 @@ public class ModalPlugin extends DoricJavaPlugin { @DoricMethod(thread = ThreadMode.UI) - public void prompt(JSDecoder decoder, final DoricPromise promise) { + public void prompt(JSObject jsObject, final DoricPromise promise) { try { - JSObject jsObject = decoder.decode().asObject(); JSValue titleVal = jsObject.getProperty("title"); JSValue msgVal = jsObject.getProperty("msg"); JSValue okBtn = jsObject.getProperty("okLabel"); diff --git a/Android/doric/src/main/java/pub/doric/plugin/NetworkPlugin.java b/Android/doric/src/main/java/pub/doric/plugin/NetworkPlugin.java index 45fdc272..ec36fb34 100644 --- a/Android/doric/src/main/java/pub/doric/plugin/NetworkPlugin.java +++ b/Android/doric/src/main/java/pub/doric/plugin/NetworkPlugin.java @@ -58,9 +58,8 @@ public class NetworkPlugin extends DoricJavaPlugin { } @DoricMethod - public void request(JSDecoder decoder, final DoricPromise promise) { + public void request(JSObject requestVal, final DoricPromise promise) { try { - JSObject requestVal = decoder.decode().asObject(); String url = requestVal.getProperty("url").asString().value(); String method = requestVal.getProperty("method").asString().value(); JSValue headerVal = requestVal.getProperty("headers"); diff --git a/Android/doric/src/main/java/pub/doric/plugin/PopoverPlugin.java b/Android/doric/src/main/java/pub/doric/plugin/PopoverPlugin.java new file mode 100644 index 00000000..fbcfdfaf --- /dev/null +++ b/Android/doric/src/main/java/pub/doric/plugin/PopoverPlugin.java @@ -0,0 +1,32 @@ +package pub.doric.plugin; + +import com.github.pengfeizhou.jscore.JSDecoder; +import com.github.pengfeizhou.jscore.JSObject; +import com.github.pengfeizhou.jscore.JavaValue; + +import pub.doric.DoricContext; +import pub.doric.extension.bridge.DoricMethod; +import pub.doric.extension.bridge.DoricPlugin; +import pub.doric.extension.bridge.DoricPromise; + +/** + * @Description: pub.doric.plugin + * @Author: pengfei.zhou + * @CreateDate: 2019-11-29 + */ +@DoricPlugin(name = "popover") +public class PopoverPlugin extends DoricJavaPlugin { + + public PopoverPlugin(DoricContext doricContext) { + super(doricContext); + } + + @DoricMethod + public void show(JSObject jsObject, DoricPromise promise) { + + } + + @DoricMethod + public void dismiss(JSObject jsObject, DoricPromise promise) { + } +} diff --git a/Android/doric/src/main/java/pub/doric/plugin/StoragePlugin.java b/Android/doric/src/main/java/pub/doric/plugin/StoragePlugin.java index f5293235..746ffd29 100644 --- a/Android/doric/src/main/java/pub/doric/plugin/StoragePlugin.java +++ b/Android/doric/src/main/java/pub/doric/plugin/StoragePlugin.java @@ -41,9 +41,8 @@ public class StoragePlugin extends DoricJavaPlugin { } @DoricMethod - public void setItem(JSDecoder decoder, final DoricPromise promise) { + public void setItem(JSObject jsObject, final DoricPromise promise) { try { - JSObject jsObject = decoder.decode().asObject(); JSValue zone = jsObject.getProperty("zone"); String key = jsObject.getProperty("key").asString().value(); String value = jsObject.getProperty("value").asString().value(); @@ -59,9 +58,8 @@ public class StoragePlugin extends DoricJavaPlugin { } @DoricMethod - public void getItem(JSDecoder decoder, final DoricPromise promise) { + public void getItem(JSObject jsObject, final DoricPromise promise) { try { - JSObject jsObject = decoder.decode().asObject(); JSValue zone = jsObject.getProperty("zone"); String key = jsObject.getProperty("key").asString().value(); String prefName = zone.isString() ? PREF_NAME + "_" + zone.asString() : PREF_NAME; @@ -76,9 +74,8 @@ public class StoragePlugin extends DoricJavaPlugin { } @DoricMethod - public void remove(JSDecoder decoder, final DoricPromise promise) { + public void remove(JSObject jsObject, final DoricPromise promise) { try { - JSObject jsObject = decoder.decode().asObject(); JSValue zone = jsObject.getProperty("zone"); String key = jsObject.getProperty("key").asString().value(); String prefName = zone.isString() ? PREF_NAME + "_" + zone.asString() : PREF_NAME; @@ -93,9 +90,8 @@ public class StoragePlugin extends DoricJavaPlugin { } @DoricMethod - public void clear(JSDecoder decoder, final DoricPromise promise) { + public void clear(JSObject jsObject, final DoricPromise promise) { try { - JSObject jsObject = decoder.decode().asObject(); JSValue zone = jsObject.getProperty("zone"); if (zone.isString()) { String prefName = PREF_NAME + "_" + zone.asString(); diff --git a/js-framework/src/ui/panel.ts b/js-framework/src/ui/panel.ts index e6ff2083..7c488b1b 100644 --- a/js-framework/src/ui/panel.ts +++ b/js-framework/src/ui/panel.ts @@ -121,6 +121,9 @@ export abstract class Panel { private retrospectView(ids: string[]): View | undefined { return ids.reduce((acc: View | undefined, cur) => { if (acc === undefined) { + if (cur === this.__root__.viewId) { + return this.__root__ + } return this.headviews.get(cur) } else { if (Reflect.has(acc, "subviewById")) {