diff --git a/doric-android/doric/src/main/java/pub/doric/shader/list/ListItemNode.java b/doric-android/doric/src/main/java/pub/doric/shader/list/ListItemNode.java index 7d2a4dfc..c56efafc 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/list/ListItemNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/list/ListItemNode.java @@ -15,11 +15,18 @@ */ package pub.doric.shader.list; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.view.View; import android.widget.FrameLayout; +import com.github.pengfeizhou.jscore.JSArray; import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSValue; +import java.util.ArrayList; +import java.util.List; + import pub.doric.DoricContext; import pub.doric.extension.bridge.DoricPlugin; import pub.doric.shader.StackNode; @@ -32,6 +39,7 @@ import pub.doric.shader.StackNode; @DoricPlugin(name = "ListItem") public class ListItemNode extends StackNode { public String identifier = ""; + private JSArray actions = null; public ListItemNode(DoricContext doricContext) { super(doricContext); @@ -40,7 +48,11 @@ public class ListItemNode extends StackNode { @Override protected void blend(FrameLayout view, String name, JSValue prop) { - if ("identifier".equals(name)) { + if ("actions".equals(name)) { + if (prop.isArray()) { + this.actions = prop.asArray(); + } + } else if ("identifier".equals(name)) { this.identifier = prop.asString().value(); } else { super.blend(view, name, prop); @@ -52,5 +64,33 @@ public class ListItemNode extends StackNode { super.blend(jsObject); getNodeView().getLayoutParams().width = getLayoutParams().width; getNodeView().getLayoutParams().height = getLayoutParams().height; + if (this.actions != null && this.actions.size() > 0) { + getView().setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + if (actions == null || actions.size() == 0) { + return false; + } + String[] items = new String[actions.size()]; + final String[] callbacks = new String[actions.size()]; + for (int i = 0; i < actions.size(); i++) { + JSObject action = actions.get(i).asObject(); + String title = action.getProperty("title").asString().value(); + String callback = action.getProperty("callback").asString().value(); + items[i] = title; + callbacks[i] = callback; + } + new AlertDialog.Builder(getContext()) + .setItems(items, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + callJSResponse(callbacks[which]); + dialog.dismiss(); + } + }).show(); + return true; + } + }); + } } } diff --git a/doric-demo/src/ListDemo.ts b/doric-demo/src/ListDemo.ts index a5ce24cb..34405012 100644 --- a/doric-demo/src/ListDemo.ts +++ b/doric-demo/src/ListDemo.ts @@ -84,12 +84,14 @@ class ListVM extends ViewModel { actions: [ { title: "First", + backgroundColor: Color.RED, callback: () => { modal(context).alert("First action") } }, { title: "Second", + backgroundColor: Color.BLUE, callback: () => { modal(context).alert("Second action") }