feat:refact SliderDemo
This commit is contained in:
parent
d31a5caffd
commit
1245bbd08e
@ -1,18 +1,7 @@
|
|||||||
|
|
||||||
import { Group, Panel, Text, text, gravity, Color, Stack, LayoutSpec, vlayout, hlayout, scroller, IVLayout, IHLayout, layoutConfig } from "doric";
|
import { Group, Panel, Text, text, gravity, Color, Stack, LayoutSpec, vlayout, hlayout, scroller, IVLayout, IHLayout, layoutConfig } from "doric";
|
||||||
|
import { colors } from "./colorutils";
|
||||||
|
|
||||||
const colors = [
|
|
||||||
"#70a1ff",
|
|
||||||
"#7bed9f",
|
|
||||||
"#ff6b81",
|
|
||||||
"#a4b0be",
|
|
||||||
"#f0932b",
|
|
||||||
"#eb4d4b",
|
|
||||||
"#6ab04c",
|
|
||||||
"#e056fd",
|
|
||||||
"#686de0",
|
|
||||||
"#30336b",
|
|
||||||
].map(e => Color.parse(e))
|
|
||||||
|
|
||||||
function box(idx = 0) {
|
function box(idx = 0) {
|
||||||
return (new Stack).also(it => {
|
return (new Stack).also(it => {
|
||||||
|
@ -1,53 +1,48 @@
|
|||||||
import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout, Gravity, hlayout, slider, slideItem } from "doric";
|
import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout, Gravity, hlayout, slider, slideItem, image, layoutConfig } from "doric";
|
||||||
const colors = [
|
import { colors } from "./colorutils";
|
||||||
"#f0932b",
|
|
||||||
"#eb4d4b",
|
const imageUrls = [
|
||||||
"#6ab04c",
|
'http://b.hiphotos.baidu.com/image/pic/item/908fa0ec08fa513db777cf78376d55fbb3fbd9b3.jpg',
|
||||||
"#e056fd",
|
'http://f.hiphotos.baidu.com/image/pic/item/0e2442a7d933c8956c0e8eeadb1373f08202002a.jpg',
|
||||||
"#686de0",
|
'http://f.hiphotos.baidu.com/image/pic/item/b151f8198618367aa7f3cc7424738bd4b31ce525.jpg',
|
||||||
"#30336b",
|
'http://b.hiphotos.baidu.com/image/pic/item/0eb30f2442a7d9337119f7dba74bd11372f001e0.jpg',
|
||||||
|
'http://calonye.com/wp-content/uploads/2015/08/0-wx_fmtgiftpwebpwxfrom5wx_lazy1-9.gif',
|
||||||
|
'http://hbimg.b0.upaiyun.com/ca29ea125b7f2d580f573e48eb594b1ef509757f34a08-m0hK45_fw658',
|
||||||
|
'https://misc.aotu.io/ONE-SUNDAY/SteamEngine.png',
|
||||||
]
|
]
|
||||||
@Entry
|
@Entry
|
||||||
class SliderPanel extends Panel {
|
class SliderPanel extends Panel {
|
||||||
build(rootView: Group): void {
|
build(rootView: Group): void {
|
||||||
rootView.addChild(vlayout([
|
rootView.addChild(vlayout([
|
||||||
text({
|
text({
|
||||||
text: "SliderDemo",
|
text: "Gallery",
|
||||||
layoutConfig: {
|
layoutConfig: {
|
||||||
widthSpec: LayoutSpec.AT_MOST,
|
widthSpec: LayoutSpec.AT_MOST,
|
||||||
heightSpec: LayoutSpec.EXACTLY,
|
heightSpec: LayoutSpec.EXACTLY,
|
||||||
},
|
},
|
||||||
textSize: 30,
|
textSize: 30,
|
||||||
textColor: Color.parse("#535c68"),
|
textColor: Color.WHITE,
|
||||||
bgColor: Color.parse("#dff9fb"),
|
bgColor: colors[1],
|
||||||
textAlignment: gravity().center(),
|
textAlignment: gravity().center(),
|
||||||
height: 50,
|
height: 50,
|
||||||
}),
|
}),
|
||||||
slider({
|
slider({
|
||||||
itemCount: 100,
|
itemCount: 100,
|
||||||
renderPage: (idx) => {
|
renderPage: (idx) => {
|
||||||
return slideItem(text({
|
return slideItem(image({
|
||||||
layoutConfig: {
|
imageUrl: imageUrls[idx % imageUrls.length],
|
||||||
widthSpec: LayoutSpec.AT_MOST,
|
layoutConfig: layoutConfig().wrap().a(gravity().center()),
|
||||||
heightSpec: LayoutSpec.EXACTLY,
|
})).also(it => {
|
||||||
alignment: gravity().center(),
|
|
||||||
},
|
|
||||||
text: `Page At Line ${idx}`,
|
|
||||||
textAlignment: gravity().center(),
|
|
||||||
textColor: Color.parse("#ffffff"),
|
|
||||||
textSize: 20,
|
|
||||||
height: 300,
|
|
||||||
bgColor: Color.parse(colors[idx % colors.length]),
|
|
||||||
}).also(it => {
|
|
||||||
let start = idx
|
let start = idx
|
||||||
it.onClick = () => {
|
it.onClick = () => {
|
||||||
it.bgColor = Color.parse(colors[++start % colors.length])
|
it.bgColor = (colors[++start % colors.length])
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
},
|
},
|
||||||
layoutConfig: {
|
layoutConfig: {
|
||||||
widthSpec: LayoutSpec.AT_MOST,
|
widthSpec: LayoutSpec.AT_MOST,
|
||||||
heightSpec: LayoutSpec.WRAP_CONTENT,
|
heightSpec: LayoutSpec.WRAP_CONTENT,
|
||||||
|
weight: 1,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
]).also(it => {
|
]).also(it => {
|
||||||
|
14
demo/src/colorutils.ts
Normal file
14
demo/src/colorutils.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { Color } from "doric";
|
||||||
|
|
||||||
|
export const colors = [
|
||||||
|
"#70a1ff",
|
||||||
|
"#7bed9f",
|
||||||
|
"#ff6b81",
|
||||||
|
"#a4b0be",
|
||||||
|
"#f0932b",
|
||||||
|
"#eb4d4b",
|
||||||
|
"#6ab04c",
|
||||||
|
"#e056fd",
|
||||||
|
"#686de0",
|
||||||
|
"#30336b",
|
||||||
|
].map(e => Color.parse(e))
|
@ -148,7 +148,7 @@ export class LayoutConfigImpl implements LayoutConfig, Modeling {
|
|||||||
widthSpec: this.widthSpec,
|
widthSpec: this.widthSpec,
|
||||||
heightSpec: this.heightSpec,
|
heightSpec: this.heightSpec,
|
||||||
margin: this.margin,
|
margin: this.margin,
|
||||||
alignment: this.alignment,
|
alignment: this.alignment ? this.alignment.toModel() : undefined,
|
||||||
weight: this.weight,
|
weight: this.weight,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ export function slideItem(item: View) {
|
|||||||
return (new SlideItem).also((it) => {
|
return (new SlideItem).also((it) => {
|
||||||
it.layoutConfig = {
|
it.layoutConfig = {
|
||||||
widthSpec: LayoutSpec.AT_MOST,
|
widthSpec: LayoutSpec.AT_MOST,
|
||||||
heightSpec: LayoutSpec.WRAP_CONTENT,
|
heightSpec: LayoutSpec.AT_MOST,
|
||||||
}
|
}
|
||||||
it.addChild(item)
|
it.addChild(item)
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user