feat:enable click on ListItem

This commit is contained in:
pengfei.zhou 2019-11-13 17:59:06 +08:00
parent 460030fc4f
commit 3933582e1e
5 changed files with 24 additions and 6 deletions

View File

@ -56,6 +56,10 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
mSuperNode = parentNode; mSuperNode = parentNode;
} }
public void setId(String id) {
this.mId = id;
}
public View getDoricLayer() { public View getDoricLayer() {
return doricLayer; return doricLayer;
} }

View File

@ -58,6 +58,7 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolde
@Override @Override
public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) { public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) {
JSObject jsObject = getItemModel(position); JSObject jsObject = getItemModel(position);
holder.listItemNode.setId(String.valueOf(position));
holder.listItemNode.blend(jsObject.getProperty("props").asObject(), holder.itemView.getLayoutParams()); holder.listItemNode.blend(jsObject.getProperty("props").asObject(), holder.itemView.getLayoutParams());
} }

View File

@ -1,5 +1,12 @@
import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, ListItem, NativeCall, listItem } from "doric"; import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, ListItem, NativeCall, listItem, log } from "doric";
const colors = [
"#f0932b",
"#eb4d4b",
"#6ab04c",
"#e056fd",
"#686de0",
"#30336b",
]
@Entry @Entry
class ListPanel extends Panel { class ListPanel extends Panel {
build(rootView: Group): void { build(rootView: Group): void {
@ -22,14 +29,20 @@ class ListPanel extends Panel {
bottom: 10, bottom: 10,
}, },
}, },
text: `${idx}行内容`, text: `Cell At Line ${idx}`,
textAlignment: gravity().center(), textAlignment: gravity().center(),
textColor: Color.parse("#ffffff"),
textSize: 20,
})).also(it => { })).also(it => {
it.gravity = gravity().center() it.gravity = gravity().center()
it.bgColor = Color.parse("#fff00f") it.bgColor = Color.parse(colors[idx % colors.length])
it.layoutConfig = { it.layoutConfig = {
widthSpec: LayoutSpec.AT_MOST, widthSpec: LayoutSpec.AT_MOST,
heightSpec: LayoutSpec.WRAP_CONTENT, heightSpec: LayoutSpec.EXACTLY,
}
it.height = 50
it.onClick = () => {
log(`Click item at ${idx}`)
} }
}) })
} }

View File

@ -230,7 +230,6 @@ export function jsCallEntityMethod(contextId: string, methodName: string, args?:
hookBeforeNativeCall(context) hookBeforeNativeCall(context)
const ret = Reflect.apply(Reflect.get(context.entity, methodName), context.entity, argumentsList) const ret = Reflect.apply(Reflect.get(context.entity, methodName), context.entity, argumentsList)
hookAfterNativeCall(context) hookAfterNativeCall(context)
loge(methodName, ret)
return ret return ret
} else { } else {
loge(`Cannot find method for context id:${contextId},method name is:${methodName}`) loge(`Cannot find method for context id:${contextId},method name is:${methodName}`)

View File

@ -18,6 +18,7 @@ import { View, Property, LayoutSpec, Superview } from "./view";
import { Model } from "../util/types"; import { Model } from "../util/types";
import { O_TRUNC } from "constants"; import { O_TRUNC } from "constants";
import { Stack } from "./layout"; import { Stack } from "./layout";
import { loge } from "../util/log";
export function listItem(item: View) { export function listItem(item: View) {
return (new ListItem).also((it) => { return (new ListItem).also((it) => {
it.layoutConfig = { it.layoutConfig = {