android callJSRespone

This commit is contained in:
pengfei.zhou 2019-07-21 06:54:24 +08:00
parent c39629838d
commit eb1c076dfb
4 changed files with 36 additions and 9 deletions

View File

@ -43,4 +43,7 @@ public class DoricConstant {
public static final String DORIC_TIMER_CALLBACK = "jsCallbackTimer"; public static final String DORIC_TIMER_CALLBACK = "jsCallbackTimer";
public static final String DORIC_BRIDGE_RESOLVE = "jsCallResolve"; public static final String DORIC_BRIDGE_RESOLVE = "jsCallResolve";
public static final String DORIC_BRIDGE_REJECT = "jsCallReject"; public static final String DORIC_BRIDGE_REJECT = "jsCallReject";
public static final String DORIC_ENTITY_RESPONSE = "__response__";
} }

View File

@ -39,11 +39,15 @@ public abstract class GroupNode extends ViewNode<ViewGroup> {
String id = childObj.getProperty("id").asString().value(); String id = childObj.getProperty("id").asString().value();
ViewNode child = mChildrenNode.get(id); ViewNode child = mChildrenNode.get(id);
if (child == null) { if (child == null) {
child = ViewNode.create(getDoricContext(), id, type); child = ViewNode.create(getDoricContext(), type);
child.index = i; child.index = i;
child.ids.addAll(this.ids);
child.ids.add(id);
mChildrenNode.put(id, child); mChildrenNode.put(id, child);
mView.addView(child.mView, i); mView.addView(child.mView, i);
} else if (i != child.index) { } else if (i != child.index) {
mIndexInfo.remove(child.index);
child.index = i;
mView.removeView(child.mView); mView.removeView(child.mView);
mView.addView(child.mView, i); mView.addView(child.mView, i);
} }
@ -52,7 +56,10 @@ public abstract class GroupNode extends ViewNode<ViewGroup> {
} }
while (i < mView.getChildCount()) { while (i < mView.getChildCount()) {
mView.removeViewAt(mView.getChildCount() - 1); 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);
}
} }
} }
} }

View File

@ -7,10 +7,15 @@ import android.view.ViewGroup;
import com.github.penfeizhou.doric.DoricContext; import com.github.penfeizhou.doric.DoricContext;
import com.github.penfeizhou.doric.DoricRegistry; import com.github.penfeizhou.doric.DoricRegistry;
import com.github.penfeizhou.doric.utils.DoricComponent; 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.DoricMetaInfo;
import com.github.penfeizhou.doric.utils.DoricUtils; import com.github.penfeizhou.doric.utils.DoricUtils;
import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSObject;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/** /**
* @Description: Render * @Description: Render
* @Author: pengfei.zhou * @Author: pengfei.zhou
@ -18,10 +23,10 @@ import com.github.pengfeizhou.jscore.JSObject;
*/ */
public abstract class ViewNode<T extends View> extends DoricComponent { public abstract class ViewNode<T extends View> extends DoricComponent {
protected T mView; protected T mView;
String id;
int index; int index;
ArrayList<String> ids = new ArrayList<>();
public ViewNode(DoricContext doricContext) { public ViewNode(DoricContext doricContext) {
super(doricContext); super(doricContext);
} }
@ -43,6 +48,10 @@ public abstract class ViewNode<T extends View> extends DoricComponent {
setFrame(mView.getLayoutParams(), jsObject); setFrame(mView.getLayoutParams(), jsObject);
} }
public String getId() {
return ids.get(ids.size() - 1);
}
public void setFrame(ViewGroup.LayoutParams layoutParams, JSObject jsObject) { public void setFrame(ViewGroup.LayoutParams layoutParams, JSObject jsObject) {
float width = jsObject.getProperty("width").asNumber().toFloat(); float width = jsObject.getProperty("width").asNumber().toFloat();
float height = jsObject.getProperty("height").asNumber().toFloat(); float height = jsObject.getProperty("height").asNumber().toFloat();
@ -56,11 +65,19 @@ public abstract class ViewNode<T extends View> 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(); DoricRegistry registry = doricContext.getDriver().getRegistry();
DoricMetaInfo<ViewNode> clz = registry.acquireViewNodeInfo(type); DoricMetaInfo<ViewNode> clz = registry.acquireViewNodeInfo(type);
ViewNode node = clz.createInstance(doricContext); return clz.createInstance(doricContext);
node.id = id;
return node;
} }
} }

View File

@ -83,7 +83,7 @@ export abstract class Panel {
} }
@NativeCall @NativeCall
private __responedCallback__(viewIds: string[], callbackId: string) { private __response__(viewIds: string[], callbackId: string) {
const v = this.retrospectView(viewIds) const v = this.retrospectView(viewIds)
if (v === undefined) { if (v === undefined) {
loge(`Cannot find view for ${viewIds}`) loge(`Cannot find view for ${viewIds}`)