feat:enable click on ListItem
This commit is contained in:
		| @@ -56,6 +56,10 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder { | ||||
|         mSuperNode = parentNode; | ||||
|     } | ||||
|  | ||||
|     public void setId(String id) { | ||||
|         this.mId = id; | ||||
|     } | ||||
|  | ||||
|     public View getDoricLayer() { | ||||
|         return doricLayer; | ||||
|     } | ||||
|   | ||||
| @@ -58,6 +58,7 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolde | ||||
|     @Override | ||||
|     public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) { | ||||
|         JSObject jsObject = getItemModel(position); | ||||
|         holder.listItemNode.setId(String.valueOf(position)); | ||||
|         holder.listItemNode.blend(jsObject.getProperty("props").asObject(), holder.itemView.getLayoutParams()); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -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 | ||||
| class ListPanel extends Panel { | ||||
|     build(rootView: Group): void { | ||||
| @@ -22,14 +29,20 @@ class ListPanel extends Panel { | ||||
|                         bottom: 10, | ||||
|                     }, | ||||
|                 }, | ||||
|                 text: `第${idx}行内容`, | ||||
|                 text: `Cell At Line ${idx}`, | ||||
|                 textAlignment: gravity().center(), | ||||
|                 textColor: Color.parse("#ffffff"), | ||||
|                 textSize: 20, | ||||
|             })).also(it => { | ||||
|                 it.gravity = gravity().center() | ||||
|                 it.bgColor = Color.parse("#fff00f") | ||||
|                 it.bgColor = Color.parse(colors[idx % colors.length]) | ||||
|                 it.layoutConfig = { | ||||
|                     widthSpec: LayoutSpec.AT_MOST, | ||||
|                     heightSpec: LayoutSpec.WRAP_CONTENT, | ||||
|                     heightSpec: LayoutSpec.EXACTLY, | ||||
|                 } | ||||
|                 it.height = 50 | ||||
|                 it.onClick = () => { | ||||
|                     log(`Click item at ${idx}`) | ||||
|                 } | ||||
|             }) | ||||
|         } | ||||
|   | ||||
| @@ -230,7 +230,6 @@ export function jsCallEntityMethod(contextId: string, methodName: string, args?: | ||||
|         hookBeforeNativeCall(context) | ||||
|         const ret = Reflect.apply(Reflect.get(context.entity, methodName), context.entity, argumentsList) | ||||
|         hookAfterNativeCall(context) | ||||
|         loge(methodName, ret) | ||||
|         return ret | ||||
|     } else { | ||||
|         loge(`Cannot find method for context id:${contextId},method name is:${methodName}`) | ||||
|   | ||||
| @@ -18,6 +18,7 @@ import { View, Property, LayoutSpec, Superview } from "./view"; | ||||
| import { Model } from "../util/types"; | ||||
| import { O_TRUNC } from "constants"; | ||||
| import { Stack } from "./layout"; | ||||
| import { loge } from "../util/log"; | ||||
| export function listItem(item: View) { | ||||
|     return (new ListItem).also((it) => { | ||||
|         it.layoutConfig = { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user