This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-demo/src/ListDemo.ts

125 lines
6.1 KiB
TypeScript
Raw Normal View History

2019-12-10 20:32:17 +08:00
import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout, Gravity, hlayout, Text, refreshable, Refreshable, ListItem, layoutConfig } from "doric";
2019-12-04 14:07:14 +08:00
import { rotatedArrow, colors } from "./utils";
@Entry
class ListPanel extends Panel {
build(rootView: Group): void {
let refreshView: Refreshable
let offset = Math.ceil(Math.random() * colors.length)
vlayout([
text({
text: "ListDemo",
layoutConfig: {
2019-12-14 16:32:04 +08:00
widthSpec: LayoutSpec.MOST,
heightSpec: LayoutSpec.JUST,
2019-12-04 14:07:14 +08:00
},
textSize: 30,
textColor: Color.parse("#535c68"),
backgroundColor: Color.parse("#dff9fb"),
textAlignment: gravity().center(),
height: 50,
}),
refreshView = refreshable({
onRefresh: () => {
refreshView.setRefreshing(context, false).then(() => {
(refreshView.content as List).also(it => {
it.reset()
offset = Math.ceil(Math.random() * colors.length)
it.itemCount = 40
2019-12-10 20:32:17 +08:00
it.loadMore = true
it.onLoadMore = () => {
setTimeout(() => {
it.itemCount += 10
}, 1000)
}
it.loadMoreView = listItem(text({
text: "Loading",
2019-12-14 16:32:04 +08:00
layoutConfig: layoutConfig().most().configHeight(LayoutSpec.JUST).configAligmnet(Gravity.Center),
2019-12-10 20:32:17 +08:00
height: 50,
}))
2019-12-04 14:07:14 +08:00
it.renderItem = (idx: number) => {
let counter!: Text
return listItem(
hlayout([
text({
layoutConfig: {
2019-12-14 16:32:04 +08:00
widthSpec: LayoutSpec.FIT,
heightSpec: LayoutSpec.JUST,
2019-12-04 14:07:14 +08:00
alignment: gravity().center(),
},
text: `Cell At Line ${idx}`,
textAlignment: gravity().center(),
textColor: Color.parse("#ffffff"),
textSize: 20,
height: 50,
}),
text({
textColor: Color.parse("#ffffff"),
textSize: 20,
text: "",
}).also(it => {
counter = it
it.layoutConfig = {
2019-12-14 16:32:04 +08:00
widthSpec: LayoutSpec.FIT,
heightSpec: LayoutSpec.FIT,
2019-12-04 14:07:14 +08:00
margin: {
left: 10,
}
}
})
]).also(it => {
it.layoutConfig = {
2019-12-14 16:32:04 +08:00
widthSpec: LayoutSpec.MOST,
heightSpec: LayoutSpec.FIT,
2019-12-04 14:07:14 +08:00
margin: {
bottom: 2,
}
}
it.gravity = gravity().center()
it.backgroundColor = colors[(idx + offset) % colors.length]
let clicked = 0
it.onClick = () => {
counter.text = `Item Clicked ${++clicked}`
}
})
).also(it => {
it.layoutConfig = {
2019-12-14 16:32:04 +08:00
widthSpec: LayoutSpec.MOST,
heightSpec: LayoutSpec.FIT,
2019-12-04 14:07:14 +08:00
}
it.onClick = () => {
log(`Click item at ${idx}`)
it.height += 10
it.nativeChannel(context, "getWidth")().then(
resolve => {
log(`resolve,${resolve}`)
},
reject => {
log(`reject,${reject}`)
})
}
})
}
})
})
},
2019-12-04 18:15:41 +08:00
header: rotatedArrow(),
2019-12-04 14:07:14 +08:00
content: list({
itemCount: 0,
renderItem: () => new ListItem,
layoutConfig: {
2019-12-14 16:32:04 +08:00
widthSpec: LayoutSpec.MOST,
heightSpec: LayoutSpec.MOST,
2019-12-04 14:07:14 +08:00
},
}),
}),
]).also(it => {
it.layoutConfig = {
2019-12-14 16:32:04 +08:00
widthSpec: LayoutSpec.MOST,
heightSpec: LayoutSpec.MOST,
2019-12-04 14:07:14 +08:00
}
it.backgroundColor = Color.WHITE
}).in(rootView)
refreshView.backgroundColor = Color.YELLOW
}
}