feat:Refreshable +list

This commit is contained in:
pengfei.zhou 2019-11-26 14:06:44 +08:00
parent 84b9ec0f22
commit 0b1174c3fd
3 changed files with 112 additions and 74 deletions

View File

@ -1,15 +1,11 @@
import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout, Gravity, hlayout, Text } from "doric"; import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout, Gravity, hlayout, Text, refreshable, Refreshable, ListItem } from "doric";
const colors = [ import { rotatedArrow, colors } from "./utils";
"#f0932b", import { isObject } from "util";
"#eb4d4b",
"#6ab04c",
"#e056fd",
"#686de0",
"#30336b",
]
@Entry @Entry
class ListPanel extends Panel { class ListPanel extends Panel {
build(rootView: Group): void { build(rootView: Group): void {
let refreshView: Refreshable
let offset = Math.ceil(Math.random() * colors.length)
vlayout([ vlayout([
text({ text({
text: "ListDemo", text: "ListDemo",
@ -23,9 +19,14 @@ class ListPanel extends Panel {
textAlignment: gravity().center(), textAlignment: gravity().center(),
height: 50, height: 50,
}), }),
list({ refreshView = refreshable({
itemCount: 1000, onRefresh: () => {
renderItem: (idx: number) => { refreshView.setRefreshing(context, false).then(() => {
(refreshView.content as List).also(it => {
it.reset()
offset = Math.ceil(Math.random() * colors.length)
it.itemCount = 40
it.renderItem = (idx: number) => {
let counter!: Text let counter!: Text
return listItem( return listItem(
hlayout([ hlayout([
@ -64,7 +65,7 @@ class ListPanel extends Panel {
} }
} }
it.gravity = gravity().center() it.gravity = gravity().center()
it.bgColor = Color.parse(colors[idx % colors.length]) it.bgColor = colors[(idx + offset) % colors.length]
let clicked = 0 let clicked = 0
it.onClick = () => { it.onClick = () => {
counter.text = `Item Clicked ${++clicked}` counter.text = `Item Clicked ${++clicked}`
@ -87,12 +88,21 @@ class ListPanel extends Panel {
}) })
} }
}) })
}
})
})
}, },
header: rotatedArrow(context),
content: list({
itemCount: 0,
renderItem: () => new ListItem,
layoutConfig: { layoutConfig: {
widthSpec: LayoutSpec.AT_MOST, widthSpec: LayoutSpec.AT_MOST,
heightSpec: LayoutSpec.AT_MOST, heightSpec: LayoutSpec.AT_MOST,
}, },
}), }),
}),
]).also(it => { ]).also(it => {
it.layoutConfig = { it.layoutConfig = {
widthSpec: LayoutSpec.AT_MOST, widthSpec: LayoutSpec.AT_MOST,

File diff suppressed because one or more lines are too long

View File

@ -57,6 +57,10 @@ export class List extends Superview implements IList {
@Property @Property
batchCount = 15 batchCount = 15
reset() {
this.cachedViews.clear()
this.itemCount = 0
}
private getItem(itemIdx: number) { private getItem(itemIdx: number) {
let view = this.cachedViews.get(`${itemIdx}`) let view = this.cachedViews.get(`${itemIdx}`)
if (view === undefined) { if (view === undefined) {