feat:add Popover for Android step1

This commit is contained in:
pengfei.zhou 2019-11-29 10:00:29 +08:00
parent c0eae0f8a2
commit 33336b0873
7 changed files with 67 additions and 18 deletions

View File

@ -22,6 +22,7 @@ import com.github.pengfeizhou.jscore.JSONBuilder;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -30,6 +31,7 @@ import pub.doric.navbar.IDoricNavBar;
import pub.doric.navigator.IDoricNavigator; import pub.doric.navigator.IDoricNavigator;
import pub.doric.plugin.DoricJavaPlugin; import pub.doric.plugin.DoricJavaPlugin;
import pub.doric.shader.RootNode; import pub.doric.shader.RootNode;
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;
@ -47,6 +49,23 @@ public class DoricContext {
private String script; private String script;
private JSONObject initParams; private JSONObject initParams;
private IDoricDriver doricDriver; private IDoricDriver doricDriver;
private final Map<String, ViewNode> mHeadNodes = new HashMap<>();
public Collection<ViewNode> 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) { protected DoricContext(Context context, String contextId, String source) {
this.mContext = context; this.mContext = context;

View File

@ -58,6 +58,10 @@ public class DoricBridgeExtension {
return new JavaValue(false); return new JavaValue(false);
} }
DoricMethod doricMethod = method.getAnnotation(DoricMethod.class); 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<JavaValue> callable = new Callable<JavaValue>() { Callable<JavaValue> callable = new Callable<JavaValue>() {
@Override @Override
public JavaValue call() throws Exception { public JavaValue call() throws Exception {

View File

@ -50,9 +50,8 @@ public class ModalPlugin extends DoricJavaPlugin {
} }
@DoricMethod(thread = ThreadMode.UI) @DoricMethod(thread = ThreadMode.UI)
public void toast(JSDecoder decoder) { public void toast(JSObject jsObject) {
try { try {
JSObject jsObject = decoder.decode().asObject();
String msg = jsObject.getProperty("msg").asString().value(); String msg = jsObject.getProperty("msg").asString().value();
JSValue gravityVal = jsObject.getProperty("gravity"); JSValue gravityVal = jsObject.getProperty("gravity");
int gravity = Gravity.BOTTOM; int gravity = Gravity.BOTTOM;
@ -77,9 +76,8 @@ public class ModalPlugin extends DoricJavaPlugin {
} }
@DoricMethod(thread = ThreadMode.UI) @DoricMethod(thread = ThreadMode.UI)
public void alert(JSDecoder decoder, final DoricPromise promise) { public void alert(JSObject jsObject, final DoricPromise promise) {
try { try {
JSObject jsObject = decoder.decode().asObject();
JSValue titleVal = jsObject.getProperty("title"); JSValue titleVal = jsObject.getProperty("title");
JSValue msgVal = jsObject.getProperty("msg"); JSValue msgVal = jsObject.getProperty("msg");
JSValue okBtn = jsObject.getProperty("okLabel"); JSValue okBtn = jsObject.getProperty("okLabel");
@ -109,9 +107,8 @@ public class ModalPlugin extends DoricJavaPlugin {
@DoricMethod(thread = ThreadMode.UI) @DoricMethod(thread = ThreadMode.UI)
public void confirm(JSDecoder decoder, final DoricPromise promise) { public void confirm(JSObject jsObject, final DoricPromise promise) {
try { try {
JSObject jsObject = decoder.decode().asObject();
JSValue titleVal = jsObject.getProperty("title"); JSValue titleVal = jsObject.getProperty("title");
JSValue msgVal = jsObject.getProperty("msg"); JSValue msgVal = jsObject.getProperty("msg");
JSValue okBtn = jsObject.getProperty("okLabel"); JSValue okBtn = jsObject.getProperty("okLabel");
@ -152,9 +149,8 @@ public class ModalPlugin extends DoricJavaPlugin {
@DoricMethod(thread = ThreadMode.UI) @DoricMethod(thread = ThreadMode.UI)
public void prompt(JSDecoder decoder, final DoricPromise promise) { public void prompt(JSObject jsObject, final DoricPromise promise) {
try { try {
JSObject jsObject = decoder.decode().asObject();
JSValue titleVal = jsObject.getProperty("title"); JSValue titleVal = jsObject.getProperty("title");
JSValue msgVal = jsObject.getProperty("msg"); JSValue msgVal = jsObject.getProperty("msg");
JSValue okBtn = jsObject.getProperty("okLabel"); JSValue okBtn = jsObject.getProperty("okLabel");

View File

@ -58,9 +58,8 @@ public class NetworkPlugin extends DoricJavaPlugin {
} }
@DoricMethod @DoricMethod
public void request(JSDecoder decoder, final DoricPromise promise) { public void request(JSObject requestVal, final DoricPromise promise) {
try { try {
JSObject requestVal = decoder.decode().asObject();
String url = requestVal.getProperty("url").asString().value(); String url = requestVal.getProperty("url").asString().value();
String method = requestVal.getProperty("method").asString().value(); String method = requestVal.getProperty("method").asString().value();
JSValue headerVal = requestVal.getProperty("headers"); JSValue headerVal = requestVal.getProperty("headers");

View File

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

View File

@ -41,9 +41,8 @@ public class StoragePlugin extends DoricJavaPlugin {
} }
@DoricMethod @DoricMethod
public void setItem(JSDecoder decoder, final DoricPromise promise) { public void setItem(JSObject jsObject, final DoricPromise promise) {
try { try {
JSObject jsObject = decoder.decode().asObject();
JSValue zone = jsObject.getProperty("zone"); JSValue zone = jsObject.getProperty("zone");
String key = jsObject.getProperty("key").asString().value(); String key = jsObject.getProperty("key").asString().value();
String value = jsObject.getProperty("value").asString().value(); String value = jsObject.getProperty("value").asString().value();
@ -59,9 +58,8 @@ public class StoragePlugin extends DoricJavaPlugin {
} }
@DoricMethod @DoricMethod
public void getItem(JSDecoder decoder, final DoricPromise promise) { public void getItem(JSObject jsObject, final DoricPromise promise) {
try { try {
JSObject jsObject = decoder.decode().asObject();
JSValue zone = jsObject.getProperty("zone"); JSValue zone = jsObject.getProperty("zone");
String key = jsObject.getProperty("key").asString().value(); String key = jsObject.getProperty("key").asString().value();
String prefName = zone.isString() ? PREF_NAME + "_" + zone.asString() : PREF_NAME; String prefName = zone.isString() ? PREF_NAME + "_" + zone.asString() : PREF_NAME;
@ -76,9 +74,8 @@ public class StoragePlugin extends DoricJavaPlugin {
} }
@DoricMethod @DoricMethod
public void remove(JSDecoder decoder, final DoricPromise promise) { public void remove(JSObject jsObject, final DoricPromise promise) {
try { try {
JSObject jsObject = decoder.decode().asObject();
JSValue zone = jsObject.getProperty("zone"); JSValue zone = jsObject.getProperty("zone");
String key = jsObject.getProperty("key").asString().value(); String key = jsObject.getProperty("key").asString().value();
String prefName = zone.isString() ? PREF_NAME + "_" + zone.asString() : PREF_NAME; String prefName = zone.isString() ? PREF_NAME + "_" + zone.asString() : PREF_NAME;
@ -93,9 +90,8 @@ public class StoragePlugin extends DoricJavaPlugin {
} }
@DoricMethod @DoricMethod
public void clear(JSDecoder decoder, final DoricPromise promise) { public void clear(JSObject jsObject, final DoricPromise promise) {
try { try {
JSObject jsObject = decoder.decode().asObject();
JSValue zone = jsObject.getProperty("zone"); JSValue zone = jsObject.getProperty("zone");
if (zone.isString()) { if (zone.isString()) {
String prefName = PREF_NAME + "_" + zone.asString(); String prefName = PREF_NAME + "_" + zone.asString();

View File

@ -121,6 +121,9 @@ export abstract class Panel {
private retrospectView(ids: string[]): View | undefined { private retrospectView(ids: string[]): View | undefined {
return ids.reduce((acc: View | undefined, cur) => { return ids.reduce((acc: View | undefined, cur) => {
if (acc === undefined) { if (acc === undefined) {
if (cur === this.__root__.viewId) {
return this.__root__
}
return this.headviews.get(cur) return this.headviews.get(cur)
} else { } else {
if (Reflect.has(acc, "subviewById")) { if (Reflect.has(acc, "subviewById")) {