mirror of
https://github.com/568071718/creator-collection-view
synced 2025-12-08 13:48:50 +00:00
更新一些项目描述
This commit is contained in:
80
README.md
80
README.md
@@ -1,10 +1,6 @@
|
||||

|
||||
|
||||
|
||||
> YXCollectionView 的主要作用是管理数据的渲染和展示。为了提升性能,它通过节点池机制高效地复用单元节点,这使得它具备虚拟列表的特性。但需要特别指出的是,YXCollectionView 的核心业务不仅限于虚拟列表的管理,它更侧重于布局排列的全面控制。
|
||||
>
|
||||
> *<small>简介由 AI 生成</small>*
|
||||
>
|
||||
---
|
||||
|
||||
## 开发环境
|
||||
* 2.x
|
||||
@@ -18,72 +14,40 @@
|
||||
|
||||
* 节点回收复用(虚拟列表模式)
|
||||
* 分帧预加载节点(非虚拟列表模式)
|
||||
* 多种单元 cell 节点类型
|
||||
* 多种 cell 节点类型
|
||||
* 列表嵌套
|
||||
* 分区概念
|
||||
* supplementary 补充视图概念
|
||||
* 多种 supplementary 节点类型
|
||||
* [布局解耦(组件核心)](./doc/md/layout.md)
|
||||
|
||||
## table-layout
|
||||
|
||||
* 仿 TableView 样式,仅支持垂直方向排列
|
||||
* 支持设置不同的行高
|
||||
* 支持分区模式
|
||||
* 支持添加区头/区尾
|
||||
* 支持区头/区尾悬浮吸附效果
|
||||
* [在线演示](https://568071718.github.io/cocos-creator-build/collection-view/table-layout/)
|
||||
|
||||
## 使用
|
||||
|
||||
* 注册 cell,通过 register() 注册列表内可能用到的节点类型,可多次注册
|
||||
|
||||
```ts
|
||||
this.listComp.register(`cell1`, () => instantiate(<your cell prefab>))
|
||||
this.listComp.register(`cell2`, () => instantiate(<your cell prefab>))
|
||||
this.listComp.register(`cell3`, () => instantiate(<your cell prefab>))
|
||||
this.listComp.register(`cell4`, () => instantiate(<your cell prefab>))
|
||||
this.listComp.register(`cell5`, () => instantiate(<your cell prefab>))
|
||||
```
|
||||
|
||||
* 绑定数据源,更新节点数据
|
||||
|
||||
```ts
|
||||
// this.testData 是模拟数据
|
||||
|
||||
// 确定列表内一共需要显示多少条内容
|
||||
this.listComp.numberOfItems = () => this.testData.length;
|
||||
|
||||
this.listComp.cellForItemAt = (indexPath, collectionView) => {
|
||||
// 通过下标可以获取到对应的数据
|
||||
const data = this.testData[indexPath.item]
|
||||
|
||||
// 通过标识符获取重用池内的节点
|
||||
const cell = collectionView.dequeueReusableCell(`your cell identifier`)
|
||||
|
||||
// 更新数据显示
|
||||
const comp = cell.getComponent(CommonCell)
|
||||
comp.label.string = `${indexPath}`
|
||||
comp.randomIcon()
|
||||
comp.randomShapeColor()
|
||||
comp.randomStar()
|
||||
comp.randomLevelSign()
|
||||
|
||||
return cell // 返回这个节点给列表显示
|
||||
listComp.numberOfItems = () => 10000
|
||||
listComp.cellForItemAt = (indexPath, collectionView) => {
|
||||
const cell = collectionView.dequeueReusableCell(`cell`)
|
||||
cell.getChildByName('label').getComponent(Label).string = `${indexPath}`
|
||||
return cell
|
||||
}
|
||||
```
|
||||
|
||||
* 确定布局方案
|
||||
|
||||
```ts
|
||||
let layout = new YXTableLayout()
|
||||
layout.spacing = 20
|
||||
layout.itemSize = new math.Size(400, 100)
|
||||
this.listComp.layout = layout
|
||||
layout.rowHeight = 100
|
||||
listComp.layout = layout
|
||||
|
||||
listComp.reloadData()
|
||||
```
|
||||
|
||||
以上几个步骤不分先后,确保都配置好就好,数据源绑定/布局对象配置好之后,在需要刷新的时候执行 reloadData
|
||||
|
||||
```ts
|
||||
// 更新列表
|
||||
this.listComp.reloadData()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
补充: 附张通过编辑器内注册 cell 的截图
|
||||
|
||||

|
||||
|
||||
## 更多接口
|
||||
|
||||
* 内部 ScrollView 组件
|
||||
|
||||
Reference in New Issue
Block a user