From 1dba8d7b10e151cfc7084aeb6c3ed7cabc3aa1d6 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 19 Nov 2019 15:31:23 +0800 Subject: [PATCH] feat:fix click subview of ListItem or PageItem --- .../java/pub/doric/shader/list/ListNode.java | 7 ++++++- .../pub/doric/shader/slider/SliderNode.java | 7 ++++++- demo/index.ts | 1 + demo/src/SliderDemo.ts | 17 +++++++++++------ js-framework/src/ui/slider.ts | 2 +- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Android/doric/src/main/java/pub/doric/shader/list/ListNode.java b/Android/doric/src/main/java/pub/doric/shader/list/ListNode.java index 590e5d32..92e611d9 100644 --- a/Android/doric/src/main/java/pub/doric/shader/list/ListNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/list/ListNode.java @@ -44,7 +44,12 @@ public class ListNode extends SuperNode { @Override protected void blendSubNode(JSObject subProperties) { - listAdapter.blendSubNode(subProperties); + ViewNode node = getSubNodeById(subProperties.getProperty("id").asString().value()); + if (node != null) { + node.blend(subProperties.getProperty("props").asObject()); + } else { + listAdapter.blendSubNode(subProperties); + } } @Override diff --git a/Android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java b/Android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java index 050f89f3..0fbbcb23 100644 --- a/Android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/slider/SliderNode.java @@ -77,7 +77,12 @@ public class SliderNode extends SuperNode { @Override protected void blendSubNode(JSObject subProperties) { - slideAdapter.blendSubNode(subProperties); + ViewNode node = getSubNodeById(subProperties.getProperty("id").asString().value()); + if (node != null) { + node.blend(subProperties.getProperty("props").asObject()); + } else { + slideAdapter.blendSubNode(subProperties); + } } @Override diff --git a/demo/index.ts b/demo/index.ts index 21a61315..158cd4e3 100644 --- a/demo/index.ts +++ b/demo/index.ts @@ -3,4 +3,5 @@ export default [ 'src/Snake', 'src/ListDemo', 'src/ScrollerDemo', + 'src/SliderDemo', ] \ No newline at end of file diff --git a/demo/src/SliderDemo.ts b/demo/src/SliderDemo.ts index d8a3a885..49ca4b8a 100644 --- a/demo/src/SliderDemo.ts +++ b/demo/src/SliderDemo.ts @@ -24,25 +24,30 @@ class SliderPanel extends Panel { height: 50, }), slider({ - itemCount: 3, + itemCount: 100, renderPage: (idx) => { return slideItem(text({ layoutConfig: { - widthSpec: LayoutSpec.WRAP_CONTENT, + widthSpec: LayoutSpec.AT_MOST, heightSpec: LayoutSpec.EXACTLY, alignment: gravity().center(), }, - text: `Cell At Line ${idx}`, + text: `Page At Line ${idx}`, textAlignment: gravity().center(), textColor: Color.parse("#ffffff"), textSize: 20, - height: 50, - bgColor: Color.parse('#00ff00'), + height: 300, + bgColor: Color.parse(colors[idx % colors.length]), + }).also(it => { + let start = idx + it.onClick = () => { + it.bgColor = Color.parse(colors[++start % colors.length]) + } })) }, layoutConfig: { widthSpec: LayoutSpec.AT_MOST, - heightSpec: LayoutSpec.AT_MOST, + heightSpec: LayoutSpec.WRAP_CONTENT, }, }), ]).also(it => { diff --git a/js-framework/src/ui/slider.ts b/js-framework/src/ui/slider.ts index fe14c933..5584445a 100644 --- a/js-framework/src/ui/slider.ts +++ b/js-framework/src/ui/slider.ts @@ -4,7 +4,7 @@ import { Stack } from "./layout"; export function slideItem(item: View) { return (new SlideItem).also((it) => { it.layoutConfig = { - widthSpec: LayoutSpec.WRAP_CONTENT, + widthSpec: LayoutSpec.AT_MOST, heightSpec: LayoutSpec.WRAP_CONTENT, } it.addChild(item)