From eb1c076dfb9e1fffa8369e81550cc137e7163539 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Sun, 21 Jul 2019 06:54:24 +0800 Subject: [PATCH] android callJSRespone --- .../penfeizhou/doric/utils/DoricConstant.java | 3 ++ .../penfeizhou/doric/widget/GroupNode.java | 11 +++++-- .../penfeizhou/doric/widget/ViewNode.java | 29 +++++++++++++++---- js-framework/src/ui/panel.ts | 2 +- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/utils/DoricConstant.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/utils/DoricConstant.java index 1fe52a47..ccf85fa4 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/utils/DoricConstant.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/utils/DoricConstant.java @@ -43,4 +43,7 @@ public class DoricConstant { public static final String DORIC_TIMER_CALLBACK = "jsCallbackTimer"; public static final String DORIC_BRIDGE_RESOLVE = "jsCallResolve"; public static final String DORIC_BRIDGE_REJECT = "jsCallReject"; + + + public static final String DORIC_ENTITY_RESPONSE = "__response__"; } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/GroupNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/GroupNode.java index 3abb40fc..83c66a26 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/GroupNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/GroupNode.java @@ -39,11 +39,15 @@ public abstract class GroupNode extends ViewNode { String id = childObj.getProperty("id").asString().value(); ViewNode child = mChildrenNode.get(id); if (child == null) { - child = ViewNode.create(getDoricContext(), id, type); + child = ViewNode.create(getDoricContext(), type); child.index = i; + child.ids.addAll(this.ids); + child.ids.add(id); mChildrenNode.put(id, child); mView.addView(child.mView, i); } else if (i != child.index) { + mIndexInfo.remove(child.index); + child.index = i; mView.removeView(child.mView); mView.addView(child.mView, i); } @@ -52,7 +56,10 @@ public abstract class GroupNode extends ViewNode { } while (i < mView.getChildCount()) { mView.removeViewAt(mView.getChildCount() - 1); - mChildrenNode.remove(mIndexInfo.get(i).id); + if (mIndexInfo.get(i) != null) { + mChildrenNode.remove(mIndexInfo.get(i).getId()); + mIndexInfo.remove(i); + } } } } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/ViewNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/ViewNode.java index 21cd7362..677474c6 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/ViewNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/widget/ViewNode.java @@ -7,10 +7,15 @@ import android.view.ViewGroup; import com.github.penfeizhou.doric.DoricContext; import com.github.penfeizhou.doric.DoricRegistry; import com.github.penfeizhou.doric.utils.DoricComponent; +import com.github.penfeizhou.doric.utils.DoricConstant; import com.github.penfeizhou.doric.utils.DoricMetaInfo; import com.github.penfeizhou.doric.utils.DoricUtils; import com.github.pengfeizhou.jscore.JSObject; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + /** * @Description: Render * @Author: pengfei.zhou @@ -18,10 +23,10 @@ import com.github.pengfeizhou.jscore.JSObject; */ public abstract class ViewNode extends DoricComponent { protected T mView; - String id; - int index; + ArrayList ids = new ArrayList<>(); + public ViewNode(DoricContext doricContext) { super(doricContext); } @@ -43,6 +48,10 @@ public abstract class ViewNode extends DoricComponent { setFrame(mView.getLayoutParams(), jsObject); } + public String getId() { + return ids.get(ids.size() - 1); + } + public void setFrame(ViewGroup.LayoutParams layoutParams, JSObject jsObject) { float width = jsObject.getProperty("width").asNumber().toFloat(); float height = jsObject.getProperty("height").asNumber().toFloat(); @@ -56,11 +65,19 @@ public abstract class ViewNode extends DoricComponent { } } - public static ViewNode create(DoricContext doricContext, String id, String type) { + public void callJSRespone(String funcId, Object... args) { + final Object[] nArgs = new Object[args.length + 2]; + nArgs[0] = ids.toArray(new String[0]); + nArgs[1] = funcId; + if (args.length > 0) { + System.arraycopy(args, 0, nArgs, 2, args.length); + } + getDoricContext().callEntity(DoricConstant.DORIC_ENTITY_RESPONSE, nArgs); + } + + public static ViewNode create(DoricContext doricContext, String type) { DoricRegistry registry = doricContext.getDriver().getRegistry(); DoricMetaInfo clz = registry.acquireViewNodeInfo(type); - ViewNode node = clz.createInstance(doricContext); - node.id = id; - return node; + return clz.createInstance(doricContext); } } diff --git a/js-framework/src/ui/panel.ts b/js-framework/src/ui/panel.ts index ce6de51e..3bb279ed 100644 --- a/js-framework/src/ui/panel.ts +++ b/js-framework/src/ui/panel.ts @@ -83,7 +83,7 @@ export abstract class Panel { } @NativeCall - private __responedCallback__(viewIds: string[], callbackId: string) { + private __response__(viewIds: string[], callbackId: string) { const v = this.retrospectView(viewIds) if (v === undefined) { loge(`Cannot find view for ${viewIds}`)