9 Star 0 Fork 0

yanshuifeng/repeat_feature_demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
grid_repeat_test.ets 2.67 KB
一键复制 编辑 原始数据 按行查看 历史
xxx 提交于 2024-06-13 23:49 . add grid repeat test
@ObservedV2
class GridArrayHolder {
@Trace arr: Array<string> = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
}
@Entry
@ComponentV2
struct ParentGrid {
@Local arrayHolder: GridArrayHolder = new GridArrayHolder();
scroller: Scroller = new Scroller();
build() {
Column({ space: 5 }) {
Text('grid_repeat_test.ets')
Row() {
Button('scrollTo 0').height(100).onClick(() => {
this.scroller.scrollToIndex(0)
})
Button('scrollTo 4').height(100).onClick(() => {
this.scroller.scrollToIndex(4)
})
Button('scrollTo 10').height(100).onClick(() => {
this.scroller.scrollToIndex(10)
})
}
Row() {
Button(`change arr[0] ${this.arrayHolder.arr[0]}`).height(100).onClick(() => {
this.arrayHolder.arr[0] = this.arrayHolder.arr[0] + this.arrayHolder.arr[0]
})
Button('delete [0]').height(100).onClick(() => {
this.arrayHolder.arr.shift()
})
Button('change 20').height(100).onClick(() => {
this.arrayHolder.arr[20] = this.arrayHolder.arr[20] + this.arrayHolder.arr[20]
})
}
Grid(this.scroller) {
GridItem() {
Text('first Item').width('100%').height(50).fontColor(Color.White).backgroundColor(Color.Blue)
}
Repeat(this.arrayHolder.arr)
// @ts-ignore
.virtualScroll({ totalCount: this.arrayHolder.arr.length, })
.key((item, index) => `${index}-${item}`)
.each((r) => {
GridItem() {
Row() {
Text(' * ')
.height(50).fontColor(Color.White).backgroundColor(Color.Blue)
Text(`${r.index + 1}. `)
.height(50).fontColor(Color.White).backgroundColor(Color.Blue)
Text(`Item ${r.item}`)
.height(50).fontColor(Color.White).backgroundColor(Color.Blue)
Text(' * ')
.height(50).fontColor(Color.White).backgroundColor(Color.Blue)
}
}.backgroundColor(Color.Green)
})
GridItem() {
Text('first Item').width('100%').height(50).fontColor(Color.White).backgroundColor(Color.Blue)
}
}
.onScrollIndex((start, end) => {
console.log('onScrollIndex', start, end);
})
.columnsTemplate('1fr 1fr')
.columnsGap(10)
.rowsGap(10)
.width('90%')
.backgroundColor(0xFAEEE0)
.height(300)
Button('next page')
.onClick(() => {
this.scroller.scrollPage({ next: true })
})
}.width('100%').margin({ top: 5 })
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yan-shuifeng/repeat_feature_demo.git
git@gitee.com:yan-shuifeng/repeat_feature_demo.git
yan-shuifeng
repeat_feature_demo
repeat_feature_demo
master

搜索帮助