5 Commits

53 changed files with 2031 additions and 4922 deletions

197
README.md
View File

@@ -1,141 +1,108 @@
![title.png](./doc/imgs/title.png)
<img src="./doc/imgs/title.png" width="400"> ---
![platform](https://img.shields.io/badge/creator-2.4.13-blue?logo=cocos) ## 开发环境
![platform](https://img.shields.io/badge/creator-3.8+-blue?logo=cocos) * 2.x
引擎版本Cocos Creator **2.4.13**
编程语言TypeScript
* 3.x
引擎版本Cocos Creator **3.8.0**
编程语言TypeScript
参考苹果 UIKit 的 UICollectionView 实现的供 Cocos Creator 使用的列表组件 ## 基本特性
## 演示场景 * 节点回收复用(虚拟列表模式)
* 分帧预加载节点(非虚拟列表模式)
* 多种 cell 节点类型
* 列表嵌套
* 分区概念
* supplementary 补充视图概念
* 多种 supplementary 节点类型
* [布局解耦(组件核心)](./doc/md/layout.md)
点击图片标题可跳转对应的实现场景 ## table-layout
| [基本列表](list-3x/assets/home/table.ts) | [基本列表 (非固定高度)](list-3x/assets/home/table_anyheight.ts) | [网格布局](list-3x/assets/home/grid.ts) | * 仿 TableView 样式,仅支持垂直方向排列
| - | - | - | * 支持设置不同的行高
| <img src="./doc/imgs/jc.gif" width="220"> | <img src="./doc/imgs/jch.gif" width="220"> | <img src="./doc/imgs/jcg.gif" width="220"> | * 支持分区模式
* 支持添加区头/区尾
| [PageView](list-3x/assets/home/page_view.ts) | [PageView 嵌套](list-3x/assets/home/table_in_page.ts) | [展开子列表](list-3x/assets/home/table_sublist.ts) | * 支持区头/区尾悬浮吸附效果
| - | - | - | * [在线演示](https://568071718.github.io/cocos-creator-build/collection-view/table-layout/)
| <img src="./doc/imgs/jcp.gif" width="220"> | <img src="./doc/imgs/jjp.gif" width="220"> | <img src="./doc/imgs/jtz.gif" width="220"> |
点击图片标题可跳转对应的实现场景
## ScrollView
YXCollectionView 是基于 ScrollView 组件实现的,一些常规的滚动视图相关的配置可以直接通过 ScrollView 的属性/方法来修改
```ts
// 回弹开关
listComp.scrollView.inertia = true
// 边界开关
listComp.scrollView.elastic = true
// 减速系数
listComp.scrollView.brake = 0.8
// 获取滚动状态
let isScrolling = listComp.scrollView.isScrolling()
// 滚动
listComp.scrollView.scrollToTop(0.5)
// 更多 ScrollView 开放的方法 ...
```
还可以监听 ScrollView 定义的事件类型
```ts
// 以下两种写法一样,两个组件是同级的,获取到的是同一个 Node
listComp.node.on(ScrollView.EventType.SCROLLING, <your func>, this)
listComp.scrollView.node.on(ScrollView.EventType.SCROLLING, <your func>, this)
```
基于 ScrollView 可以很方便的获取滚动视图的各种状态以及回调事件
## 使用 ## 使用
### 注册 cell 模板
通过 `registerCell` 方法注册你的 cell 模板。为了支持多模板,这个方法约定了需要传一个标识符用来做区分
举个栗子,如果你的列表内可能会显示多种不同类型的 cell你需要创建多个 Prefab 模板,然后多次调用 `registerCell` 方法并传入不同的标识符
```ts
listComp.registerCell(`cell1`, () => { return instantiate(<your-prefab-1>) })
listComp.registerCell(`cell2`, () => { return instantiate(<your-prefab-2>) })
listComp.registerCell(`cell3`, () => { return instantiate(<your-prefab-3>) })
...
```
> 通过代码注册模板时接收的是 Node 对象,并非必须要求预制体 (Prefab)
除了代码注册,也可以在编辑器里直接关联模板,注意这里的标识符也是不能重复
<img src="./doc/imgs/erc.png" width="320">
### 关联数据源
**关联数据必须至少实现两个方法**
一个是实现 `numberOfItems` 确定一共有多少条数据
```ts
listComp.numberOfItems = (section) => {
return 10000 // 一般来说这里可能会是 <yourArray>.length
}
```
另一个是实现 `cellForItemAt` 确定要用哪个 cell 模板以及更新模板数据,这里需要通过 `dequeueReusableCell` 方法传入你注册阶段自定义的标识符来获取对应的 Node 实例对象,通过 `indexPath` 来获取当前项对应的数据
```ts ```ts
listComp.numberOfItems = () => 10000
listComp.cellForItemAt = (indexPath, collectionView) => { listComp.cellForItemAt = (indexPath, collectionView) => {
let data = <yourArray>[indexPath.row]
const cell = collectionView.dequeueReusableCell(`cell`) const cell = collectionView.dequeueReusableCell(`cell`)
cell.getChildByName('label').getComponent(Label).string = `${indexPath}` cell.getChildByName('label').getComponent(Label).string = `${indexPath}`
return cell return cell
} }
```
### 确定布局排列方案
组件本身不负责布局业务,还需要通过指定一个 `YXLayout` 子类布局对象来确定当前列表的布局方案
以 TableView 布局为例,创建一个 YXTableLayout 对象并赋值给 `YXCollectionView.layout` 属性
```ts
let layout = new YXTableLayout() let layout = new YXTableLayout()
layout.spacing = 10 layout.spacing = 20
layout.rowHeight = 120 layout.rowHeight = 100
listComp.layout = layout listComp.layout = layout
```
再以网格布局为例,只需要将 YXTableLayout 替换为 GridLayout 即可
```ts
let layout = new GridLayout()
layout.horizontalSpacing = 20
layout.verticalSpacing = 20
layout.itemSize = new math.Size(150, 180)
listComp.layout = layout
```
### 刷新
当以上配置都设置好后,在任何需要刷新的时候执行 `reloadData`
```ts
listComp.reloadData() listComp.reloadData()
``` ```
## 一些说明 ## 更多接口
* 如果你了解 UICollectionView需要注意两者表现并非是完全一致的 (有所欠缺) * 内部 ScrollView 组件
* 使用的话无需集成所有文件,可以把布局文件看作是插件,集成时候只需要 [核心组件文件](list-3x/assets/lib/yx-collection-view.ts) + 需要的布局文件即可 ```ts
* 目前在任何情况下 cell 节点的锚点都应该是 (0.5, 0.5),如果发现 cell 位置不对可以检查一下锚点设置 let isScrolling = this.listComp.scrollView.isScrolling()
* cell 根节点不应该有调整自身大小的能力 - 例如不能挂载 `Widget` 组件,或者是 `CONTAINER` 模式的 `Layout` 组件 let isAutoScrolling = this.listComp.scrollView.isAutoScrolling()
* 监听不到 `scroll-ended` 事件,滚动时卡住(无惯性滚动,无回弹) - 将 `recycleInterval` 设置为 0 this.listComp.scrollView.brake = 0.8
* 异步加载图片显示错乱 - 这个问题需要自身业务层解决,因为虚拟列表节点存在复用情况,异步加载回调时机不确定 this.listComp.scrollView.bounceDuration = 0.25
* 列表有 Widget 组件或者列表自身节点大小改变时布局错乱 - 将 `autoReloadOnSizeChange` 设置为 true this.listComp.scrollView.scrollToOffset(new math.Vec2(0, 200))
* 列表刷新时部分 cell 会闪烁 - 在调用 `dequeueReusableCell` 方法匹配节点时额外传一个 `indexPath` 参数 // ... 可以直接使用更多 ScrollView 属性或者方法
```
* 开启分区
```ts
// 注意: 分区需要自定义 YXLayout 支持
this.listComp.numberOfSections = () => 2 // 设置列表分 2 个区排列
this.listComp.numberOfItems = (section, collectionView) => {
if (section == 0) {
return 10 // 第 1 个区返回 10 条数据
}
if (section == 1) {
return 20 // 第 2 个区返回 20 条数据
}
return 0 // 默认情况
}
```
* 节点显示状态回调
```ts
this.listComp.onCellDisplay = (cell, indexPath, collectionView) => {
log(`onCellDisplay: ${indexPath}`)
}
this.listComp.onCellEndDisplay = (cell, indexPath, collectionView) => {
log(`onCellEndDisplay: ${indexPath}`)
}
```
* 滚动至指定位置
```ts
let indexPath = new YXIndexPath(0, 2) // 要滚动到的节点索引
this.listComp.scrollTo(indexPath)
```
* 预加载相关接口
```ts
this.listComp.preloadNodesLimitPerFrame = 2 // 每帧加载多少个节点
this.listComp.preloadProgress = (current, total) => {
log(`加载进度: ${current}/${total}`)
}
```
## 相关链接 ## 相关链接
* [Github](https://github.com/568071718/creator-collection-view)
* [Gitee](https://gitee.com/568071718/creator-collection-view)
* [查看声明文件](./doc/declarations/yx-collection-view.d.ts)
* [旧版文档](https://gitee.com/568071718/creator-collection-view-doc)
* [Gitee 镜像](https://gitee.com/568071718/creator-collection-view)

441
doc/declarations/yx-collection-view.d.ts vendored Normal file
View File

@@ -0,0 +1,441 @@
import { Component, math, Node, ScrollView } from 'cc';
/**
* 定义列表的滚动方向
*/
declare enum _yx_collection_view_scroll_direction {
/**
* 水平滚动
*/
HORIZONTAL = 0,
/**
* 垂直滚动
*/
VERTICAL = 1
}
/**
* 列表节点加载模式
*/
declare enum _yx_collection_view_list_mode {
/**
* 根据列表显示范围加载需要的节点,同类型的节点会进行复用
* 优点: 控制总节点数量,不会创建大量节点
* 缺点: 因为有复用逻辑节点内容会频繁更新cell 更新业务比较重的话列表会抖动,例如 Label (NONE) 很多的节点
*/
RECYCLE = 0,
/**
* 直接预加载所有的节点,处于列表显示范围外的节点透明化处理
* 优点: 避免 cell 频繁更新,优化大量 Label (NONE) 场景下的卡顿问题
* 缺点: 会实例化所有节点,并非真正的虚拟列表,仅仅是把显示范围外的节点透明了,如果列表数据量很大仍然会卡
*/
PRELOAD = 1
}
/**
* 表示索引的对象
*/
export declare class YXIndexPath {
static ZERO: Readonly<YXIndexPath>;
/**
* 区索引
*/
get section(): number;
/**
* 单元格在区内的位置
*/
get item(): number;
/**
* item 别名
*/
get row(): number;
constructor(section: number, item: number);
clone(): YXIndexPath;
equals(other: YXIndexPath): boolean;
toString(): string;
}
/**
* 表示边距的对象
*/
export declare class YXEdgeInsets {
static ZERO: Readonly<YXEdgeInsets>;
top: number;
left: number;
bottom: number;
right: number;
constructor(top: number, left: number, bottom: number, right: number);
clone(): YXEdgeInsets;
equals(other: YXEdgeInsets): boolean;
set(other: YXEdgeInsets): void;
toString(): string;
}
/**
* 节点的布局属性
*/
export declare class YXLayoutAttributes {
/**
* 创建一个 cell 布局属性实例
*/
static layoutAttributesForCell(indexPath: YXIndexPath): YXLayoutAttributes;
/**
* 创建一个 supplementary 布局属性实例
* @param kinds 自定义类别标识,更多说明查看 supplementaryKinds
*/
static layoutAttributesForSupplementary(indexPath: YXIndexPath, kinds: string): YXLayoutAttributes;
/**
* 构造方法,外部禁止直接访问,需要通过上面的静态方法创建对象
*/
protected constructor();
/**
* 节点索引
*/
get indexPath(): YXIndexPath;
/**
* 节点种类
*/
get elementCategory(): "Cell" | "Supplementary";
/**
* Supplementary 种类,本身无实际意义,具体作用由自定义布局规则决定
*/
get supplementaryKinds(): string;
/**
* 节点在滚动视图中的位置和大小属性
* origin 属性表示节点在父视图坐标系中的左上角的位置size 属性表示节点的宽度和高度
*/
get frame(): math.Rect;
/**
* 节点层级
* 越小会越早的添加到滚动视图上
* https://docs.cocos.com/creator/manual/zh/ui-system/components/editor/ui-transform.html?h=uitrans
* 备注: 内部暂时是通过节点的 siblingIndex 实现的,如果自定义 layout 有修改这个值的需求,需要重写 layout 的 @shouldUpdateAttributesZIndex 方法,默认情况下会忽略这个配置
*/
zIndex: number;
/**
* 节点透明度
* 备注: 内部通过 UIOpacity 组件实现,会修改节点 UIOpacity 组件的 opacity 值,如果自定义 layout 有修改这个值的需求,需要重写 layout 的 @shouldUpdateAttributesOpacity 方法,默认情况下会忽略这个配置
*/
opacity: number;
/**
* 节点变换 - 缩放
*/
scale: math.Vec3;
/**
* 节点变换 - 平移
*/
offset: math.Vec3;
/**
* 节点变换 - 旋转
* 备注: 3D 变换似乎需要透视相机???
*/
eulerAngles: math.Vec3;
}
/**
* 布局规则
* 这里只是约定出了一套接口,内部只是一些基础实现,具体布局方案通过子类重载去实现
*/
export declare abstract class YXLayout {
constructor();
/**
* @required
* 整个滚动区域大小
* 需要在 prepare 内初始化
*/
contentSize: math.Size;
/**
* @required
* 所有元素的布局属性
* 需要在 prepare 内初始化
* @todo 这个不应该限制为数组结构,准确来说是不应该限制开发者必须使用数组来保存所有布局属性,目前为了实现预加载模式暂时是必须要求数组结构,后续有好的方案的话应该考虑优化
*/
attributes: YXLayoutAttributes[];
/**
* @required
* 子类重写实现布局方案
* 注意: 必须初始化滚动区域大小并赋值给 contentSize 属性
* 注意: 必须初始化所有的元素布局属性,并保存到 attributes 数组
* 可选: 根据 collectionView 的 scrollDirection 支持不同的滚动方向
*/
abstract prepare(collectionView: YXCollectionView): void;
/**
* @optional
* 列表在首次更新数据后会执行这个方法
* 在这个方法里设置滚动视图的初始偏移量
*
* @example
* // 比如一个垂直列表希望初始化时从最顶部开始展示数据,那么可以在这个方法里通过 scrollToTop 实现
* initOffset(collectionView: YXCollectionView): void {
* collectionView.scrollView.scrollToTop()
* }
*/
initOffset(collectionView: YXCollectionView): void;
/**
* @optional
* 当一次手势拖动结束后会立即调用此方法,通过重写这个方法可以定制列表最终停留的位置
*
* @param collectionView 列表组件
* @param touchMoveVelocity 手势速度
* @param startOffset 此次手势开始时列表的偏移位置
* @param originTargetOffset 接下来将要自动滚动到的位置
* @param originScrollDuration 接下来的惯性滚动持续时间
* @returns 可以返回 null ,返回 null 执行默认的惯性滚动逻辑
*
* 另外关于返回值的字段说明
* @param offset 这个字段表示列表本次滚动结束时期望停留的位置,一旦返回了这个字段,列表最终将会停留至返回的这个位置
* @param time 可选,默认为 originScrollDuration这个字段表示自动滚动至期望停留位置需要的时间
* @param attenuated 可选,默认为 true这个字段表示惯性滚动速度是否衰减
*/
targetOffset(collectionView: YXCollectionView, touchMoveVelocity: math.Vec3, startOffset: math.Vec2, originTargetOffset: math.Vec2, originScrollDuration: number): {
offset: math.Vec2;
time?: number;
attenuated?: boolean;
} | null;
/**
* @optional
* 列表每次滚动结束后会调用此方法
*/
onScrollEnded(collectionView: YXCollectionView): void;
/**
* @optional
* 当滚动视图的可见范围变化后执行,这个方法会在列表滚动过程中频繁的执行
* 在这个方法里可以调整节点属性以实现交互性的节点变换效果,(如果在这个方法里调整了节点变换属性,需要重写 shouldUpdateAttributesForBoundsChange 以支持实时变换)
*
* @param rect 当前滚动视图的可见区域
*
* @returns
* 关于这个方法的返回值,最优的情况应该是根据实际的布局情况计算出当前显示区域内需要显示的所有布局属性
* 列表在更新可见节点时会遍历这个方法返回的数组并依次检查节点是否需要添加到列表内,默认这个方法是直接返回所有的布局属性,也就是在更新可见节点时的时间复杂度默认为 O(attributes.length),除非有更优的算法,否则建议直接返回所有的布局属性
*/
layoutAttributesForElementsInRect(rect: math.Rect, collectionView: YXCollectionView): YXLayoutAttributes[];
layoutAttributesForItemAtIndexPath(indexPath: YXIndexPath, collectionView: YXCollectionView): YXLayoutAttributes;
layoutAttributesForSupplementaryAtIndexPath(indexPath: YXIndexPath, collectionView: YXCollectionView, kinds: string): YXLayoutAttributes;
/**
* @optional
* 列表组件在调用 scrollTo 方法时会触发这个方法,如果实现了这个方法,最终的滚动停止位置以这个方法返回的为准
*/
scrollTo(indexPath: YXIndexPath, collectionView: YXCollectionView): math.Vec2;
/**
* @optional
* @see YXLayoutAttributes.zIndex
*/
shouldUpdateAttributesZIndex(): boolean;
/**
* @optional
* @see YXLayoutAttributes.opacity
*/
shouldUpdateAttributesOpacity(): boolean;
/**
* @optional
* 此布局下的节点,是否需要实时更新变换效果
* @returns 返回 true 会忽略 YXCollectionView 的 frameInterval 设置,强制在滚动过程中实时更新节点
*/
shouldUpdateAttributesForBoundsChange(): boolean;
/**
* @optional
* 列表组件销毁时执行
*/
onDestroy(): void;
}
/**
* @see NodePool.poolHandlerComp
* 节点的自定义组件可以通过这个接口跟 NodePool 的重用业务关联起来
*/
export interface YXCollectionViewCell extends Component {
unuse(): void;
reuse(args: any): void;
}
/**
* 列表组件
*/
export declare class YXCollectionView extends Component {
/**
* 访问定义的私有枚举
*/
static ScrollDirection: typeof _yx_collection_view_scroll_direction;
static Mode: typeof _yx_collection_view_list_mode;
/**
* 滚动视图组件
*/
get scrollView(): ScrollView;
/**
* 允许手势滚动
*/
scrollEnabled: boolean;
/**
* 允许鼠标滑轮滚动
*/
wheelScrollEnabled: boolean;
/**
* 列表滚动方向,默认垂直方向滚动
* 自定义 YXLayout 应该尽量根据这个配置来实现不同方向的布局业务
* 备注: 如果使用的 YXLayout 未支持对应的滚动方向,则此配置不会生效,严格来说这个滚动方向本就应该是由 YXLayout 决定的,定义在这里是为了编辑器配置方便
*/
scrollDirection: YXCollectionView.ScrollDirection;
/**
* 列表单元节点加载模式
*/
mode: YXCollectionView.Mode;
/**
* 预加载模式下每帧加载多少个节点
*/
preloadNodesLimitPerFrame: number;
/**
* 预加载进度
*/
preloadProgress: (current: number, total: number) => void;
/**
* 每多少帧刷新一次可见节点1 表示每帧都刷
*/
frameInterval: number;
/**
* 滚动过程中每多少帧回收一次不可见节点1表示每帧都回收0表示不在滚动过程中回收不可见节点
* @bug 滚动过程中如果实时的回收不可见节点,有时候会收不到 scroll view 的 cancel 事件,导致 scroll view 的滚动状态不会更新 (且收不到滚动结束事件)
* @fix 当这个属性设置为 0 时,只会在 `touch-up` 和 `scroll-ended` 里面回收不可见节点
*/
recycleInterval: number;
/**
* 注册 cell
* 可多次注册不同种类的 cell只要确保 identifier 的唯一性就好
* @param identifier cell 标识符,通过 dequeueReusableCell 获取重用 cell 时,会根据这个值匹配
* @param maker 生成节点,当重用池里没有可用的节点时,会通过这个回调获取节点,需要在这个回调里面生成节点
* @param poolComp (可选) 节点自定义组件,可以通过这个组件跟 NodePool 的重用业务关联起来
*/
registerCell(identifier: string, maker: () => Node, poolComp?: (new (...args: any[]) => YXCollectionViewCell) | string | null): void;
/**
* 注册 supplementary 追加视图,用法跟 registerCell 一样
*/
registerSupplementary(identifier: string, maker: () => Node, poolComp?: (new (...args: any[]) => YXCollectionViewCell) | string | null): void;
/**
* 通过标识符从重用池里取出一个可用的 cell 节点
* @param identifier 注册时候的标识符
*/
dequeueReusableCell(identifier: string): Node;
/**
* 通过标识符从重用池里取出一个可用的 supplementary 节点
* @param identifier 注册时候的标识符
*/
dequeueReusableSupplementary(identifier: string): Node;
/**
* 内容要分几个区展示,默认 1
* 没有分区展示的需求可以不管这个配置
*/
numberOfSections: number | ((collectionView: YXCollectionView) => number);
getNumberOfSections(): number;
/**
* 每个区里要展示多少条内容
*/
numberOfItems: number | ((section: number, collectionView: YXCollectionView) => number);
getNumberOfItems(section: number): number;
/**
* 配置每块内容对应的 UI 节点
* 在这个方法里,需要确定 indexPath 这个位置对应的节点应该是用注册过的哪个类型的 Node 节点,然后通过 dequeueReusableCell 生成对应的 Node
*
* @example
* yourList.cellForItemAt = (indexPath ,collectionView) => {
* let cell = collectionView.dequeueReusableCell(`your identifier`)
* let comp = cell.getComponent(YourCellComp)
* comp.label.string = `${indexPath}`
* return cell
* }
*
* @returns 注意: 不要在这个方法里创建新的节点对象,这个方法返回的 Node必须是通过 dequeueReusableCell 匹配到的 Node
*/
cellForItemAt: (indexPath: YXIndexPath, collectionView: YXCollectionView) => Node;
/**
* 用法跟 cellForItemAt 差不多,此方法内需要通过 dequeueReusableSupplementary 获取 Node 节点
* @param kinds 关于这个字段的具体含义应该根据使用的自定义 layout 决定
*/
supplementaryForItemAt: (indexPath: YXIndexPath, collectionView: YXCollectionView, kinds: string) => Node;
/**
* cell 节点可见状态回调
* 如果同类型的节点大小可能不一样,可以在这里调整子节点的位置
*/
onCellDisplay: (node: Node, indexPath: YXIndexPath, collectionView: YXCollectionView) => void;
onCellEndDisplay: (node: Node, indexPath: YXIndexPath, collectionView: YXCollectionView) => void;
/**
* supplementary 节点可见状态回调
*/
onSupplementaryDisplay: (node: Node, indexPath: YXIndexPath, collectionView: YXCollectionView, kinds: string) => void;
onSupplementaryEndDisplay: (node: Node, indexPath: YXIndexPath, collectionView: YXCollectionView, kinds: string) => void;
/**
* 点击到 cell 节点后执行
*/
onTouchCellAt: (indexPath: YXIndexPath, collectionView: YXCollectionView) => void;
/**
* 点击到 supplementary 节点后执行
*/
onTouchSupplementaryAt: (indexPath: YXIndexPath, collectionView: YXCollectionView, kinds: string) => void;
/**
* 布局规则
*/
layout: YXLayout;
/**
* 获取列表当前的可见范围
*/
getVisibleRect(): math.Rect;
/**
* 通过索引获取指定的可见的 cell 节点
*/
getVisibleCellNode(indexPath: YXIndexPath): Node;
/**
* 通过索引获取指定的可见的 supplementary 节点
*/
getVisibleSupplementaryNode(indexPath: YXIndexPath, kinds: string): Node;
/**
* 获取所有正在显示的 cell 节点
*/
getVisibleCellNodes(): Node[];
/**
* 获取所有正在显示的 supplementary 节点
* @param kinds 可选按种类筛选
*/
getVisibleSupplementaryNodes(kinds?: string): Node[];
/**
* 获取指定节点绑定的布局属性对象
*/
getElementAttributes(node: Node): YXLayoutAttributes;
/**
* 刷新列表数据
*/
reloadData(): void;
/**
* 刷新当前可见节点
* @param force true: 立即刷新; false: 根据设置的刷新帧间隔在合适的时候刷新
*/
markForUpdateVisibleData(force?: boolean): void;
/**
* 滚动到指定节点的位置
* @todo 支持偏移方位,目前固定是按顶部的位置的,有特殊需求的建议直接通过 .scrollView.scrollToOffset() 实现
*/
scrollTo(indexPath: YXIndexPath, timeInSecond?: number, attenuated?: boolean): void;
/**
* 生命周期方法
*/
protected onLoad(): void;
protected onDestroy(): void;
protected update(dt: number): void;
}
export declare namespace YXCollectionView {
/**
* 重定义私有类型
*/
type ScrollDirection = _yx_collection_view_scroll_direction;
type Mode = _yx_collection_view_list_mode;
}
/**
* *****************************************************************************************
* *****************************************************************************************
* 把二分查找的规则抽出来封装一下,继承这个类的布局,默认通过二分查找实现查找业务
* 这种查找规则对数据量很大的有序列表来说相对高效,具体是否使用还是要根据实际排列需求决定
* *****************************************************************************************
* *****************************************************************************************
*
* @deprecated 1.4.0 版本开始,在自定义布局规则的时候暂时不建议继承这个规则了,如何优化查找算法应该全靠开发者根据实际需求自行实现,目前保留这个是为了 flow-layout 使用,后续有更优方案的话可能会删除这部分代码
*/
export declare abstract class YXBinaryLayout extends YXLayout {
/**
* @bug 如果节点大小差距很大,可能会导致计算屏幕内节点时不准确,出现节点不被正确添加到滚动视图上的问题
* @fix 可以通过此属性,追加屏幕显示的节点数量
* 设置这个值会在检查是否可见的节点时,尝试检查更多的可能处于屏幕外的节点,具体设置多少要根据实际情况调试,一般如果都是正常大小的节点,不需要考虑这个配置
* 设置负值会检查所有的节点
*/
extraVisibleCount: number;
layoutAttributesForElementsInRect(rect: math.Rect, collectionView: YXCollectionView): YXLayoutAttributes[];
}
export {};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 581 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 610 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 273 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

80
doc/md/layout.md Normal file
View File

@@ -0,0 +1,80 @@
YXCollectionView 的 layout 属性决定了单元节点在屏幕上的排列方式。
通过 YXLayout 作为布局管理器YXCollectionView 将所有的布局和展示逻辑交给了 YXLayout 来处理。也就是说YXCollectionView 本身不负责具体的布局实现,而是通过将布局职责委托给 YXLayout 来实现布局的完全解耦。
这一设计的最大优势是布局的独立性:你可以针对不同的需求实现不同的布局样式,无论是 TableView、网格布局还是其他任意排列方式都可以通过自定义 YXLayout 来实现。
每种布局都可以独立封装,不同布局之间相互隔离,互不依赖。使用时只需引入对应的布局规则,极大地提高了灵活性和可重用性。而且,由于布局规则是独立设计的,它们还可以很方便地被导出并分享给其他开发者使用。
---
## YXIndexPath
YXIndexPath 代表了索引,常见的列表组件里数据索引一般来说都是直接用整形来定义的 (例如 index: number),但是因为 YXCollectionView 有分区的概念所以是封装了一个对象用来表示节点的位置索引通俗的来说YXIndexPath 表示的是第 section 个区里的第 item 个节点,这个 item 就可以看做是 index只不过表示的是在某个区内的位置
## YXLayoutAttributes
YXLayoutAttributes 用来描述节点的 UI 相关的信息,在自定义布局的时候,需要对应的创建多个 YXLayoutAttributes 对象来描述节点的 UI 信息,假如说列表一共需要展示 100 条内容,那就是需要创建 100 个 YXLayoutAttributes 对象来描述这 100 个节点的位置YXLayoutAttributes 通过关键属性 indexPath 记录这个布局对象对应的是哪个节点,通过 frame 属性记录这个节点实际的 UI 位置,总结来说 YXLayoutAttributes 就是它**表示了第 indexPath 个节点的位置是 frame**
需要注意的是frame 是一个 Rect 类型,同时包含了节点的位置和大小信息,**参考坐标系为左上角原点坐标系**,也就是 origin (0,0) 的位置表示节点紧靠列表左边/上边的位置,举个例子,假如现在需要在列表内以左上角为起点垂直方向排列 3 个大小为 200x100 的节点,不考虑间距边距的情况下,最终的节点位置用 frame 来表示应该为:
```ts
1. (0, 0, 200, 100)
2. (0, 100, 200, 100)
3. (0, 200, 200, 100)
```
如果需要给节点之间加上一个间距 10则最终节点位置用 frame 来表示应该为:
```ts
1. (0, 0, 200, 100)
2. (0, 110, 200, 100)
3. (0, 220, 200, 100)
```
如果还需要给节点加一个左边距 20 的话,则最终节点位置用 frame 来表示应该为:
```ts
1. (20, 0, 200, 100)
2. (20, 110, 200, 100)
3. (20, 220, 200, 100)
```
把上面的例子通过代码实现的话就是:
```ts
// 伪代码
let spacing = 10 // 节点之间间距
let section_left = 20 // 左边距
let itemSize = new math.Size(200, 100) // 节点大小
let attr1 = new YXLayoutAttributes()
attr1.indexPath = new YXIndexPath(0, 0) // 第 0 个区第 0 个节点
attr1.frame = new math.Rect(section_left, 0, itemSize.width, itemSize.height) // 这个节点的位置
let attr2 = new YXLayoutAttributes()
attr2.indexPath = new YXIndexPath(0, 1) // 第 0 个区第 1 个节点
attr2.frame = new math.Rect(section_left, attr1.frame.yMax + spacing, itemSize.width, itemSize.height) // 这个节点的位置
let attr3 = new YXLayoutAttributes()
attr3.indexPath = new YXIndexPath(0, 2) // 第 0 个区第 2 个节点
attr3.frame = new math.Rect(section_left, attr2.frame.yMax + spacing, itemSize.width, itemSize.height) // 这个节点的位置
```
## YXLayout
YXLayout 主要就是负责管理自定义的 YXLayoutAttributes 对象,在 YXLayout 里面无需考虑节点管理,开发者可以放心的定义全部的 YXLayoutAttributes 对象以描述所有的节点位置
可以参考项目里的 table-layout 的实现,了解 YXLayout 的基本工作流程
## table-layout
1. [实现一个类似 TableView 的布局规则 table-layout (了解基本的自定义布局流程)](./table-layout-1.md)
1. [使 table-layout 支持不同高度的节点 (了解如何支持不同大小的单元项)](./table-layout-2.md)
1. [使 table-layout 支持分区配置 (了解组件的分区概念)](./table-layout-3.md)
1. [使 table-layout 支持区头/区尾配置 (简单了解 supplementary 补充视图概念)](./table-layout-4.md)
1. [使 table-layout 支持区头/区尾吸附效果 (了解如何实时更新节点布局属性)](./table-layout-5.md)
1. [table-layout 性能优化 (了解组件的性能缺陷)](./table-layout-6.md)
以上就是 table-layout 完整的实现过程,有兴趣的可以了解一下

83
doc/md/table-layout-1.md Normal file
View File

@@ -0,0 +1,83 @@
基本的实现一个垂直方向排列的布局规则
```ts
export class YXTableLayout extends YXLayout {
/**
* 行高
*/
rowHeight: number = 100
/**
* 内容上边距
*/
top: number = 0
/**
* 内容下边距
*/
bottom: number = 0
/**
* 节点之间间距
*/
spacing: number = 0
prepare(collectionView: YXCollectionView): void {
// 设置列表的滚动方向(这套布局固定为垂直方向滚动)
collectionView.scrollView.horizontal = false
collectionView.scrollView.vertical = true
if (collectionView.scrollDirection === YXCollectionView.ScrollDirection.HORIZONTAL) {
// 由于这套布局规则只支持垂直方向布局,当外部配置了水平方向滚动时这里可以给个警告
warn(`YXTableLayout 仅支持垂直方向排列`)
}
// 获取列表内一共多少数据,这里传的这个 0 表示的区,在目前不支持分区的情况可以先不用考虑这个,后面会说到
let numberOfItems = collectionView.getNumberOfItems(0)
// 清空一下布局属性数组
this.attributes = []
// 获取列表宽度
const contentWidth = collectionView.node.getComponent(UITransform).width
// 声明一个临时变量,用来记录当前所有内容的总高度
let contentHeight = this.top
// 为每条数据对应的生成一个布局属性
for (let item = 0; item < numberOfItems; item++) {
// 创建索引
let indexPath = new YXIndexPath(0, item)
// 通过索引创建一个 cell 节点的布局属性
let attr = YXLayoutAttributes.layoutAttributesForCell(indexPath)
// 确定这个节点的位置
attr.frame.x = 0
attr.frame.width = contentWidth
attr.frame.height = this.rowHeight
attr.frame.y = contentHeight + (item > 0 ? this.spacing : 0)
// 重要: 保存布局属性
this.attributes.push(attr)
// 更新当前内容高度
contentHeight = attr.frame.yMax
}
// 高度补一个底部间距
contentHeight = contentHeight + this.bottom
// 重要: 设置内容区域总大小,只有确定了滚动区域的大小列表才能滚动
this.contentSize = new math.Size(contentWidth, contentHeight)
}
initOffset(collectionView: YXCollectionView): void {
// 列表首次刷新时,调整一下列表的偏移位置
collectionView.scrollView.scrollToTop()
}
}
```

86
doc/md/table-layout-2.md Normal file
View File

@@ -0,0 +1,86 @@
使 table-layout 支持不同高度的节点
```ts
export class YXTableLayout extends YXLayout {
/**
* 行高
*/
rowHeight: number | ((indexPath: YXIndexPath) => number) = 100
/**
* 内容上边距
*/
top: number = 0
/**
* 内容下边距
*/
bottom: number = 0
/**
* 节点之间间距
*/
spacing: number = 0
prepare(collectionView: YXCollectionView): void {
// 设置列表的滚动方向(这套布局固定为垂直方向滚动)
collectionView.scrollView.horizontal = false
collectionView.scrollView.vertical = true
if (collectionView.scrollDirection === YXCollectionView.ScrollDirection.HORIZONTAL) {
// 由于这套布局规则只支持垂直方向布局,当外部配置了水平方向滚动时这里可以给个警告
warn(`YXTableLayout 仅支持垂直方向排列`)
}
// 获取列表内一共多少数据,这里传的这个 0 表示的区,在目前不支持分区的情况可以先不用考虑这个,后面会说到
let numberOfItems = collectionView.getNumberOfItems(0)
// 清空一下布局属性数组
this.attributes = []
// 获取列表宽度
const contentWidth = collectionView.node.getComponent(UITransform).width
// 声明一个临时变量,用来记录当前所有内容的总高度
let contentHeight = this.top
// 为每条数据对应的生成一个布局属性
for (let item = 0; item < numberOfItems; item++) {
// 创建索引
let indexPath = new YXIndexPath(0, item)
// 通过索引创建一个 cell 节点的布局属性
let attr = YXLayoutAttributes.layoutAttributesForCell(indexPath)
// 通过索引获取这个节点的高度
let rowHeight = this.rowHeight instanceof Function ? this.rowHeight(indexPath) : this.rowHeight
// 确定这个节点的位置
attr.frame.x = 0
attr.frame.width = contentWidth
attr.frame.height = rowHeight
attr.frame.y = contentHeight + (item > 0 ? this.spacing : 0)
// 重要: 保存布局属性
this.attributes.push(attr)
// 更新当前内容高度
contentHeight = attr.frame.yMax
}
// 高度补一个底部间距
contentHeight = contentHeight + this.bottom
// 重要: 设置内容区域总大小,只有确定了滚动区域的大小列表才能滚动
this.contentSize = new math.Size(contentWidth, contentHeight)
}
initOffset(collectionView: YXCollectionView): void {
// 列表首次刷新时,调整一下列表的偏移位置
collectionView.scrollView.scrollToTop()
}
}
```

95
doc/md/table-layout-3.md Normal file
View File

@@ -0,0 +1,95 @@
使 table-layout 支持分区配置
```ts
export class YXTableLayout extends YXLayout {
/**
* 行高
*/
rowHeight: number | ((indexPath: YXIndexPath) => number) = 100
/**
* 内容上边距
*/
top: number = 0
/**
* 内容下边距
*/
bottom: number = 0
/**
* 节点之间间距
*/
spacing: number = 0
prepare(collectionView: YXCollectionView): void {
// 设置列表的滚动方向(这套布局固定为垂直方向滚动)
collectionView.scrollView.horizontal = false
collectionView.scrollView.vertical = true
if (collectionView.scrollDirection === YXCollectionView.ScrollDirection.HORIZONTAL) {
// 由于这套布局规则只支持垂直方向布局,当外部配置了水平方向滚动时这里可以给个警告
warn(`YXTableLayout 仅支持垂直方向排列`)
}
// 清空一下布局属性数组
this.attributes = []
// 获取列表宽度
const contentWidth = collectionView.node.getComponent(UITransform).width
// 声明一个临时变量,用来记录当前所有内容的总高度
let contentHeight = 0
// 获取列表一共分多少个区
let numberOfSections = collectionView.getNumberOfSections()
// 为每条数据对应的生成一个布局属性
for (let section = 0; section < numberOfSections; section++) {
// 将 top 配置应用到每个区
contentHeight = contentHeight + this.top
// 获取这个区内的内容数量,注意这里传入的是 section
let numberOfItems = collectionView.getNumberOfItems(section)
for (let item = 0; item < numberOfItems; item++) {
// 创建索引,注意这里的 section 已经改为正确的 section 了
let indexPath = new YXIndexPath(section, item)
// 通过索引创建一个 cell 节点的布局属性
let attr = YXLayoutAttributes.layoutAttributesForCell(indexPath)
// 通过索引获取这个节点的高度
let rowHeight = this.rowHeight instanceof Function ? this.rowHeight(indexPath) : this.rowHeight
// 确定这个节点的位置
attr.frame.x = 0
attr.frame.width = contentWidth
attr.frame.height = rowHeight
attr.frame.y = contentHeight + (item > 0 ? this.spacing : 0)
// 重要: 保存布局属性
this.attributes.push(attr)
// 更新当前内容高度
contentHeight = attr.frame.yMax
}
// 高度补一个底部间距,跟 top 一样,也是应用到每个区
contentHeight = contentHeight + this.bottom
}
// 重要: 设置内容区域总大小,只有确定了滚动区域的大小列表才能滚动
this.contentSize = new math.Size(contentWidth, contentHeight)
}
initOffset(collectionView: YXCollectionView): void {
// 列表首次刷新时,调整一下列表的偏移位置
collectionView.scrollView.scrollToTop()
}
}
```

159
doc/md/table-layout-4.md Normal file
View File

@@ -0,0 +1,159 @@
使 table-layout 支持区头/区尾配置
```ts
enum _yx_table_layout_supplementary_kinds {
HEADER = 'header',
FOOTER = 'footer',
}
export class YXTableLayout extends YXLayout {
/**
* 行高
*/
rowHeight: number | ((indexPath: YXIndexPath) => number) = 100
/**
* 内容上边距
*/
top: number = 0
/**
* 内容下边距
*/
bottom: number = 0
/**
* 节点之间间距
*/
spacing: number = 0
/**
* 区头高度
*/
sectionHeaderHeight: number | ((section: number) => number) = null
/**
* 区尾高度
*/
sectionFooterHeight: number | ((section: number) => number) = null
/**
* 区头/区尾标识
*/
static SupplementaryKinds = _yx_table_layout_supplementary_kinds
prepare(collectionView: YXCollectionView): void {
// 设置列表的滚动方向(这套布局固定为垂直方向滚动)
collectionView.scrollView.horizontal = false
collectionView.scrollView.vertical = true
if (collectionView.scrollDirection === YXCollectionView.ScrollDirection.HORIZONTAL) {
// 由于这套布局规则只支持垂直方向布局,当外部配置了水平方向滚动时这里可以给个警告
warn(`YXTableLayout 仅支持垂直方向排列`)
}
// 清空一下布局属性数组
this.attributes = []
// 获取列表宽度
const contentWidth = collectionView.node.getComponent(UITransform).width
// 声明一个临时变量,用来记录当前所有内容的总高度
let contentHeight = 0
// 获取列表一共分多少个区
let numberOfSections = collectionView.getNumberOfSections()
// 为每条数据对应的生成一个布局属性
for (let section = 0; section < numberOfSections; section++) {
// 创建一个区索引
let sectionIndexPath = new YXIndexPath(section, 0)
// 通过区索引创建一个区头节点布局属性
let sectionHeaderHeight = 0
if (this.sectionHeaderHeight) {
sectionHeaderHeight = this.sectionHeaderHeight instanceof Function ? this.sectionHeaderHeight(section) : this.sectionHeaderHeight
}
if (sectionHeaderHeight > 0) {
let headerAttr = YXLayoutAttributes.layoutAttributesForSupplementary(sectionIndexPath, YXTableLayout.SupplementaryKinds.HEADER)
// 确定这个节点的位置
headerAttr.frame.x = 0
headerAttr.frame.width = contentWidth
headerAttr.frame.height = sectionHeaderHeight
headerAttr.frame.y = contentHeight
// 重要: 保存布局属性
this.attributes.push(headerAttr)
// 更新整体内容高度
contentHeight = headerAttr.frame.yMax
}
// 将 top 配置应用到每个区
contentHeight = contentHeight + this.top
// 获取这个区内的内容数量,注意这里传入的是 section
let numberOfItems = collectionView.getNumberOfItems(section)
for (let item = 0; item < numberOfItems; item++) {
// 创建索引,注意这里的 section 已经改为正确的 section 了
let indexPath = new YXIndexPath(section, item)
// 通过索引创建一个 cell 节点的布局属性
let attr = YXLayoutAttributes.layoutAttributesForCell(indexPath)
// 通过索引获取这个节点的高度
let rowHeight = this.rowHeight instanceof Function ? this.rowHeight(indexPath) : this.rowHeight
// 确定这个节点的位置
attr.frame.x = 0
attr.frame.width = contentWidth
attr.frame.height = rowHeight
attr.frame.y = contentHeight + (item > 0 ? this.spacing : 0)
// 重要: 保存布局属性
this.attributes.push(attr)
// 更新当前内容高度
contentHeight = attr.frame.yMax
}
// 高度补一个底部间距,跟 top 一样,也是应用到每个区
contentHeight = contentHeight + this.bottom
// 通过区索引创建一个区尾节点布局属性
let sectionFooterHeight = 0
if (this.sectionFooterHeight) {
sectionFooterHeight = this.sectionFooterHeight instanceof Function ? this.sectionFooterHeight(section) : this.sectionFooterHeight
}
if (sectionFooterHeight > 0) {
let footerAttr = YXLayoutAttributes.layoutAttributesForSupplementary(sectionIndexPath, YXTableLayout.SupplementaryKinds.FOOTER)
// 确定这个节点的位置
footerAttr.frame.x = 0
footerAttr.frame.width = contentWidth
footerAttr.frame.height = sectionFooterHeight
footerAttr.frame.y = contentHeight
// 重要: 保存布局属性
this.attributes.push(footerAttr)
// 更新整体内容高度
contentHeight = footerAttr.frame.yMax
}
}
// 重要: 设置内容区域总大小,只有确定了滚动区域的大小列表才能滚动
this.contentSize = new math.Size(contentWidth, contentHeight)
}
initOffset(collectionView: YXCollectionView): void {
// 列表首次刷新时,调整一下列表的偏移位置
collectionView.scrollView.scrollToTop()
}
}
```

267
doc/md/table-layout-5.md Normal file
View File

@@ -0,0 +1,267 @@
使 table-layout 支持区头/区尾吸附效果
```ts
enum _yx_table_layout_supplementary_kinds {
HEADER = 'header',
FOOTER = 'footer',
}
export class YXTableLayout extends YXLayout {
/**
* 行高
*/
rowHeight: number | ((indexPath: YXIndexPath) => number) = 100
/**
* 内容上边距
*/
top: number = 0
/**
* 内容下边距
*/
bottom: number = 0
/**
* 节点之间间距
*/
spacing: number = 0
/**
* 区头高度
*/
sectionHeaderHeight: number | ((section: number) => number) = null
/**
* 区尾高度
*/
sectionFooterHeight: number | ((section: number) => number) = null
/**
* 钉住 header 的位置 ( header 吸附在列表可见范围内 )
*/
sectionHeadersPinToVisibleBounds: boolean = false
/**
* 钉住 footer 的位置 ( footer 吸附在列表可见范围内 )
*/
sectionFootersPinToVisibleBounds: boolean = false
/**
* 区头/区尾标识
*/
static SupplementaryKinds = _yx_table_layout_supplementary_kinds
protected originalHeaderRect: Map<number, math.Rect> = new Map() // 保存所有 header 的原始位置
protected originalFooterRect: Map<number, math.Rect> = new Map() // 保存所有 footer 的原始位置
prepare(collectionView: YXCollectionView): void {
// 设置列表的滚动方向(这套布局固定为垂直方向滚动)
collectionView.scrollView.horizontal = false
collectionView.scrollView.vertical = true
if (collectionView.scrollDirection === YXCollectionView.ScrollDirection.HORIZONTAL) {
// 由于这套布局规则只支持垂直方向布局,当外部配置了水平方向滚动时这里可以给个警告
warn(`YXTableLayout 仅支持垂直方向排列`)
}
// 清空一下布局属性数组
this.attributes = []
this.originalHeaderRect.clear()
this.originalFooterRect.clear()
// 获取列表宽度
const contentWidth = collectionView.node.getComponent(UITransform).width
// 声明一个临时变量,用来记录当前所有内容的总高度
let contentHeight = 0
// 获取列表一共分多少个区
let numberOfSections = collectionView.getNumberOfSections()
// 为每条数据对应的生成一个布局属性
for (let section = 0; section < numberOfSections; section++) {
// 创建一个区索引
let sectionIndexPath = new YXIndexPath(section, 0)
// 通过区索引创建一个区头节点布局属性
let sectionHeaderHeight = 0
if (this.sectionHeaderHeight) {
sectionHeaderHeight = this.sectionHeaderHeight instanceof Function ? this.sectionHeaderHeight(section) : this.sectionHeaderHeight
}
if (sectionHeaderHeight > 0) {
let headerAttr = YXLayoutAttributes.layoutAttributesForSupplementary(sectionIndexPath, YXTableLayout.SupplementaryKinds.HEADER)
// 确定这个节点的位置
headerAttr.frame.x = 0
headerAttr.frame.width = contentWidth
headerAttr.frame.height = sectionHeaderHeight
headerAttr.frame.y = contentHeight
// 调整层级
headerAttr.zIndex = 1
// 重要: 保存布局属性
this.attributes.push(headerAttr)
this.originalHeaderRect.set(section, headerAttr.frame.clone())
// 更新整体内容高度
contentHeight = headerAttr.frame.yMax
}
// 将 top 配置应用到每个区
contentHeight = contentHeight + this.top
// 获取这个区内的内容数量,注意这里传入的是 section
let numberOfItems = collectionView.getNumberOfItems(section)
for (let item = 0; item < numberOfItems; item++) {
// 创建索引,注意这里的 section 已经改为正确的 section 了
let indexPath = new YXIndexPath(section, item)
// 通过索引创建一个 cell 节点的布局属性
let attr = YXLayoutAttributes.layoutAttributesForCell(indexPath)
// 通过索引获取这个节点的高度
let rowHeight = this.rowHeight instanceof Function ? this.rowHeight(indexPath) : this.rowHeight
// 确定这个节点的位置
attr.frame.x = 0
attr.frame.width = contentWidth
attr.frame.height = rowHeight
attr.frame.y = contentHeight + (item > 0 ? this.spacing : 0)
// 重要: 保存布局属性
this.attributes.push(attr)
// 更新当前内容高度
contentHeight = attr.frame.yMax
}
// 高度补一个底部间距,跟 top 一样,也是应用到每个区
contentHeight = contentHeight + this.bottom
// 通过区索引创建一个区尾节点布局属性
let sectionFooterHeight = 0
if (this.sectionFooterHeight) {
sectionFooterHeight = this.sectionFooterHeight instanceof Function ? this.sectionFooterHeight(section) : this.sectionFooterHeight
}
if (sectionFooterHeight > 0) {
let footerAttr = YXLayoutAttributes.layoutAttributesForSupplementary(sectionIndexPath, YXTableLayout.SupplementaryKinds.FOOTER)
// 确定这个节点的位置
footerAttr.frame.x = 0
footerAttr.frame.width = contentWidth
footerAttr.frame.height = sectionFooterHeight
footerAttr.frame.y = contentHeight
// 调整层级
footerAttr.zIndex = 1
// 重要: 保存布局属性
this.attributes.push(footerAttr)
this.originalFooterRect.set(section, footerAttr.frame.clone())
// 更新整体内容高度
contentHeight = footerAttr.frame.yMax
}
}
// 重要: 设置内容区域总大小,只有确定了滚动区域的大小列表才能滚动
this.contentSize = new math.Size(contentWidth, contentHeight)
}
initOffset(collectionView: YXCollectionView): void {
// 列表首次刷新时,调整一下列表的偏移位置
collectionView.scrollView.scrollToTop()
}
layoutAttributesForElementsInRect(rect: math.Rect, collectionView: YXCollectionView): YXLayoutAttributes[] {
let numberOfSections = collectionView.getNumberOfSections()
let scrollOffset = collectionView.scrollView.getScrollOffset()
for (let index = 0; index < this.attributes.length; index++) {
const element = this.attributes[index];
if (element.elementCategory === 'Supplementary') {
if (this.sectionHeadersPinToVisibleBounds && element.supplementaryKinds === YXTableLayout.SupplementaryKinds.HEADER) {
const originalFrame = this.originalHeaderRect.get(element.indexPath.section)
element.frame.y = originalFrame.y
if (scrollOffset.y > originalFrame.y) {
element.frame.y = scrollOffset.y
}
const nextOriginalFrame = this.getNextOriginalFrame(element.indexPath.section, YXTableLayout.SupplementaryKinds.FOOTER, numberOfSections)
if (nextOriginalFrame) {
if (element.frame.yMax > nextOriginalFrame.y) {
element.frame.y = nextOriginalFrame.y - element.frame.height
}
}
}
if (this.sectionFootersPinToVisibleBounds && element.supplementaryKinds === YXTableLayout.SupplementaryKinds.FOOTER) {
let bottom = scrollOffset.y + collectionView.scrollView.view.height
const originalFrame = this.originalFooterRect.get(element.indexPath.section)
const previousOriginalFrame = this.getPreviousOriginalFrame(element.indexPath.section, YXTableLayout.SupplementaryKinds.HEADER)
element.frame.y = originalFrame.y
if (bottom < originalFrame.yMax) {
element.frame.y = bottom - element.frame.height
if (previousOriginalFrame) {
if (element.frame.y < previousOriginalFrame.yMax) {
element.frame.y = previousOriginalFrame.yMax
}
}
}
}
}
}
return this.attributes
}
shouldUpdateAttributesZIndex(): boolean {
return this.sectionHeadersPinToVisibleBounds || this.sectionFootersPinToVisibleBounds
}
shouldUpdateAttributesForBoundsChange(): boolean {
return this.sectionHeadersPinToVisibleBounds || this.sectionFootersPinToVisibleBounds
}
/**
* 获取 `section` 下一个 header 或者 footer 的位置
*/
protected getNextOriginalFrame(section: number, kinds: _yx_table_layout_supplementary_kinds, total: number) {
if (section >= total) { return null }
if (kinds === YXTableLayout.SupplementaryKinds.HEADER) {
let result = this.originalHeaderRect.get(section)
if (result) { return result }
return this.getNextOriginalFrame(section, YXTableLayout.SupplementaryKinds.FOOTER, total)
}
if (kinds === YXTableLayout.SupplementaryKinds.FOOTER) {
let result = this.originalFooterRect.get(section)
if (result) { return result }
return this.getNextOriginalFrame(section + 1, YXTableLayout.SupplementaryKinds.HEADER, total)
}
return null
}
/**
* 获取 `section` 前一个 header 或者 footer 的位置
*/
protected getPreviousOriginalFrame(section: number, kinds: _yx_table_layout_supplementary_kinds) {
if (section < 0) { return null }
if (kinds === YXTableLayout.SupplementaryKinds.HEADER) {
let result = this.originalHeaderRect.get(section)
if (result) { return result }
return this.getPreviousOriginalFrame(section - 1, YXTableLayout.SupplementaryKinds.FOOTER)
}
if (kinds === YXTableLayout.SupplementaryKinds.FOOTER) {
let result = this.originalFooterRect.get(section)
if (result) { return result }
return this.getPreviousOriginalFrame(section, YXTableLayout.SupplementaryKinds.HEADER)
}
return null
}
}
```

354
doc/md/table-layout-6.md Normal file
View File

@@ -0,0 +1,354 @@
通过二分查找优化 table-layout 性能
```ts
enum _yx_table_layout_supplementary_kinds {
HEADER = 'header',
FOOTER = 'footer',
}
export class YXTableLayout extends YXLayout {
/**
* 行高
*/
rowHeight: number | ((indexPath: YXIndexPath) => number) = 100
/**
* 内容上边距
*/
top: number = 0
/**
* 内容下边距
*/
bottom: number = 0
/**
* 节点之间间距
*/
spacing: number = 0
/**
* 区头高度
*/
sectionHeaderHeight: number | ((section: number) => number) = null
/**
* 区尾高度
*/
sectionFooterHeight: number | ((section: number) => number) = null
/**
* 钉住 header 的位置 ( header 吸附在列表可见范围内 )
*/
sectionHeadersPinToVisibleBounds: boolean = false
/**
* 钉住 footer 的位置 ( footer 吸附在列表可见范围内 )
*/
sectionFootersPinToVisibleBounds: boolean = false
/**
* 区头/区尾标识
*/
static SupplementaryKinds = _yx_table_layout_supplementary_kinds
protected originalHeaderRect: Map<number, math.Rect> = new Map() // 保存所有 header 的原始位置
protected originalFooterRect: Map<number, math.Rect> = new Map() // 保存所有 footer 的原始位置
// 为了优化查找,额外维护几个数组按类别管理所有的布局属性,空间换时间
protected allCellAttributes: YXLayoutAttributes[] = []
protected allHeaderAttributes: YXLayoutAttributes[] = []
protected allFooterAttributes: YXLayoutAttributes[] = []
prepare(collectionView: YXCollectionView): void {
// 设置列表的滚动方向(这套布局固定为垂直方向滚动)
collectionView.scrollView.horizontal = false
collectionView.scrollView.vertical = true
if (collectionView.scrollDirection === YXCollectionView.ScrollDirection.HORIZONTAL) {
// 由于这套布局规则只支持垂直方向布局,当外部配置了水平方向滚动时这里可以给个警告
warn(`YXTableLayout 仅支持垂直方向排列`)
}
// 清空一下布局属性数组
this.attributes = []
this.allCellAttributes = []
this.allHeaderAttributes = []
this.allFooterAttributes = []
this.originalHeaderRect.clear()
this.originalFooterRect.clear()
// 获取列表宽度
const contentWidth = collectionView.node.getComponent(UITransform).width
// 声明一个临时变量,用来记录当前所有内容的总高度
let contentHeight = 0
// 获取列表一共分多少个区
let numberOfSections = collectionView.getNumberOfSections()
// 为每条数据对应的生成一个布局属性
for (let section = 0; section < numberOfSections; section++) {
// 创建一个区索引
let sectionIndexPath = new YXIndexPath(section, 0)
// 通过区索引创建一个区头节点布局属性
let sectionHeaderHeight = 0
if (this.sectionHeaderHeight) {
sectionHeaderHeight = this.sectionHeaderHeight instanceof Function ? this.sectionHeaderHeight(section) : this.sectionHeaderHeight
}
if (sectionHeaderHeight > 0) {
let headerAttr = YXLayoutAttributes.layoutAttributesForSupplementary(sectionIndexPath, YXTableLayout.SupplementaryKinds.HEADER)
// 确定这个节点的位置
headerAttr.frame.x = 0
headerAttr.frame.width = contentWidth
headerAttr.frame.height = sectionHeaderHeight
headerAttr.frame.y = contentHeight
// 调整层级
headerAttr.zIndex = 1
// 重要: 保存布局属性
this.attributes.push(headerAttr)
this.originalHeaderRect.set(section, headerAttr.frame.clone())
this.allHeaderAttributes.push(headerAttr)
// 更新整体内容高度
contentHeight = headerAttr.frame.yMax
}
// 将 top 配置应用到每个区
contentHeight = contentHeight + this.top
// 获取这个区内的内容数量,注意这里传入的是 section
let numberOfItems = collectionView.getNumberOfItems(section)
for (let item = 0; item < numberOfItems; item++) {
// 创建索引,注意这里的 section 已经改为正确的 section 了
let indexPath = new YXIndexPath(section, item)
// 通过索引创建一个 cell 节点的布局属性
let attr = YXLayoutAttributes.layoutAttributesForCell(indexPath)
// 通过索引获取这个节点的高度
let rowHeight = this.rowHeight instanceof Function ? this.rowHeight(indexPath) : this.rowHeight
// 确定这个节点的位置
attr.frame.x = 0
attr.frame.width = contentWidth
attr.frame.height = rowHeight
attr.frame.y = contentHeight + (item > 0 ? this.spacing : 0)
// 重要: 保存布局属性
this.attributes.push(attr)
this.allCellAttributes.push(attr)
// 更新当前内容高度
contentHeight = attr.frame.yMax
}
// 高度补一个底部间距,跟 top 一样,也是应用到每个区
contentHeight = contentHeight + this.bottom
// 通过区索引创建一个区尾节点布局属性
let sectionFooterHeight = 0
if (this.sectionFooterHeight) {
sectionFooterHeight = this.sectionFooterHeight instanceof Function ? this.sectionFooterHeight(section) : this.sectionFooterHeight
}
if (sectionFooterHeight > 0) {
let footerAttr = YXLayoutAttributes.layoutAttributesForSupplementary(sectionIndexPath, YXTableLayout.SupplementaryKinds.FOOTER)
// 确定这个节点的位置
footerAttr.frame.x = 0
footerAttr.frame.width = contentWidth
footerAttr.frame.height = sectionFooterHeight
footerAttr.frame.y = contentHeight
// 调整层级
footerAttr.zIndex = 1
// 重要: 保存布局属性
this.attributes.push(footerAttr)
this.originalFooterRect.set(section, footerAttr.frame.clone())
this.allFooterAttributes.push(footerAttr)
// 更新整体内容高度
contentHeight = footerAttr.frame.yMax
}
}
// 重要: 设置内容区域总大小,只有确定了滚动区域的大小列表才能滚动
this.contentSize = new math.Size(contentWidth, contentHeight)
}
initOffset(collectionView: YXCollectionView): void {
// 列表首次刷新时,调整一下列表的偏移位置
collectionView.scrollView.scrollToTop()
}
layoutAttributesForElementsInRect(rect: math.Rect, collectionView: YXCollectionView): YXLayoutAttributes[] {
let result = this.visibleElementsInRect(rect, collectionView)
if (this.sectionHeadersPinToVisibleBounds == false && this.sectionFootersPinToVisibleBounds == false) {
return result // 不需要调整节点位置,直接返回就好
}
let numberOfSections = collectionView.getNumberOfSections()
let scrollOffset = collectionView.scrollView.getScrollOffset()
for (let index = 0; index < result.length; index++) {
const element = result[index];
if (element.elementCategory === 'Supplementary') {
if (this.sectionHeadersPinToVisibleBounds && element.supplementaryKinds === YXTableLayout.SupplementaryKinds.HEADER) {
const originalFrame = this.originalHeaderRect.get(element.indexPath.section)
element.frame.y = originalFrame.y
if (scrollOffset.y > originalFrame.y) {
element.frame.y = scrollOffset.y
}
const nextOriginalFrame = this.getNextOriginalFrame(element.indexPath.section, YXTableLayout.SupplementaryKinds.FOOTER, numberOfSections)
if (nextOriginalFrame) {
if (element.frame.yMax > nextOriginalFrame.y) {
element.frame.y = nextOriginalFrame.y - element.frame.height
}
}
}
if (this.sectionFootersPinToVisibleBounds && element.supplementaryKinds === YXTableLayout.SupplementaryKinds.FOOTER) {
let bottom = scrollOffset.y + collectionView.scrollView.view.height
const originalFrame = this.originalFooterRect.get(element.indexPath.section)
const previousOriginalFrame = this.getPreviousOriginalFrame(element.indexPath.section, YXTableLayout.SupplementaryKinds.HEADER)
element.frame.y = originalFrame.y
if (bottom < originalFrame.yMax) {
element.frame.y = bottom - element.frame.height
if (previousOriginalFrame) {
if (element.frame.y < previousOriginalFrame.yMax) {
element.frame.y = previousOriginalFrame.yMax
}
}
}
}
}
}
return result
}
shouldUpdateAttributesZIndex(): boolean {
return this.sectionHeadersPinToVisibleBounds || this.sectionFootersPinToVisibleBounds
}
shouldUpdateAttributesForBoundsChange(): boolean {
return this.sectionHeadersPinToVisibleBounds || this.sectionFootersPinToVisibleBounds
}
/**
* 获取 `section` 下一个 header 或者 footer 的位置
*/
protected getNextOriginalFrame(section: number, kinds: _yx_table_layout_supplementary_kinds, total: number) {
if (section >= total) { return null }
if (kinds === YXTableLayout.SupplementaryKinds.HEADER) {
let result = this.originalHeaderRect.get(section)
if (result) { return result }
return this.getNextOriginalFrame(section, YXTableLayout.SupplementaryKinds.FOOTER, total)
}
if (kinds === YXTableLayout.SupplementaryKinds.FOOTER) {
let result = this.originalFooterRect.get(section)
if (result) { return result }
return this.getNextOriginalFrame(section + 1, YXTableLayout.SupplementaryKinds.HEADER, total)
}
return null
}
/**
* 获取 `section` 前一个 header 或者 footer 的位置
*/
protected getPreviousOriginalFrame(section: number, kinds: _yx_table_layout_supplementary_kinds) {
if (section < 0) { return null }
if (kinds === YXTableLayout.SupplementaryKinds.HEADER) {
let result = this.originalHeaderRect.get(section)
if (result) { return result }
return this.getPreviousOriginalFrame(section - 1, YXTableLayout.SupplementaryKinds.FOOTER)
}
if (kinds === YXTableLayout.SupplementaryKinds.FOOTER) {
let result = this.originalFooterRect.get(section)
if (result) { return result }
return this.getPreviousOriginalFrame(section, YXTableLayout.SupplementaryKinds.HEADER)
}
return null
}
/**
* 抽出来一个方法用来优化列表性能
* 在优化之前,可以先看一下 @see YXLayout.layoutAttributesForElementsInRect 关于返回值的说明
* 对于有序列表来说,一般都是可以通过二分查找来进行优化
*/
protected visibleElementsInRect(rect: math.Rect, collectionView: YXCollectionView) {
if (this.attributes.length <= 100) { return this.attributes } // 少量数据就不查了,直接返回全部
let result: YXLayoutAttributes[] = []
// header 跟 footer 暂时不考虑,数据相对来说不算很多,直接全部返回
result.push(...this.allHeaderAttributes)
result.push(...this.allFooterAttributes)
// 关于 cell这里用二分查找来优化一下
// 首先通过二分先查出个大概位置
let midIdx = -1
let left = 0
let right = this.allCellAttributes.length - 1
while (left <= right && right >= 0) {
let mid = left + (right - left) / 2
mid = Math.floor(mid)
let attr = this.allCellAttributes[mid]
if (rect.intersects(attr.frame)) {
midIdx = mid
break
}
if (rect.yMax < attr.frame.yMin || rect.xMax < attr.frame.xMin) {
right = mid - 1
} else {
left = mid + 1
}
}
// 二分查找出错了,返回全部的布局属性
if (midIdx < 0) {
return this.attributes
}
// 把模糊查到这个先加进来
result.push(this.allCellAttributes[midIdx])
// 然后依次往前检查,直到超出当前的显示范围
let startIdx = midIdx
while (startIdx > 0) {
let idx = startIdx - 1
let attr = this.allCellAttributes[idx]
if (rect.intersects(attr.frame) == false) {
break
}
result.push(attr)
startIdx = idx
}
// 依次往后检查,直到超出当前的显示范围
let endIdx = midIdx
while (endIdx < this.allCellAttributes.length - 1) {
let idx = endIdx + 1
let attr = this.allCellAttributes[idx]
if (rect.intersects(attr.frame) == false) {
break
}
result.push(attr)
endIdx = idx
}
return result
}
}
```

View File

@@ -1,658 +0,0 @@
[
{
"__type__": "cc.Prefab",
"_name": "page-element",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"persistent": false
},
{
"__type__": "cc.Node",
"_name": "page-element",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [
{
"__id__": 2
},
{
"__id__": 10
},
{
"__id__": 18
}
],
"_active": true,
"_components": [
{
"__id__": 27
},
{
"__id__": 29
}
],
"_prefab": {
"__id__": 31
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "shape",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 3
},
{
"__id__": 5
},
{
"__id__": 7
}
],
"_prefab": {
"__id__": 9
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": {
"__id__": 4
},
"_contentSize": {
"__type__": "cc.Size",
"width": 400,
"height": 1000
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "38Ctl8rrVBIIzUsgoEVl18"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": {
"__id__": 6
},
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 85,
"g": 71,
"b": 56,
"a": 255
},
"_spriteFrame": {
"__uuid__": "7d8f9b89-4fd1-4c9f-a3ab-38ec7cded7ca@f9941",
"__expectedType__": "cc.SpriteFrame"
},
"_type": 0,
"_fillType": 0,
"_sizeMode": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_useGrayscale": false,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "e5z4rNsp5IqKHKYrZmbbGr"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": {
"__id__": 8
},
"_alignFlags": 45,
"_target": null,
"_left": 0,
"_right": 0,
"_top": 0,
"_bottom": 0,
"_horizontalCenter": 0,
"_verticalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 100,
"_originalHeight": 100,
"_alignMode": 1,
"_lockFlags": 45,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "16YuS9Y1RIHL3+RkLAY9ri"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "50E3C8mxhHcLBLSMVIqx2D",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.Node",
"_name": "label",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 11
},
{
"__id__": 13
},
{
"__id__": 15
}
],
"_prefab": {
"__id__": 17
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 454.8,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 10
},
"_enabled": true,
"__prefab": {
"__id__": 12
},
"_contentSize": {
"__type__": "cc.Size",
"width": 63.3837890625,
"height": 50.4
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "227SaOS3lF15buT8rVMsrU"
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 10
},
"_enabled": true,
"__prefab": {
"__id__": 14
},
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_string": "label",
"_horizontalAlign": 1,
"_verticalAlign": 1,
"_actualFontSize": 30,
"_fontSize": 30,
"_fontFamily": "Arial",
"_lineHeight": 40,
"_overflow": 0,
"_enableWrapText": true,
"_font": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_isItalic": false,
"_isBold": false,
"_isUnderline": false,
"_underlineHeight": 2,
"_cacheMode": 0,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "452rD9FHJNEZN1iBdm4Ra3"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 10
},
"_enabled": true,
"__prefab": {
"__id__": 16
},
"_alignFlags": 17,
"_target": null,
"_left": 0,
"_right": 0,
"_top": 20,
"_bottom": 0,
"_horizontalCenter": 0,
"_verticalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_alignMode": 1,
"_lockFlags": 17,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "c4+eUG/NhA7LESiCzTGhbg"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "db55RKuw1JC52K7YOxNE+s",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.Node",
"_name": "list",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 19
},
{
"__id__": 21
},
{
"__id__": 24
}
],
"_prefab": {
"__id__": 26
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": -60,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 18
},
"_enabled": true,
"__prefab": {
"__id__": 20
},
"_contentSize": {
"__type__": "cc.Size",
"width": 400,
"height": 880
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "5dhyHuI65FV7IT7n6wbI2F"
},
{
"__type__": "f94cbxum3xAsomhVNW1piY0",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 18
},
"_enabled": true,
"__prefab": {
"__id__": 22
},
"mask": true,
"scrollEnabled": true,
"wheelScrollEnabled": false,
"scrollDirection": 1,
"mode": 0,
"preloadNodesLimitPerFrame": 2,
"frameInterval": 1,
"recycleInterval": 1,
"autoReloadOnSizeChange": true,
"registerCellForEditor": [
{
"__id__": 23
}
],
"registerSupplementaryForEditor": [],
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "08ri/AdJ1DXbmTgNAS+Z/f"
},
{
"__type__": "_yx_editor_register_element_info",
"prefab": {
"__uuid__": "c8b689a4-ae47-4041-8c9c-7298939e76be",
"__expectedType__": "cc.Prefab"
},
"identifier": "cell",
"comp": ""
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 18
},
"_enabled": true,
"__prefab": {
"__id__": 25
},
"_alignFlags": 45,
"_target": null,
"_left": 0,
"_right": 0,
"_top": 120,
"_bottom": 0,
"_horizontalCenter": 0,
"_verticalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 100,
"_originalHeight": 100,
"_alignMode": 1,
"_lockFlags": 45,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "9faoiM3ilPwZBJ1szRVcqX"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "eaMIqsGr9F+bNhvWAL0QNX",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 28
},
"_contentSize": {
"__type__": "cc.Size",
"width": 400,
"height": 1000
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "65OHSX1lBN0p7gbe3Wj+iU"
},
{
"__type__": "8081ftYWzZM978tGrmRuUfA",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 30
},
"titleLabel": {
"__id__": 13
},
"listComp": {
"__id__": 21
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "62r7cYEdJJ3I7gDFST7oVR"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "aanzQWNlJP9JX9MJIPpZk7",
"instance": null,
"targetOverrides": null
}
]

View File

@@ -1,13 +0,0 @@
{
"ver": "1.1.45",
"importer": "prefab",
"imported": true,
"uuid": "7c5f26c4-f052-40b0-9788-c0e5c4f209b2",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "page-element"
}
}

View File

@@ -1,33 +0,0 @@
import { _decorator, Component, Label, Node } from 'cc';
import { YXCollectionView } from '../lib/yx-collection-view';
import { YXTableLayout } from '../lib/yx-table-layout';
const { ccclass, property } = _decorator;
@ccclass('PageElement')
export class PageElement extends Component {
@property(Label)
titleLabel: Label = null
@property(YXCollectionView)
listComp: YXCollectionView = null
protected start(): void {
this.listComp.numberOfItems = () => {
return 10000
}
this.listComp.cellForItemAt = (indexPath, collectionView) => {
const cell = collectionView.dequeueReusableCell(`cell`)
cell.getChildByName('label').getComponent(Label).string = `${indexPath}`
return cell
}
let layout = new YXTableLayout()
layout.spacing = 10
layout.rowHeight = 100
this.listComp.layout = layout
this.listComp.reloadData()
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "8081fb58-5b36-4cf7-bf2d-1ab991b947c0",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,575 +0,0 @@
[
{
"__type__": "cc.SceneAsset",
"_name": "grid",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"scene": {
"__id__": 1
}
},
{
"__type__": "cc.Scene",
"_name": "grid",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [
{
"__id__": 2
}
],
"_active": true,
"_components": [],
"_prefab": {
"__id__": 13
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"autoReleaseAssets": false,
"_globals": {
"__id__": 14
},
"_id": "85f5e60f-5f3d-42a9-871d-7e695a424d93"
},
{
"__type__": "cc.Node",
"_name": "Canvas",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 3
},
{
"__id__": 5
}
],
"_active": true,
"_components": [
{
"__id__": 9
},
{
"__id__": 10
},
{
"__id__": 11
},
{
"__id__": 12
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 360,
"y": 640,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "beI88Z2HpFELqR4T5EMHpg"
},
{
"__type__": "cc.Node",
"_name": "Camera",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 4
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 1000
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "ebFwiq8gBFaYpqYbdoDODe"
},
{
"__type__": "cc.Camera",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 3
},
"_enabled": true,
"__prefab": null,
"_projection": 0,
"_priority": 0,
"_fov": 45,
"_fovAxis": 0,
"_orthoHeight": 640,
"_near": 0,
"_far": 1000,
"_color": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_depth": 1,
"_stencil": 0,
"_clearFlags": 7,
"_rect": {
"__type__": "cc.Rect",
"x": 0,
"y": 0,
"width": 1,
"height": 1
},
"_aperture": 19,
"_shutter": 7,
"_iso": 0,
"_screenScale": 1,
"_visibility": 1108344832,
"_targetTexture": null,
"_postProcess": null,
"_usePostProcess": false,
"_cameraType": -1,
"_trackingType": 0,
"_id": "63WIch3o5BEYRlXzTT0oWc"
},
{
"__type__": "cc.Node",
"_name": "list",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 6
},
{
"__id__": 7
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "d1/dCc9yNJ44lI4TRGfy4z"
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 5
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 720,
"height": 1280
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "315xpp6rxGVIpwfAByHAu2"
},
{
"__type__": "f94cbxum3xAsomhVNW1piY0",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 5
},
"_enabled": true,
"__prefab": null,
"mask": true,
"scrollEnabled": true,
"wheelScrollEnabled": true,
"scrollDirection": 1,
"mode": 0,
"preloadNodesLimitPerFrame": 2,
"frameInterval": 1,
"recycleInterval": 1,
"autoReloadOnSizeChange": false,
"registerCellForEditor": [
{
"__id__": 8
}
],
"registerSupplementaryForEditor": [],
"_id": "540sP7RuVMr66Fyji3wiJs"
},
{
"__type__": "_yx_editor_register_element_info",
"prefab": {
"__uuid__": "c8b689a4-ae47-4041-8c9c-7298939e76be",
"__expectedType__": "cc.Prefab"
},
"identifier": "cell",
"comp": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 720,
"height": 1280
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "d6rUX5yfhMlKoWX2bSbawx"
},
{
"__type__": "cc.Canvas",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_cameraComponent": {
"__id__": 4
},
"_alignCanvasWithScreen": true,
"_id": "12O/ljcVlEqLmVm3U2gEOQ"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_alignFlags": 45,
"_target": null,
"_left": 0,
"_right": 0,
"_top": 5.684341886080802e-14,
"_bottom": 5.684341886080802e-14,
"_horizontalCenter": 0,
"_verticalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_alignMode": 2,
"_lockFlags": 0,
"_id": "c5V1EV8IpMtrIvY1OE9t2u"
},
{
"__type__": "602edmasWxHMY+0WrUVIhcv",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_id": "597Xe6AAxAUKkZXOTkRnHK"
},
{
"__type__": "cc.PrefabInfo",
"root": null,
"asset": null,
"fileId": "5d2f3c26-c7d2-48bd-bd13-ca5aa20a93c4",
"instance": null,
"targetOverrides": null
},
{
"__type__": "cc.SceneGlobals",
"ambient": {
"__id__": 15
},
"shadows": {
"__id__": 16
},
"_skybox": {
"__id__": 17
},
"fog": {
"__id__": 18
},
"octree": {
"__id__": 19
},
"skin": {
"__id__": 20
},
"lightProbeInfo": {
"__id__": 21
},
"bakedWithStationaryMainLight": false,
"bakedWithHighpLightmap": false
},
{
"__type__": "cc.AmbientInfo",
"_skyColorHDR": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0.520833125
},
"_skyColor": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0.520833125
},
"_skyIllumHDR": 20000,
"_skyIllum": 20000,
"_groundAlbedoHDR": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0
},
"_groundAlbedo": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0
},
"_skyColorLDR": {
"__type__": "cc.Vec4",
"x": 0.2,
"y": 0.5,
"z": 0.8,
"w": 1
},
"_skyIllumLDR": 20000,
"_groundAlbedoLDR": {
"__type__": "cc.Vec4",
"x": 0.2,
"y": 0.2,
"z": 0.2,
"w": 1
}
},
{
"__type__": "cc.ShadowsInfo",
"_enabled": false,
"_type": 0,
"_normal": {
"__type__": "cc.Vec3",
"x": 0,
"y": 1,
"z": 0
},
"_distance": 0,
"_shadowColor": {
"__type__": "cc.Color",
"r": 76,
"g": 76,
"b": 76,
"a": 255
},
"_maxReceived": 4,
"_size": {
"__type__": "cc.Vec2",
"x": 512,
"y": 512
}
},
{
"__type__": "cc.SkyboxInfo",
"_envLightingType": 0,
"_envmapHDR": null,
"_envmap": null,
"_envmapLDR": null,
"_diffuseMapHDR": null,
"_diffuseMapLDR": null,
"_enabled": false,
"_useHDR": true,
"_editableMaterial": null,
"_reflectionHDR": null,
"_reflectionLDR": null,
"_rotationAngle": 0
},
{
"__type__": "cc.FogInfo",
"_type": 0,
"_fogColor": {
"__type__": "cc.Color",
"r": 200,
"g": 200,
"b": 200,
"a": 255
},
"_enabled": false,
"_fogDensity": 0.3,
"_fogStart": 0.5,
"_fogEnd": 300,
"_fogAtten": 5,
"_fogTop": 1.5,
"_fogRange": 1.2,
"_accurate": false
},
{
"__type__": "cc.OctreeInfo",
"_enabled": false,
"_minPos": {
"__type__": "cc.Vec3",
"x": -1024,
"y": -1024,
"z": -1024
},
"_maxPos": {
"__type__": "cc.Vec3",
"x": 1024,
"y": 1024,
"z": 1024
},
"_depth": 8
},
{
"__type__": "cc.SkinInfo",
"_enabled": false,
"_blurRadius": 0.01,
"_sssIntensity": 3
},
{
"__type__": "cc.LightProbeInfo",
"_giScale": 1,
"_giSamples": 1024,
"_bounces": 2,
"_reduceRinging": 0,
"_showProbe": true,
"_showWireframe": true,
"_showConvex": false,
"_data": null,
"_lightProbeSphereVolume": 1
}
]

View File

@@ -1 +0,0 @@
{"ver":"1.1.45","importer":"scene","imported":true,"uuid":"85f5e60f-5f3d-42a9-871d-7e695a424d93","files":[".json"],"subMetas":{},"userData":{}}

View File

@@ -1,30 +0,0 @@
import { _decorator, Component, Label, math, Node } from 'cc';
import { YXCollectionView } from '../lib/yx-collection-view';
import { GridLayout } from '../lib/grid-layout';
const { ccclass, property } = _decorator;
@ccclass('grid')
export class grid extends Component {
protected start(): void {
const listComp = this.node.getChildByName('list').getComponent(YXCollectionView)
listComp.numberOfItems = () => {
return 10000
}
listComp.cellForItemAt = (indexPath, collectionView) => {
const cell = collectionView.dequeueReusableCell(`cell`)
cell.getChildByName('label').getComponent(Label).string = `${indexPath}`
return cell
}
let layout = new GridLayout()
layout.horizontalSpacing = 20
layout.verticalSpacing = 20
layout.itemSize = new math.Size(150, 180)
listComp.layout = layout
listComp.reloadData()
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "602ed99a-b16c-4731-8fb4-5ab51522172f",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -23,7 +23,7 @@
"_active": true, "_active": true,
"_components": [], "_components": [],
"_prefab": { "_prefab": {
"__id__": 13 "__id__": 23
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@@ -54,7 +54,7 @@
}, },
"autoReleaseAssets": false, "autoReleaseAssets": false,
"_globals": { "_globals": {
"__id__": 14 "__id__": 24
}, },
"_id": "5d2f3c26-c7d2-48bd-bd13-ca5aa20a93c4" "_id": "5d2f3c26-c7d2-48bd-bd13-ca5aa20a93c4"
}, },
@@ -72,28 +72,34 @@
}, },
{ {
"__id__": 5 "__id__": 5
},
{
"__id__": 9
},
{
"__id__": 14
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 9 "__id__": 19
}, },
{ {
"__id__": 10 "__id__": 20
}, },
{ {
"__id__": 11 "__id__": 21
}, },
{ {
"__id__": 12 "__id__": 22
} }
], ],
"_prefab": null, "_prefab": null,
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 360, "x": 640,
"y": 640, "y": 360.00000000000006,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -178,7 +184,7 @@
"_priority": 0, "_priority": 0,
"_fov": 45, "_fov": 45,
"_fovAxis": 0, "_fovAxis": 0,
"_orthoHeight": 640, "_orthoHeight": 415.3929539295393,
"_near": 0, "_near": 0,
"_far": 1000, "_far": 1000,
"_color": { "_color": {
@@ -212,7 +218,7 @@
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "list", "_name": "list1",
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"_parent": { "_parent": {
@@ -231,7 +237,7 @@
"_prefab": null, "_prefab": null,
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": -420,
"y": 0, "y": 0,
"z": 0 "z": 0
}, },
@@ -270,8 +276,8 @@
"__prefab": null, "__prefab": null,
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 720, "width": 400,
"height": 1280 "height": 700
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@@ -315,6 +321,242 @@
"identifier": "cell", "identifier": "cell",
"comp": "" "comp": ""
}, },
{
"__type__": "cc.Node",
"_name": "list2",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 10
},
{
"__id__": 11
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "15UUoyfNhFtISYnWUZ/NMT"
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 9
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 400,
"height": 700
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "61HeNMUnxBJ4RjTTIkj7jX"
},
{
"__type__": "f94cbxum3xAsomhVNW1piY0",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 9
},
"_enabled": true,
"__prefab": null,
"mask": true,
"scrollEnabled": true,
"wheelScrollEnabled": true,
"scrollDirection": 1,
"mode": 0,
"preloadNodesLimitPerFrame": 2,
"frameInterval": 1,
"recycleInterval": 1,
"registerCellForEditor": [
{
"__id__": 12
}
],
"registerSupplementaryForEditor": [
{
"__id__": 13
}
],
"_id": "557IDOUVFMgaXUVLj9KNOh"
},
{
"__type__": "_yx_editor_register_element_info",
"prefab": {
"__uuid__": "c8b689a4-ae47-4041-8c9c-7298939e76be",
"__expectedType__": "cc.Prefab"
},
"identifier": "cell",
"comp": ""
},
{
"__type__": "_yx_editor_register_element_info",
"prefab": {
"__uuid__": "c8b689a4-ae47-4041-8c9c-7298939e76be",
"__expectedType__": "cc.Prefab"
},
"identifier": "supplementary",
"comp": ""
},
{
"__type__": "cc.Node",
"_name": "list3",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 15
},
{
"__id__": 16
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 420,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "fdY0keATpIKb8Mxuy2Wwhd"
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 14
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 400,
"height": 700
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "6agiejTfZKQIWskmHSuyHv"
},
{
"__type__": "f94cbxum3xAsomhVNW1piY0",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 14
},
"_enabled": true,
"__prefab": null,
"mask": true,
"scrollEnabled": true,
"wheelScrollEnabled": true,
"scrollDirection": 1,
"mode": 0,
"preloadNodesLimitPerFrame": 2,
"frameInterval": 1,
"recycleInterval": 1,
"registerCellForEditor": [
{
"__id__": 17
}
],
"registerSupplementaryForEditor": [
{
"__id__": 18
}
],
"_id": "e75snCyRxN9KrcOvFeGEnP"
},
{
"__type__": "_yx_editor_register_element_info",
"prefab": {
"__uuid__": "c8b689a4-ae47-4041-8c9c-7298939e76be",
"__expectedType__": "cc.Prefab"
},
"identifier": "cell",
"comp": ""
},
{
"__type__": "_yx_editor_register_element_info",
"prefab": {
"__uuid__": "c8b689a4-ae47-4041-8c9c-7298939e76be",
"__expectedType__": "cc.Prefab"
},
"identifier": "supplementary",
"comp": ""
},
{ {
"__type__": "cc.UITransform", "__type__": "cc.UITransform",
"_name": "", "_name": "",
@@ -327,8 +569,8 @@
"__prefab": null, "__prefab": null,
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 720, "width": 1280,
"height": 1280 "height": 720
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@@ -406,25 +648,25 @@
{ {
"__type__": "cc.SceneGlobals", "__type__": "cc.SceneGlobals",
"ambient": { "ambient": {
"__id__": 15 "__id__": 25
}, },
"shadows": { "shadows": {
"__id__": 16 "__id__": 26
}, },
"_skybox": { "_skybox": {
"__id__": 17 "__id__": 27
}, },
"fog": { "fog": {
"__id__": 18 "__id__": 28
}, },
"octree": { "octree": {
"__id__": 19 "__id__": 29
}, },
"skin": { "skin": {
"__id__": 20 "__id__": 30
}, },
"lightProbeInfo": { "lightProbeInfo": {
"__id__": 21 "__id__": 31
}, },
"bakedWithStationaryMainLight": false, "bakedWithStationaryMainLight": false,
"bakedWithHighpLightmap": false "bakedWithHighpLightmap": false

View File

@@ -6,12 +6,17 @@ const { ccclass, property } = _decorator;
@ccclass('home') @ccclass('home')
export class home extends Component { export class home extends Component {
protected start(): void {
const listComp = this.node.getChildByName('list').getComponent(YXCollectionView)
listComp.numberOfItems = () => { protected start(): void {
return 10000 this.setup_list1()
this.setup_list2()
this.setup_list3()
} }
setup_list1() {
const listComp = this.node.getChildByName('list1').getComponent(YXCollectionView)
listComp.numberOfItems = () => 10000
listComp.cellForItemAt = (indexPath, collectionView) => { listComp.cellForItemAt = (indexPath, collectionView) => {
const cell = collectionView.dequeueReusableCell(`cell`) const cell = collectionView.dequeueReusableCell(`cell`)
cell.getChildByName('label').getComponent(Label).string = `${indexPath}` cell.getChildByName('label').getComponent(Label).string = `${indexPath}`
@@ -25,5 +30,89 @@ export class home extends Component {
listComp.reloadData() listComp.reloadData()
} }
setup_list2() {
const listComp = this.node.getChildByName('list2').getComponent(YXCollectionView)
listComp.numberOfSections = () => 100
listComp.supplementaryForItemAt = (indexPath, collectionView, kinds) => {
if (kinds === YXTableLayout.SupplementaryKinds.HEADER) {
const supplementary = collectionView.dequeueReusableSupplementary('supplementary')
supplementary.getChildByName('label').getComponent(Label).string = `header ${indexPath}`
const shape = supplementary.getChildByName('shape')
shape.getComponent(Sprite).color = new math.Color(100, 100, 150)
return supplementary
}
if (kinds === YXTableLayout.SupplementaryKinds.FOOTER) {
const supplementary = collectionView.dequeueReusableSupplementary('supplementary')
supplementary.getChildByName('label').getComponent(Label).string = `footer ${indexPath}`
const shape = supplementary.getChildByName('shape')
shape.getComponent(Sprite).color = new math.Color(150, 100, 100)
return supplementary
}
return null
}
listComp.numberOfItems = () => 20
listComp.cellForItemAt = (indexPath, collectionView) => {
const cell = collectionView.dequeueReusableCell(`cell`)
cell.getChildByName('label').getComponent(Label).string = `${indexPath}`
return cell
}
let layout = new YXTableLayout()
layout.spacing = 20
layout.top = 20
layout.bottom = 20
layout.rowHeight = 100
layout.sectionHeaderHeight = 120
layout.sectionFooterHeight = 120
listComp.layout = layout
listComp.reloadData()
}
setup_list3() {
const listComp = this.node.getChildByName('list3').getComponent(YXCollectionView)
listComp.numberOfSections = () => 100
listComp.supplementaryForItemAt = (indexPath, collectionView, kinds) => {
if (kinds === YXTableLayout.SupplementaryKinds.HEADER) {
const supplementary = collectionView.dequeueReusableSupplementary('supplementary')
supplementary.getChildByName('label').getComponent(Label).string = `header ${indexPath}`
const shape = supplementary.getChildByName('shape')
shape.getComponent(Sprite).color = new math.Color(100, 100, 150)
return supplementary
}
if (kinds === YXTableLayout.SupplementaryKinds.FOOTER) {
const supplementary = collectionView.dequeueReusableSupplementary('supplementary')
supplementary.getChildByName('label').getComponent(Label).string = `footer ${indexPath}`
const shape = supplementary.getChildByName('shape')
shape.getComponent(Sprite).color = new math.Color(150, 100, 100)
return supplementary
}
return null
}
listComp.numberOfItems = () => 20
listComp.cellForItemAt = (indexPath, collectionView) => {
const cell = collectionView.dequeueReusableCell(`cell`)
cell.getChildByName('label').getComponent(Label).string = `${indexPath}`
return cell
}
let layout = new YXTableLayout()
layout.spacing = 20
layout.top = 20
layout.bottom = 20
layout.rowHeight = 100
layout.sectionHeaderHeight = 120
layout.sectionFooterHeight = 120
layout.sectionHeadersPinToVisibleBounds = true
layout.sectionFootersPinToVisibleBounds = true
listComp.layout = layout
listComp.reloadData()
}
} }

View File

@@ -1,575 +0,0 @@
[
{
"__type__": "cc.SceneAsset",
"_name": "page_view",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"scene": {
"__id__": 1
}
},
{
"__type__": "cc.Scene",
"_name": "page_view",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [
{
"__id__": 2
}
],
"_active": true,
"_components": [],
"_prefab": {
"__id__": 13
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"autoReleaseAssets": false,
"_globals": {
"__id__": 14
},
"_id": "aab8c0ca-1eba-412f-a30c-b2d7e17dcb86"
},
{
"__type__": "cc.Node",
"_name": "Canvas",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 3
},
{
"__id__": 5
}
],
"_active": true,
"_components": [
{
"__id__": 9
},
{
"__id__": 10
},
{
"__id__": 11
},
{
"__id__": 12
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 360,
"y": 640,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "beI88Z2HpFELqR4T5EMHpg"
},
{
"__type__": "cc.Node",
"_name": "Camera",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 4
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 1000
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "ebFwiq8gBFaYpqYbdoDODe"
},
{
"__type__": "cc.Camera",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 3
},
"_enabled": true,
"__prefab": null,
"_projection": 0,
"_priority": 0,
"_fov": 45,
"_fovAxis": 0,
"_orthoHeight": 640,
"_near": 0,
"_far": 1000,
"_color": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_depth": 1,
"_stencil": 0,
"_clearFlags": 7,
"_rect": {
"__type__": "cc.Rect",
"x": 0,
"y": 0,
"width": 1,
"height": 1
},
"_aperture": 19,
"_shutter": 7,
"_iso": 0,
"_screenScale": 1,
"_visibility": 1108344832,
"_targetTexture": null,
"_postProcess": null,
"_usePostProcess": false,
"_cameraType": -1,
"_trackingType": 0,
"_id": "63WIch3o5BEYRlXzTT0oWc"
},
{
"__type__": "cc.Node",
"_name": "list",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 6
},
{
"__id__": 7
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "d1/dCc9yNJ44lI4TRGfy4z"
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 5
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 720,
"height": 1280
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "315xpp6rxGVIpwfAByHAu2"
},
{
"__type__": "f94cbxum3xAsomhVNW1piY0",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 5
},
"_enabled": true,
"__prefab": null,
"mask": true,
"scrollEnabled": true,
"wheelScrollEnabled": false,
"scrollDirection": 1,
"mode": 0,
"preloadNodesLimitPerFrame": 2,
"frameInterval": 1,
"recycleInterval": 1,
"autoReloadOnSizeChange": false,
"registerCellForEditor": [
{
"__id__": 8
}
],
"registerSupplementaryForEditor": [],
"_id": "540sP7RuVMr66Fyji3wiJs"
},
{
"__type__": "_yx_editor_register_element_info",
"prefab": {
"__uuid__": "c8b689a4-ae47-4041-8c9c-7298939e76be",
"__expectedType__": "cc.Prefab"
},
"identifier": "cell",
"comp": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 720,
"height": 1280
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "d6rUX5yfhMlKoWX2bSbawx"
},
{
"__type__": "cc.Canvas",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_cameraComponent": {
"__id__": 4
},
"_alignCanvasWithScreen": true,
"_id": "12O/ljcVlEqLmVm3U2gEOQ"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_alignFlags": 45,
"_target": null,
"_left": 0,
"_right": 0,
"_top": 5.684341886080802e-14,
"_bottom": 5.684341886080802e-14,
"_horizontalCenter": 0,
"_verticalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_alignMode": 2,
"_lockFlags": 0,
"_id": "c5V1EV8IpMtrIvY1OE9t2u"
},
{
"__type__": "719d9iNbZlKorsUoOM5YPll",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_id": "e1zHsjFPZAZ7M4IJ47yFyu"
},
{
"__type__": "cc.PrefabInfo",
"root": null,
"asset": null,
"fileId": "5d2f3c26-c7d2-48bd-bd13-ca5aa20a93c4",
"instance": null,
"targetOverrides": null
},
{
"__type__": "cc.SceneGlobals",
"ambient": {
"__id__": 15
},
"shadows": {
"__id__": 16
},
"_skybox": {
"__id__": 17
},
"fog": {
"__id__": 18
},
"octree": {
"__id__": 19
},
"skin": {
"__id__": 20
},
"lightProbeInfo": {
"__id__": 21
},
"bakedWithStationaryMainLight": false,
"bakedWithHighpLightmap": false
},
{
"__type__": "cc.AmbientInfo",
"_skyColorHDR": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0.520833125
},
"_skyColor": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0.520833125
},
"_skyIllumHDR": 20000,
"_skyIllum": 20000,
"_groundAlbedoHDR": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0
},
"_groundAlbedo": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0
},
"_skyColorLDR": {
"__type__": "cc.Vec4",
"x": 0.2,
"y": 0.5,
"z": 0.8,
"w": 1
},
"_skyIllumLDR": 20000,
"_groundAlbedoLDR": {
"__type__": "cc.Vec4",
"x": 0.2,
"y": 0.2,
"z": 0.2,
"w": 1
}
},
{
"__type__": "cc.ShadowsInfo",
"_enabled": false,
"_type": 0,
"_normal": {
"__type__": "cc.Vec3",
"x": 0,
"y": 1,
"z": 0
},
"_distance": 0,
"_shadowColor": {
"__type__": "cc.Color",
"r": 76,
"g": 76,
"b": 76,
"a": 255
},
"_maxReceived": 4,
"_size": {
"__type__": "cc.Vec2",
"x": 512,
"y": 512
}
},
{
"__type__": "cc.SkyboxInfo",
"_envLightingType": 0,
"_envmapHDR": null,
"_envmap": null,
"_envmapLDR": null,
"_diffuseMapHDR": null,
"_diffuseMapLDR": null,
"_enabled": false,
"_useHDR": true,
"_editableMaterial": null,
"_reflectionHDR": null,
"_reflectionLDR": null,
"_rotationAngle": 0
},
{
"__type__": "cc.FogInfo",
"_type": 0,
"_fogColor": {
"__type__": "cc.Color",
"r": 200,
"g": 200,
"b": 200,
"a": 255
},
"_enabled": false,
"_fogDensity": 0.3,
"_fogStart": 0.5,
"_fogEnd": 300,
"_fogAtten": 5,
"_fogTop": 1.5,
"_fogRange": 1.2,
"_accurate": false
},
{
"__type__": "cc.OctreeInfo",
"_enabled": false,
"_minPos": {
"__type__": "cc.Vec3",
"x": -1024,
"y": -1024,
"z": -1024
},
"_maxPos": {
"__type__": "cc.Vec3",
"x": 1024,
"y": 1024,
"z": 1024
},
"_depth": 8
},
{
"__type__": "cc.SkinInfo",
"_enabled": false,
"_blurRadius": 0.01,
"_sssIntensity": 3
},
{
"__type__": "cc.LightProbeInfo",
"_giScale": 1,
"_giSamples": 1024,
"_bounces": 2,
"_reduceRinging": 0,
"_showProbe": true,
"_showWireframe": true,
"_showConvex": false,
"_data": null,
"_lightProbeSphereVolume": 1
}
]

View File

@@ -1 +0,0 @@
{"ver":"1.1.45","importer":"scene","imported":true,"uuid":"aab8c0ca-1eba-412f-a30c-b2d7e17dcb86","files":[".json"],"subMetas":{},"userData":{}}

View File

@@ -1,31 +0,0 @@
import { _decorator, Component, Label } from 'cc';
import { YXCollectionView } from '../lib/yx-collection-view';
import { PageLayout } from '../lib/page-layout';
const { ccclass, property } = _decorator;
@ccclass('page_view')
export class page_view extends Component {
protected start(): void {
const listComp = this.node.getChildByName('list').getComponent(YXCollectionView)
listComp.recycleInterval = 0
listComp.ignoreScrollEndedDuringAutoScroll = true
listComp.numberOfItems = () => {
return 3
}
listComp.cellForItemAt = (indexPath, collectionView) => {
let index = indexPath.row % 3
const cell = collectionView.dequeueReusableCell(`cell`)
cell.getChildByName('label').getComponent(Label).string = `左右滑动切换页面` + `\n` + `当前页面: ` + `${index}`
return cell
}
let layout = new PageLayout()
// 这个属性用来控制是否循环滚动
layout.loop = true
listComp.layout = layout
listComp.reloadData()
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "719d988d-6d99-4aa2-bb14-a0e33960f965",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,575 +0,0 @@
[
{
"__type__": "cc.SceneAsset",
"_name": "table",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"scene": {
"__id__": 1
}
},
{
"__type__": "cc.Scene",
"_name": "table",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [
{
"__id__": 2
}
],
"_active": true,
"_components": [],
"_prefab": {
"__id__": 13
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"autoReleaseAssets": false,
"_globals": {
"__id__": 14
},
"_id": "61cb8dbb-56d2-403e-a035-5385b6ddaf2b"
},
{
"__type__": "cc.Node",
"_name": "Canvas",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 3
},
{
"__id__": 5
}
],
"_active": true,
"_components": [
{
"__id__": 9
},
{
"__id__": 10
},
{
"__id__": 11
},
{
"__id__": 12
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 360,
"y": 640,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "beI88Z2HpFELqR4T5EMHpg"
},
{
"__type__": "cc.Node",
"_name": "Camera",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 4
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 1000
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "ebFwiq8gBFaYpqYbdoDODe"
},
{
"__type__": "cc.Camera",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 3
},
"_enabled": true,
"__prefab": null,
"_projection": 0,
"_priority": 0,
"_fov": 45,
"_fovAxis": 0,
"_orthoHeight": 640,
"_near": 0,
"_far": 1000,
"_color": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_depth": 1,
"_stencil": 0,
"_clearFlags": 7,
"_rect": {
"__type__": "cc.Rect",
"x": 0,
"y": 0,
"width": 1,
"height": 1
},
"_aperture": 19,
"_shutter": 7,
"_iso": 0,
"_screenScale": 1,
"_visibility": 1108344832,
"_targetTexture": null,
"_postProcess": null,
"_usePostProcess": false,
"_cameraType": -1,
"_trackingType": 0,
"_id": "63WIch3o5BEYRlXzTT0oWc"
},
{
"__type__": "cc.Node",
"_name": "list",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 6
},
{
"__id__": 7
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "d1/dCc9yNJ44lI4TRGfy4z"
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 5
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 720,
"height": 1280
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "315xpp6rxGVIpwfAByHAu2"
},
{
"__type__": "f94cbxum3xAsomhVNW1piY0",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 5
},
"_enabled": true,
"__prefab": null,
"mask": true,
"scrollEnabled": true,
"wheelScrollEnabled": true,
"scrollDirection": 1,
"mode": 0,
"preloadNodesLimitPerFrame": 2,
"frameInterval": 1,
"recycleInterval": 1,
"autoReloadOnSizeChange": false,
"registerCellForEditor": [
{
"__id__": 8
}
],
"registerSupplementaryForEditor": [],
"_id": "540sP7RuVMr66Fyji3wiJs"
},
{
"__type__": "_yx_editor_register_element_info",
"prefab": {
"__uuid__": "c8b689a4-ae47-4041-8c9c-7298939e76be",
"__expectedType__": "cc.Prefab"
},
"identifier": "cell",
"comp": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 720,
"height": 1280
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "d6rUX5yfhMlKoWX2bSbawx"
},
{
"__type__": "cc.Canvas",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_cameraComponent": {
"__id__": 4
},
"_alignCanvasWithScreen": true,
"_id": "12O/ljcVlEqLmVm3U2gEOQ"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_alignFlags": 45,
"_target": null,
"_left": 0,
"_right": 0,
"_top": 5.684341886080802e-14,
"_bottom": 5.684341886080802e-14,
"_horizontalCenter": 0,
"_verticalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_alignMode": 2,
"_lockFlags": 0,
"_id": "c5V1EV8IpMtrIvY1OE9t2u"
},
{
"__type__": "5cd4ePkznBAh4rxIlprB3Bf",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_id": "8e9RdBC9VF6ZvCDMCSULSb"
},
{
"__type__": "cc.PrefabInfo",
"root": null,
"asset": null,
"fileId": "5d2f3c26-c7d2-48bd-bd13-ca5aa20a93c4",
"instance": null,
"targetOverrides": null
},
{
"__type__": "cc.SceneGlobals",
"ambient": {
"__id__": 15
},
"shadows": {
"__id__": 16
},
"_skybox": {
"__id__": 17
},
"fog": {
"__id__": 18
},
"octree": {
"__id__": 19
},
"skin": {
"__id__": 20
},
"lightProbeInfo": {
"__id__": 21
},
"bakedWithStationaryMainLight": false,
"bakedWithHighpLightmap": false
},
{
"__type__": "cc.AmbientInfo",
"_skyColorHDR": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0.520833125
},
"_skyColor": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0.520833125
},
"_skyIllumHDR": 20000,
"_skyIllum": 20000,
"_groundAlbedoHDR": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0
},
"_groundAlbedo": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0
},
"_skyColorLDR": {
"__type__": "cc.Vec4",
"x": 0.2,
"y": 0.5,
"z": 0.8,
"w": 1
},
"_skyIllumLDR": 20000,
"_groundAlbedoLDR": {
"__type__": "cc.Vec4",
"x": 0.2,
"y": 0.2,
"z": 0.2,
"w": 1
}
},
{
"__type__": "cc.ShadowsInfo",
"_enabled": false,
"_type": 0,
"_normal": {
"__type__": "cc.Vec3",
"x": 0,
"y": 1,
"z": 0
},
"_distance": 0,
"_shadowColor": {
"__type__": "cc.Color",
"r": 76,
"g": 76,
"b": 76,
"a": 255
},
"_maxReceived": 4,
"_size": {
"__type__": "cc.Vec2",
"x": 512,
"y": 512
}
},
{
"__type__": "cc.SkyboxInfo",
"_envLightingType": 0,
"_envmapHDR": null,
"_envmap": null,
"_envmapLDR": null,
"_diffuseMapHDR": null,
"_diffuseMapLDR": null,
"_enabled": false,
"_useHDR": true,
"_editableMaterial": null,
"_reflectionHDR": null,
"_reflectionLDR": null,
"_rotationAngle": 0
},
{
"__type__": "cc.FogInfo",
"_type": 0,
"_fogColor": {
"__type__": "cc.Color",
"r": 200,
"g": 200,
"b": 200,
"a": 255
},
"_enabled": false,
"_fogDensity": 0.3,
"_fogStart": 0.5,
"_fogEnd": 300,
"_fogAtten": 5,
"_fogTop": 1.5,
"_fogRange": 1.2,
"_accurate": false
},
{
"__type__": "cc.OctreeInfo",
"_enabled": false,
"_minPos": {
"__type__": "cc.Vec3",
"x": -1024,
"y": -1024,
"z": -1024
},
"_maxPos": {
"__type__": "cc.Vec3",
"x": 1024,
"y": 1024,
"z": 1024
},
"_depth": 8
},
{
"__type__": "cc.SkinInfo",
"_enabled": false,
"_blurRadius": 0.01,
"_sssIntensity": 3
},
{
"__type__": "cc.LightProbeInfo",
"_giScale": 1,
"_giSamples": 1024,
"_bounces": 2,
"_reduceRinging": 0,
"_showProbe": true,
"_showWireframe": true,
"_showConvex": false,
"_data": null,
"_lightProbeSphereVolume": 1
}
]

View File

@@ -1 +0,0 @@
{"ver":"1.1.45","importer":"scene","imported":true,"uuid":"61cb8dbb-56d2-403e-a035-5385b6ddaf2b","files":[".json"],"subMetas":{},"userData":{}}

View File

@@ -1,29 +0,0 @@
import { _decorator, Component, Label, Node } from 'cc';
import { YXCollectionView } from '../lib/yx-collection-view';
import { YXTableLayout } from '../lib/yx-table-layout';
const { ccclass, property } = _decorator;
@ccclass('table')
export class table extends Component {
protected start(): void {
const listComp = this.node.getChildByName('list').getComponent(YXCollectionView)
listComp.numberOfItems = () => {
return 10000
}
listComp.cellForItemAt = (indexPath, collectionView) => {
const cell = collectionView.dequeueReusableCell(`cell`)
cell.getChildByName('label').getComponent(Label).string = `${indexPath}`
return cell
}
let layout = new YXTableLayout()
layout.spacing = 10
layout.rowHeight = 120
listComp.layout = layout
listComp.reloadData()
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "5cd4e3e4-ce70-4087-8af1-225a6b07705f",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,575 +0,0 @@
[
{
"__type__": "cc.SceneAsset",
"_name": "table_anyheight",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"scene": {
"__id__": 1
}
},
{
"__type__": "cc.Scene",
"_name": "table_anyheight",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [
{
"__id__": 2
}
],
"_active": true,
"_components": [],
"_prefab": {
"__id__": 13
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"autoReleaseAssets": false,
"_globals": {
"__id__": 14
},
"_id": "2a449616-89aa-4f43-b171-25d08562f375"
},
{
"__type__": "cc.Node",
"_name": "Canvas",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 3
},
{
"__id__": 5
}
],
"_active": true,
"_components": [
{
"__id__": 9
},
{
"__id__": 10
},
{
"__id__": 11
},
{
"__id__": 12
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 360,
"y": 640,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "beI88Z2HpFELqR4T5EMHpg"
},
{
"__type__": "cc.Node",
"_name": "Camera",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 4
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 1000
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "ebFwiq8gBFaYpqYbdoDODe"
},
{
"__type__": "cc.Camera",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 3
},
"_enabled": true,
"__prefab": null,
"_projection": 0,
"_priority": 0,
"_fov": 45,
"_fovAxis": 0,
"_orthoHeight": 640,
"_near": 0,
"_far": 1000,
"_color": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_depth": 1,
"_stencil": 0,
"_clearFlags": 7,
"_rect": {
"__type__": "cc.Rect",
"x": 0,
"y": 0,
"width": 1,
"height": 1
},
"_aperture": 19,
"_shutter": 7,
"_iso": 0,
"_screenScale": 1,
"_visibility": 1108344832,
"_targetTexture": null,
"_postProcess": null,
"_usePostProcess": false,
"_cameraType": -1,
"_trackingType": 0,
"_id": "63WIch3o5BEYRlXzTT0oWc"
},
{
"__type__": "cc.Node",
"_name": "list",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 6
},
{
"__id__": 7
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "d1/dCc9yNJ44lI4TRGfy4z"
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 5
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 720,
"height": 1280
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "315xpp6rxGVIpwfAByHAu2"
},
{
"__type__": "f94cbxum3xAsomhVNW1piY0",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 5
},
"_enabled": true,
"__prefab": null,
"mask": true,
"scrollEnabled": true,
"wheelScrollEnabled": true,
"scrollDirection": 1,
"mode": 0,
"preloadNodesLimitPerFrame": 2,
"frameInterval": 1,
"recycleInterval": 1,
"autoReloadOnSizeChange": false,
"registerCellForEditor": [
{
"__id__": 8
}
],
"registerSupplementaryForEditor": [],
"_id": "540sP7RuVMr66Fyji3wiJs"
},
{
"__type__": "_yx_editor_register_element_info",
"prefab": {
"__uuid__": "c8b689a4-ae47-4041-8c9c-7298939e76be",
"__expectedType__": "cc.Prefab"
},
"identifier": "cell",
"comp": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 720,
"height": 1280
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "d6rUX5yfhMlKoWX2bSbawx"
},
{
"__type__": "cc.Canvas",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_cameraComponent": {
"__id__": 4
},
"_alignCanvasWithScreen": true,
"_id": "12O/ljcVlEqLmVm3U2gEOQ"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_alignFlags": 45,
"_target": null,
"_left": 0,
"_right": 0,
"_top": 5.684341886080802e-14,
"_bottom": 5.684341886080802e-14,
"_horizontalCenter": 0,
"_verticalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_alignMode": 2,
"_lockFlags": 0,
"_id": "c5V1EV8IpMtrIvY1OE9t2u"
},
{
"__type__": "5d98avssBZEDJz/71riEpI0",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_id": "92Ya0n3HhBD5ktM9+wUhgB"
},
{
"__type__": "cc.PrefabInfo",
"root": null,
"asset": null,
"fileId": "5d2f3c26-c7d2-48bd-bd13-ca5aa20a93c4",
"instance": null,
"targetOverrides": null
},
{
"__type__": "cc.SceneGlobals",
"ambient": {
"__id__": 15
},
"shadows": {
"__id__": 16
},
"_skybox": {
"__id__": 17
},
"fog": {
"__id__": 18
},
"octree": {
"__id__": 19
},
"skin": {
"__id__": 20
},
"lightProbeInfo": {
"__id__": 21
},
"bakedWithStationaryMainLight": false,
"bakedWithHighpLightmap": false
},
{
"__type__": "cc.AmbientInfo",
"_skyColorHDR": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0.520833125
},
"_skyColor": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0.520833125
},
"_skyIllumHDR": 20000,
"_skyIllum": 20000,
"_groundAlbedoHDR": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0
},
"_groundAlbedo": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0
},
"_skyColorLDR": {
"__type__": "cc.Vec4",
"x": 0.2,
"y": 0.5,
"z": 0.8,
"w": 1
},
"_skyIllumLDR": 20000,
"_groundAlbedoLDR": {
"__type__": "cc.Vec4",
"x": 0.2,
"y": 0.2,
"z": 0.2,
"w": 1
}
},
{
"__type__": "cc.ShadowsInfo",
"_enabled": false,
"_type": 0,
"_normal": {
"__type__": "cc.Vec3",
"x": 0,
"y": 1,
"z": 0
},
"_distance": 0,
"_shadowColor": {
"__type__": "cc.Color",
"r": 76,
"g": 76,
"b": 76,
"a": 255
},
"_maxReceived": 4,
"_size": {
"__type__": "cc.Vec2",
"x": 512,
"y": 512
}
},
{
"__type__": "cc.SkyboxInfo",
"_envLightingType": 0,
"_envmapHDR": null,
"_envmap": null,
"_envmapLDR": null,
"_diffuseMapHDR": null,
"_diffuseMapLDR": null,
"_enabled": false,
"_useHDR": true,
"_editableMaterial": null,
"_reflectionHDR": null,
"_reflectionLDR": null,
"_rotationAngle": 0
},
{
"__type__": "cc.FogInfo",
"_type": 0,
"_fogColor": {
"__type__": "cc.Color",
"r": 200,
"g": 200,
"b": 200,
"a": 255
},
"_enabled": false,
"_fogDensity": 0.3,
"_fogStart": 0.5,
"_fogEnd": 300,
"_fogAtten": 5,
"_fogTop": 1.5,
"_fogRange": 1.2,
"_accurate": false
},
{
"__type__": "cc.OctreeInfo",
"_enabled": false,
"_minPos": {
"__type__": "cc.Vec3",
"x": -1024,
"y": -1024,
"z": -1024
},
"_maxPos": {
"__type__": "cc.Vec3",
"x": 1024,
"y": 1024,
"z": 1024
},
"_depth": 8
},
{
"__type__": "cc.SkinInfo",
"_enabled": false,
"_blurRadius": 0.01,
"_sssIntensity": 3
},
{
"__type__": "cc.LightProbeInfo",
"_giScale": 1,
"_giSamples": 1024,
"_bounces": 2,
"_reduceRinging": 0,
"_showProbe": true,
"_showWireframe": true,
"_showConvex": false,
"_data": null,
"_lightProbeSphereVolume": 1
}
]

View File

@@ -1 +0,0 @@
{"ver":"1.1.45","importer":"scene","imported":true,"uuid":"2a449616-89aa-4f43-b171-25d08562f375","files":[".json"],"subMetas":{},"userData":{}}

View File

@@ -1,32 +0,0 @@
import { _decorator, Component, Label, Node } from 'cc';
import { YXCollectionView } from '../lib/yx-collection-view';
import { YXTableLayout } from '../lib/yx-table-layout';
const { ccclass, property } = _decorator;
@ccclass('table_anyheight')
export class table_anyheight extends Component {
protected start(): void {
const listComp = this.node.getChildByName('list').getComponent(YXCollectionView)
listComp.numberOfItems = () => {
return 10000
}
listComp.cellForItemAt = (indexPath, collectionView) => {
const cell = collectionView.dequeueReusableCell(`cell`)
cell.getChildByName('label').getComponent(Label).string = `${indexPath}`
return cell
}
let layout = new YXTableLayout()
layout.spacing = 10
layout.rowHeight = (indexPath) => {
// 可以根据 `indexPath` 返回实际数据对应的 UI 高度
return (indexPath.row % 2 == 0) ? 120 : 200
}
listComp.layout = layout
listComp.reloadData()
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "5d98abec-b016-440c-9cff-ef5ae2129234",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,575 +0,0 @@
[
{
"__type__": "cc.SceneAsset",
"_name": "table_in_page",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"scene": {
"__id__": 1
}
},
{
"__type__": "cc.Scene",
"_name": "table_in_page",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [
{
"__id__": 2
}
],
"_active": true,
"_components": [],
"_prefab": {
"__id__": 13
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"autoReleaseAssets": false,
"_globals": {
"__id__": 14
},
"_id": "cbfd651a-8d93-4763-bec9-718b1b7cb8c2"
},
{
"__type__": "cc.Node",
"_name": "Canvas",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 3
},
{
"__id__": 5
}
],
"_active": true,
"_components": [
{
"__id__": 9
},
{
"__id__": 10
},
{
"__id__": 11
},
{
"__id__": 12
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 360,
"y": 640,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "beI88Z2HpFELqR4T5EMHpg"
},
{
"__type__": "cc.Node",
"_name": "Camera",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 4
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 1000
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "ebFwiq8gBFaYpqYbdoDODe"
},
{
"__type__": "cc.Camera",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 3
},
"_enabled": true,
"__prefab": null,
"_projection": 0,
"_priority": 0,
"_fov": 45,
"_fovAxis": 0,
"_orthoHeight": 640,
"_near": 0,
"_far": 1000,
"_color": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_depth": 1,
"_stencil": 0,
"_clearFlags": 7,
"_rect": {
"__type__": "cc.Rect",
"x": 0,
"y": 0,
"width": 1,
"height": 1
},
"_aperture": 19,
"_shutter": 7,
"_iso": 0,
"_screenScale": 1,
"_visibility": 1108344832,
"_targetTexture": null,
"_postProcess": null,
"_usePostProcess": false,
"_cameraType": -1,
"_trackingType": 0,
"_id": "63WIch3o5BEYRlXzTT0oWc"
},
{
"__type__": "cc.Node",
"_name": "list",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 6
},
{
"__id__": 7
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "d1/dCc9yNJ44lI4TRGfy4z"
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 5
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 720,
"height": 1280
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "315xpp6rxGVIpwfAByHAu2"
},
{
"__type__": "f94cbxum3xAsomhVNW1piY0",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 5
},
"_enabled": true,
"__prefab": null,
"mask": true,
"scrollEnabled": true,
"wheelScrollEnabled": false,
"scrollDirection": 1,
"mode": 0,
"preloadNodesLimitPerFrame": 2,
"frameInterval": 1,
"recycleInterval": 1,
"autoReloadOnSizeChange": false,
"registerCellForEditor": [
{
"__id__": 8
}
],
"registerSupplementaryForEditor": [],
"_id": "540sP7RuVMr66Fyji3wiJs"
},
{
"__type__": "_yx_editor_register_element_info",
"prefab": {
"__uuid__": "7c5f26c4-f052-40b0-9788-c0e5c4f209b2",
"__expectedType__": "cc.Prefab"
},
"identifier": "cell",
"comp": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 720,
"height": 1280
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "d6rUX5yfhMlKoWX2bSbawx"
},
{
"__type__": "cc.Canvas",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_cameraComponent": {
"__id__": 4
},
"_alignCanvasWithScreen": true,
"_id": "12O/ljcVlEqLmVm3U2gEOQ"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_alignFlags": 45,
"_target": null,
"_left": 0,
"_right": 0,
"_top": 5.684341886080802e-14,
"_bottom": 5.684341886080802e-14,
"_horizontalCenter": 0,
"_verticalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_alignMode": 2,
"_lockFlags": 0,
"_id": "c5V1EV8IpMtrIvY1OE9t2u"
},
{
"__type__": "795d2737txC74uGAQLarTJb",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_id": "7fgnhCa5RCvIntnBknQ5LG"
},
{
"__type__": "cc.PrefabInfo",
"root": null,
"asset": null,
"fileId": "5d2f3c26-c7d2-48bd-bd13-ca5aa20a93c4",
"instance": null,
"targetOverrides": null
},
{
"__type__": "cc.SceneGlobals",
"ambient": {
"__id__": 15
},
"shadows": {
"__id__": 16
},
"_skybox": {
"__id__": 17
},
"fog": {
"__id__": 18
},
"octree": {
"__id__": 19
},
"skin": {
"__id__": 20
},
"lightProbeInfo": {
"__id__": 21
},
"bakedWithStationaryMainLight": false,
"bakedWithHighpLightmap": false
},
{
"__type__": "cc.AmbientInfo",
"_skyColorHDR": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0.520833125
},
"_skyColor": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0.520833125
},
"_skyIllumHDR": 20000,
"_skyIllum": 20000,
"_groundAlbedoHDR": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0
},
"_groundAlbedo": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0
},
"_skyColorLDR": {
"__type__": "cc.Vec4",
"x": 0.2,
"y": 0.5,
"z": 0.8,
"w": 1
},
"_skyIllumLDR": 20000,
"_groundAlbedoLDR": {
"__type__": "cc.Vec4",
"x": 0.2,
"y": 0.2,
"z": 0.2,
"w": 1
}
},
{
"__type__": "cc.ShadowsInfo",
"_enabled": false,
"_type": 0,
"_normal": {
"__type__": "cc.Vec3",
"x": 0,
"y": 1,
"z": 0
},
"_distance": 0,
"_shadowColor": {
"__type__": "cc.Color",
"r": 76,
"g": 76,
"b": 76,
"a": 255
},
"_maxReceived": 4,
"_size": {
"__type__": "cc.Vec2",
"x": 512,
"y": 512
}
},
{
"__type__": "cc.SkyboxInfo",
"_envLightingType": 0,
"_envmapHDR": null,
"_envmap": null,
"_envmapLDR": null,
"_diffuseMapHDR": null,
"_diffuseMapLDR": null,
"_enabled": false,
"_useHDR": true,
"_editableMaterial": null,
"_reflectionHDR": null,
"_reflectionLDR": null,
"_rotationAngle": 0
},
{
"__type__": "cc.FogInfo",
"_type": 0,
"_fogColor": {
"__type__": "cc.Color",
"r": 200,
"g": 200,
"b": 200,
"a": 255
},
"_enabled": false,
"_fogDensity": 0.3,
"_fogStart": 0.5,
"_fogEnd": 300,
"_fogAtten": 5,
"_fogTop": 1.5,
"_fogRange": 1.2,
"_accurate": false
},
{
"__type__": "cc.OctreeInfo",
"_enabled": false,
"_minPos": {
"__type__": "cc.Vec3",
"x": -1024,
"y": -1024,
"z": -1024
},
"_maxPos": {
"__type__": "cc.Vec3",
"x": 1024,
"y": 1024,
"z": 1024
},
"_depth": 8
},
{
"__type__": "cc.SkinInfo",
"_enabled": false,
"_blurRadius": 0.01,
"_sssIntensity": 3
},
{
"__type__": "cc.LightProbeInfo",
"_giScale": 1,
"_giSamples": 1024,
"_bounces": 2,
"_reduceRinging": 0,
"_showProbe": true,
"_showWireframe": true,
"_showConvex": false,
"_data": null,
"_lightProbeSphereVolume": 1
}
]

View File

@@ -1 +0,0 @@
{"ver":"1.1.45","importer":"scene","imported":true,"uuid":"cbfd651a-8d93-4763-bec9-718b1b7cb8c2","files":[".json"],"subMetas":{},"userData":{}}

View File

@@ -1,32 +0,0 @@
import { _decorator, Component, Label } from 'cc';
import { YXCollectionView } from '../lib/yx-collection-view';
import { PageLayout } from '../lib/page-layout';
const { ccclass, property } = _decorator;
@ccclass('table_in_page')
export class table_in_page extends Component {
protected start(): void {
const listComp = this.node.getChildByName('list').getComponent(YXCollectionView)
listComp.recycleInterval = 0
listComp.ignoreScrollEndedDuringAutoScroll = true
listComp.numberOfItems = () => {
return 5
}
listComp.cellForItemAt = (indexPath, collectionView) => {
let index = indexPath.row % 5
const cell = collectionView.dequeueReusableCell(`cell`)
cell.getChildByName('label').getComponent(Label).string = `左右滑动切换页面` + `\n` + `当前页面: ` + `${index}`
return cell
}
let layout = new PageLayout()
// 这个属性用来控制是否循环滚动
layout.loop = false
listComp.layout = layout
listComp.reloadData()
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "795d2ef7-eedc-42ef-8b86-0102daad325b",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,588 +0,0 @@
[
{
"__type__": "cc.SceneAsset",
"_name": "table_sublist",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"scene": {
"__id__": 1
}
},
{
"__type__": "cc.Scene",
"_name": "table_sublist",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [
{
"__id__": 2
}
],
"_active": true,
"_components": [],
"_prefab": {
"__id__": 14
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"autoReleaseAssets": false,
"_globals": {
"__id__": 15
},
"_id": "addde7a9-b10c-4157-83e1-8a53476a6ace"
},
{
"__type__": "cc.Node",
"_name": "Canvas",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 3
},
{
"__id__": 5
}
],
"_active": true,
"_components": [
{
"__id__": 10
},
{
"__id__": 11
},
{
"__id__": 12
},
{
"__id__": 13
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 360,
"y": 640,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "beI88Z2HpFELqR4T5EMHpg"
},
{
"__type__": "cc.Node",
"_name": "Camera",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 4
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 1000
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "ebFwiq8gBFaYpqYbdoDODe"
},
{
"__type__": "cc.Camera",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 3
},
"_enabled": true,
"__prefab": null,
"_projection": 0,
"_priority": 0,
"_fov": 45,
"_fovAxis": 0,
"_orthoHeight": 640,
"_near": 0,
"_far": 1000,
"_color": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_depth": 1,
"_stencil": 0,
"_clearFlags": 7,
"_rect": {
"__type__": "cc.Rect",
"x": 0,
"y": 0,
"width": 1,
"height": 1
},
"_aperture": 19,
"_shutter": 7,
"_iso": 0,
"_screenScale": 1,
"_visibility": 1108344832,
"_targetTexture": null,
"_postProcess": null,
"_usePostProcess": false,
"_cameraType": -1,
"_trackingType": 0,
"_id": "63WIch3o5BEYRlXzTT0oWc"
},
{
"__type__": "cc.Node",
"_name": "list",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 6
},
{
"__id__": 7
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "d1/dCc9yNJ44lI4TRGfy4z"
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 5
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 720,
"height": 1280
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "315xpp6rxGVIpwfAByHAu2"
},
{
"__type__": "f94cbxum3xAsomhVNW1piY0",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 5
},
"_enabled": true,
"__prefab": null,
"mask": true,
"scrollEnabled": true,
"wheelScrollEnabled": true,
"scrollDirection": 1,
"mode": 0,
"preloadNodesLimitPerFrame": 2,
"frameInterval": 1,
"recycleInterval": 1,
"autoReloadOnSizeChange": false,
"registerCellForEditor": [
{
"__id__": 8
}
],
"registerSupplementaryForEditor": [
{
"__id__": 9
}
],
"_id": "540sP7RuVMr66Fyji3wiJs"
},
{
"__type__": "_yx_editor_register_element_info",
"prefab": {
"__uuid__": "c8b689a4-ae47-4041-8c9c-7298939e76be",
"__expectedType__": "cc.Prefab"
},
"identifier": "cell",
"comp": ""
},
{
"__type__": "_yx_editor_register_element_info",
"prefab": {
"__uuid__": "c8b689a4-ae47-4041-8c9c-7298939e76be",
"__expectedType__": "cc.Prefab"
},
"identifier": "header",
"comp": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 720,
"height": 1280
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "d6rUX5yfhMlKoWX2bSbawx"
},
{
"__type__": "cc.Canvas",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_cameraComponent": {
"__id__": 4
},
"_alignCanvasWithScreen": true,
"_id": "12O/ljcVlEqLmVm3U2gEOQ"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_alignFlags": 45,
"_target": null,
"_left": 0,
"_right": 0,
"_top": 5.684341886080802e-14,
"_bottom": 5.684341886080802e-14,
"_horizontalCenter": 0,
"_verticalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_alignMode": 2,
"_lockFlags": 0,
"_id": "c5V1EV8IpMtrIvY1OE9t2u"
},
{
"__type__": "72eebI6ZkpMca5vkdlt7bSx",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_id": "adYAwgxuBG+YQTfpqxP4Xj"
},
{
"__type__": "cc.PrefabInfo",
"root": null,
"asset": null,
"fileId": "5d2f3c26-c7d2-48bd-bd13-ca5aa20a93c4",
"instance": null,
"targetOverrides": null
},
{
"__type__": "cc.SceneGlobals",
"ambient": {
"__id__": 16
},
"shadows": {
"__id__": 17
},
"_skybox": {
"__id__": 18
},
"fog": {
"__id__": 19
},
"octree": {
"__id__": 20
},
"skin": {
"__id__": 21
},
"lightProbeInfo": {
"__id__": 22
},
"bakedWithStationaryMainLight": false,
"bakedWithHighpLightmap": false
},
{
"__type__": "cc.AmbientInfo",
"_skyColorHDR": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0.520833125
},
"_skyColor": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0.520833125
},
"_skyIllumHDR": 20000,
"_skyIllum": 20000,
"_groundAlbedoHDR": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0
},
"_groundAlbedo": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0
},
"_skyColorLDR": {
"__type__": "cc.Vec4",
"x": 0.2,
"y": 0.5,
"z": 0.8,
"w": 1
},
"_skyIllumLDR": 20000,
"_groundAlbedoLDR": {
"__type__": "cc.Vec4",
"x": 0.2,
"y": 0.2,
"z": 0.2,
"w": 1
}
},
{
"__type__": "cc.ShadowsInfo",
"_enabled": false,
"_type": 0,
"_normal": {
"__type__": "cc.Vec3",
"x": 0,
"y": 1,
"z": 0
},
"_distance": 0,
"_shadowColor": {
"__type__": "cc.Color",
"r": 76,
"g": 76,
"b": 76,
"a": 255
},
"_maxReceived": 4,
"_size": {
"__type__": "cc.Vec2",
"x": 512,
"y": 512
}
},
{
"__type__": "cc.SkyboxInfo",
"_envLightingType": 0,
"_envmapHDR": null,
"_envmap": null,
"_envmapLDR": null,
"_diffuseMapHDR": null,
"_diffuseMapLDR": null,
"_enabled": false,
"_useHDR": true,
"_editableMaterial": null,
"_reflectionHDR": null,
"_reflectionLDR": null,
"_rotationAngle": 0
},
{
"__type__": "cc.FogInfo",
"_type": 0,
"_fogColor": {
"__type__": "cc.Color",
"r": 200,
"g": 200,
"b": 200,
"a": 255
},
"_enabled": false,
"_fogDensity": 0.3,
"_fogStart": 0.5,
"_fogEnd": 300,
"_fogAtten": 5,
"_fogTop": 1.5,
"_fogRange": 1.2,
"_accurate": false
},
{
"__type__": "cc.OctreeInfo",
"_enabled": false,
"_minPos": {
"__type__": "cc.Vec3",
"x": -1024,
"y": -1024,
"z": -1024
},
"_maxPos": {
"__type__": "cc.Vec3",
"x": 1024,
"y": 1024,
"z": 1024
},
"_depth": 8
},
{
"__type__": "cc.SkinInfo",
"_enabled": false,
"_blurRadius": 0.01,
"_sssIntensity": 3
},
{
"__type__": "cc.LightProbeInfo",
"_giScale": 1,
"_giSamples": 1024,
"_bounces": 2,
"_reduceRinging": 0,
"_showProbe": true,
"_showWireframe": true,
"_showConvex": false,
"_data": null,
"_lightProbeSphereVolume": 1
}
]

View File

@@ -1 +0,0 @@
{"ver":"1.1.45","importer":"scene","imported":true,"uuid":"addde7a9-b10c-4157-83e1-8a53476a6ace","files":[".json"],"subMetas":{},"userData":{}}

View File

@@ -1,126 +0,0 @@
import { _decorator, Component, Label, math, Node, Sprite } from 'cc';
import { YXCollectionView } from '../lib/yx-collection-view';
import { YXTableLayout } from '../lib/yx-table-layout';
const { ccclass, property } = _decorator;
let __ID__ = 0
const data = [
{
id: __ID__++,
title: "DATA-A",
list: [
{ name: "data-a-1" },
{ name: "data-a-2" },
{ name: "data-a-3" },
{ name: "data-a-4" },
{ name: "data-a-5" },
]
},
{
id: __ID__++,
title: "DATA-B",
list: [
{ name: "data-b-1" },
{ name: "data-b-2" },
{ name: "data-b-3" },
{ name: "data-b-4" },
{ name: "data-b-5" },
]
},
{
id: __ID__++,
title: "DATA-C",
list: [
{ name: "data-c-1" },
{ name: "data-c-2" },
{ name: "data-c-3" },
{ name: "data-c-4" },
{ name: "data-c-5" },
]
},
{
id: __ID__++,
title: "DATA-D",
list: [
{ name: "data-d-1" },
{ name: "data-d-2" },
{ name: "data-d-3" },
{ name: "data-d-4" },
{ name: "data-d-5" },
]
},
{
id: __ID__++,
title: "DATA-E",
list: [
{ name: "data-e-1" },
{ name: "data-e-2" },
{ name: "data-e-3" },
{ name: "data-e-4" },
{ name: "data-e-5" },
]
},
]
@ccclass('table_sublist')
export class table_sublist extends Component {
openIds = new Map<number, boolean>()
protected start(): void {
const listComp = this.node.getChildByName('list').getComponent(YXCollectionView)
listComp.numberOfSections = () => {
return data.length
}
listComp.numberOfItems = (section) => {
let sectionData = data[section]
let isOpen = this.openIds.get(sectionData.id) ?? false
if (isOpen) {
return data[section].list.length
}
return 0
}
listComp.supplementaryForItemAt = (indexPath, collectionView, kinds) => {
let sectionData = data[indexPath.section]
if (kinds === YXTableLayout.SupplementaryKinds.HEADER) {
const header = collectionView.dequeueReusableSupplementary(`header`)
header.getChildByName('label').getComponent(Label).string = sectionData.title + "\n" + "点击展开/收起子列表"
header.getChildByName('shape').getComponent(Sprite).color = new math.Color(100, 100, 200)
return header
}
return null
}
listComp.cellForItemAt = (indexPath, collectionView) => {
let rowData = data[indexPath.section].list[indexPath.row]
const cell = collectionView.dequeueReusableCell(`cell`)
cell.getChildByName('label').getComponent(Label).string = rowData.name
return cell
}
listComp.onTouchSupplementaryAt = (indexPath, collectionView, kinds) => {
let sectionData = data[indexPath.section]
if (kinds === YXTableLayout.SupplementaryKinds.HEADER) {
let isOpen = this.openIds.get(sectionData.id) ?? false
this.openIds.set(sectionData.id, !isOpen) // 取反
collectionView.reloadData()
}
}
let layout = new YXTableLayout()
layout.top = 10
layout.spacing = 10
layout.bottom = 10
layout.rowHeight = 120
layout.sectionHeaderHeight = 150
// 这个属性用来控制 header 是否悬浮
layout.sectionHeadersPinToVisibleBounds = false
listComp.layout = layout
listComp.reloadData()
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "72eeb23a-664a-4c71-ae6f-91d96dedb4b1",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,10 +1,8 @@
import { math, UITransform, warn } from "cc"; import { math, UITransform, warn } from "cc";
import { YXCollectionView, YXIndexPath, YXLayout, YXLayoutAttributes } from "./yx-collection-view"; import { YXCollectionView, YXIndexPath, YXLayout, YXLayoutAttributes } from "./yx-collection-view";
/**
* 网格布局
*/
export class GridLayout extends YXLayout { export class GridLayout extends YXLayout {
/** /**
* 节点大小 * 节点大小
*/ */
@@ -20,24 +18,11 @@ export class GridLayout extends YXLayout {
*/ */
verticalSpacing: number = 0 verticalSpacing: number = 0
/**
* @deprecated contentAlignment
*/
set alignment(value: number) {
this.contentAlignment = value
}
/** /**
* 整体对齐方式 * 整体对齐方式
* 0靠左 1居中 2靠右 * 0靠左 1居中 2靠右
*/ */
contentAlignment: number = 1 alignment: number = 1
/**
* 最后一行元素的对齐方式
* 0靠左 1居中 2靠右 (默认 null靠左)
*/
lastRowAlignment?: number = null
/** /**
* 获取每行最多可以容纳多少个节点 * 获取每行最多可以容纳多少个节点
@@ -79,14 +64,15 @@ export class GridLayout extends YXLayout {
// 计算每行最多可以放多少个节点 // 计算每行最多可以放多少个节点
this._maxItemsPerRow = null this._maxItemsPerRow = null
let num = this.getMaxItemsPerRow(collectionView) let num = this.getMaxItemsPerRow(collectionView)
let maxWidth = (num * this.itemSize.width + (num - 1) * this.horizontalSpacing) // 每行节点需要占用的总宽度
// 根据设置的对齐方式计算左边距 // 根据设置的对齐方式计算左边距
let left = 0 let left = 0
if (this.contentAlignment == 1) { if (this.alignment == 1) {
let maxWidth = (num * this.itemSize.width + (num - 1) * this.horizontalSpacing) // 每行节点总宽度
left = (width - maxWidth) * 0.5 left = (width - maxWidth) * 0.5
} }
if (this.contentAlignment == 2) { if (this.alignment == 2) {
let maxWidth = (num * this.itemSize.width + (num - 1) * this.horizontalSpacing) // 每行节点总宽度
left = width - maxWidth left = width - maxWidth
} }
@@ -94,10 +80,6 @@ export class GridLayout extends YXLayout {
if (numberOfSections > 1) { warn(`GridLayout 暂时不支持分区模式`) } if (numberOfSections > 1) { warn(`GridLayout 暂时不支持分区模式`) }
const numberOfItems = collectionView.getNumberOfItems(0) const numberOfItems = collectionView.getNumberOfItems(0)
// 计算元素一共有多少行
let total = Math.ceil(numberOfItems / num)
// 临时记录最后一行的元素
let lastAttrs: YXLayoutAttributes[] = []
for (let index = 0; index < numberOfItems; index++) { for (let index = 0; index < numberOfItems; index++) {
// 计算这个节点是第几行 // 计算这个节点是第几行
@@ -119,26 +101,6 @@ export class GridLayout extends YXLayout {
// 更新内容高度 // 更新内容高度
contentSize.height = Math.max(contentSize.height, attr.frame.yMax) contentSize.height = Math.max(contentSize.height, attr.frame.yMax)
if (row == total - 1) {
lastAttrs.push(attr)
}
}
// 单独调整最后一行元素的对齐方式
if (this.lastRowAlignment != null) {
let tempLeft = left
if (this.lastRowAlignment == 1) {
tempLeft = left + (maxWidth - this.itemSize.width * lastAttrs.length - this.horizontalSpacing * (lastAttrs.length - 1)) * 0.5
}
if (this.lastRowAlignment == 2) {
tempLeft = left + (maxWidth - this.itemSize.width * lastAttrs.length - this.horizontalSpacing * (lastAttrs.length - 1))
}
for (let index = 0; index < lastAttrs.length; index++) {
const attr = lastAttrs[index]
attr.frame.x = tempLeft
tempLeft = attr.frame.xMax + this.horizontalSpacing
}
} }
this.attributes = attrs this.attributes = attrs
@@ -175,3 +137,4 @@ export class GridLayout extends YXLayout {
return this.attributes.slice(startIdx, endIdx) return this.attributes.slice(startIdx, endIdx)
} }
} }

View File

@@ -1,149 +0,0 @@
import { log, math, warn } from "cc";
import { YXCollectionView, YXIndexPath, YXLayout, YXLayoutAttributes } from "./yx-collection-view";
/**
* PageView 布局
*/
export class PageLayout extends YXLayout {
/**
* 是否开启分页效果
*/
private pagingEnabled: boolean = true
/**
* 分页效果开启时,自动吸附动画时间
*/
pagingAnimationDuration: number = 0.5
/**
* 循环滚动,默认关闭
* 注意: 当开启循环滚动时YXCollectionView 需要额外设置 `recycleInterval = 0`
* 注意: 当开启循环滚动时YXCollectionView 需要额外设置 `ignoreScrollEndedDuringAutoScroll = true`
* 注意: 开启循环滚动会生成较大范围的 `indexPath`,在使用索引的时候需要进行取余处理
*
* @example
* listComp.recycleInterval = 0
* listComp.ignoreScrollEndedDuringAutoScroll = true
* listComp.numberOfItems = () => {
* return <data-length>
* }
* listComp.cellForItemAt = (indexPath, collectionView) => {
* let index = indexPath.row % <data-length> // 通过取余获取真实数据索引
* const cell = collectionView.dequeueReusableCell(`cell`)
* return cell
* }
*/
loop: boolean = false
/**
* 仅开启循环滚动时生效,由于循环滚动是伪循环,如果不间断的朝着某一个方向一直滑是会滑到头的 (就像苹果的闹钟时间可以滑到尽头...)
* 调整这个属性可以放大滚动范围,避免滑动到头穿帮
* 会生成额外的布局属性,建议范围 1 ~ 10默认: 5 (实际情况可以看数据压力,数据不多的话可以设置更大)
*/
scrollRangeMultiplier: number = 5
private get safeScrollRangeMultiplier(): number {
let value = Math.floor(this.scrollRangeMultiplier)
return Math.max(1, value)
}
prepare(collectionView: YXCollectionView): void {
collectionView.scrollView.horizontal = true
collectionView.scrollView.vertical = false
if (collectionView.scrollDirection === YXCollectionView.ScrollDirection.VERTICAL) {
warn(`PageLayout 仅支持水平方向排列`)
}
const numberOfSections = collectionView.getNumberOfSections()
if (numberOfSections > 1) { warn(`GridLayout 暂时不支持分区模式`) }
let contentSize = collectionView.scrollView.view.contentSize.clone()
let attrs = []
let itemSize = collectionView.scrollView.view.contentSize
let numberOfItems = collectionView.getNumberOfItems(0)
if (this.loop) {
numberOfItems = numberOfItems * 3 * this.safeScrollRangeMultiplier
if (collectionView.recycleInterval != 0) {
warn(`PageLayout: 开启循环滚动时建议将 YXCollectionView.recycleInterval 设置为 0`)
}
if (collectionView.ignoreScrollEndedDuringAutoScroll == false) {
warn(`PageLayout: 开启循环滚动时建议将 YXCollectionView.ignoreScrollEndedDuringAutoScroll 设置为 true`)
}
}
for (let index = 0; index < numberOfItems; index++) {
let attr = YXLayoutAttributes.layoutAttributesForCell(new YXIndexPath(0, index))
attr.frame.x = itemSize.width * index
attr.frame.y = 0
attr.frame.width = itemSize.width
attr.frame.height = itemSize.height
attrs.push(attr)
contentSize.width = Math.max(contentSize.width, attr.frame.xMax)
}
this.attributes = attrs
this.contentSize = contentSize
}
initOffset(collectionView: YXCollectionView): void {
if (this.loop) {
let numberOfItems = collectionView.getNumberOfItems(0)
let offset = new math.Vec2()
offset.x = numberOfItems * this.safeScrollRangeMultiplier * collectionView.scrollView.view.width
offset.y = 0
collectionView.scrollView.scrollToOffset(offset, 0)
} else {
collectionView.scrollView.scrollToLeft()
}
}
targetOffset(collectionView: YXCollectionView, touchMoveVelocity: math.Vec3, startOffset: math.Vec2, originTargetOffset: math.Vec2, originScrollDuration: number): { offset: math.Vec2; time?: number; attenuated?: boolean; } | null {
if (this.pagingEnabled == false) {
return null
}
let offset = collectionView.scrollView.getScrollOffset()
offset.x = - offset.x
let threshold = 0.2
let idx = Math.round(offset.x / collectionView.scrollView.view.width)
let r = touchMoveVelocity.x / collectionView.scrollView.view.width
if (startOffset && Math.abs(r) >= threshold) {
idx = Math.round(startOffset.x / collectionView.scrollView.view.width) + (r > 0 ? -1 : 1)
}
offset.x = idx * collectionView.scrollView.view.width
return { offset: offset, time: this.pagingAnimationDuration }
}
layoutAttributesForElementsInRect(rect: math.Rect, collectionView: YXCollectionView): YXLayoutAttributes[] {
if (collectionView.scrollView.view.width <= 0 || this.attributes.length <= 0) {
return super.layoutAttributesForElementsInRect(rect, collectionView)
}
// 直接计算出当前元素位置,另外额外返回左右两边的元素
let result = []
let idx = Math.round(rect.x / collectionView.scrollView.view.width)
let previousIdx = idx - 1
let latterIdx = idx + 1
if (idx >= 0 && idx < this.attributes.length) {
result.push(this.attributes[idx])
}
if (previousIdx >= 0 && previousIdx < this.attributes.length && previousIdx != idx) {
result.push(this.attributes[previousIdx])
}
if (latterIdx >= 0 && latterIdx < this.attributes.length && latterIdx != idx) {
result.push(this.attributes[latterIdx])
}
return result
}
onScrollEnded(collectionView: YXCollectionView): void {
if (this.loop == false) {
return
}
let numberOfItems = collectionView.getNumberOfItems(0)
let offset = collectionView.scrollView.getScrollOffset()
offset.x = - offset.x
let idx = Math.round(offset.x / collectionView.scrollView.view.width) % numberOfItems
offset.x = collectionView.scrollView.view.width * (numberOfItems * this.safeScrollRangeMultiplier + idx)
collectionView.scrollView.scrollToOffset(offset)
// 直接设置滚动位置不会触发刷新,这里强制刷新一下
collectionView.markForUpdateVisibleData(true)
}
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "0b60b98b-e96f-4ced-8e6c-87910ed7b6d1",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,4 +1,4 @@
import { _decorator, Component, Enum, Event, EventMouse, EventTouch, instantiate, Mask, math, Node, NodeEventType, NodePool, Prefab, ScrollView, UIOpacity, UITransform } from 'cc'; import { _decorator, Component, Enum, Event, EventMouse, EventTouch, instantiate, Mask, math, Node, NodeEventType, NodePool, Prefab, ScrollView, UIOpacity, UITransform, Widget } from 'cc';
const { ccclass, property, executionOrder, disallowMultiple, help } = _decorator; const { ccclass, property, executionOrder, disallowMultiple, help } = _decorator;
const _vec3Out = new math.Vec3() const _vec3Out = new math.Vec3()
@@ -115,7 +115,7 @@ class _yx_node_element_comp extends Component {
/** /**
* 私有组件 * 私有组件
* 内部滚动视图组件 * 内部滚动视图组件
* https://github.com/cocos/cocos-engine/blob/v3.8.8/cocos/ui/scroll-view.ts * https://github.com/cocos/cocos-engine/blob/v3.8.0/cocos/ui/scroll-view.ts
*/ */
class _scroll_view extends ScrollView { class _scroll_view extends ScrollView {
@@ -238,15 +238,6 @@ class _scroll_view extends ScrollView {
super._stopPropagationIfTargetIsMe(event) super._stopPropagationIfTargetIsMe(event)
} }
ignoreScrollEndedDuringAutoScroll = false
protected _dispatchEvent(event: string): void {
// 这里非常奇怪,在快速滑动的时候收到了 `SCROLL_ENDED` 但是 `isAutoScrolling` 还是 true感觉不太符合常理看源码似乎是设计如此不清楚是何用意
if (this.ignoreScrollEndedDuringAutoScroll && event === ScrollView.EventType.SCROLL_ENDED as string && this.isAutoScrolling()) {
return
}
super._dispatchEvent(event)
}
/** /**
* 获取本次滑动是要滑动哪个列表 * 获取本次滑动是要滑动哪个列表
*/ */
@@ -303,6 +294,17 @@ class _scroll_view extends ScrollView {
} }
return result return result
} }
set content(value) {
Reflect.set(ScrollView.prototype, 'content', value, this);
if (value) {
value.on(NodeEventType.SIZE_CHANGED, this._calculateBoundary, this);
value.on(NodeEventType.TRANSFORM_CHANGED, this._scaleChanged, this);
}
}
get content() {
return Reflect.get(ScrollView.prototype, 'content', this);
}
} }
class _yx_node_pool extends NodePool { class _yx_node_pool extends NodePool {
@@ -572,7 +574,7 @@ export class YXCollectionView extends Component {
let transform = content.getComponent(UITransform) || content.addComponent(UITransform) let transform = content.getComponent(UITransform) || content.addComponent(UITransform)
transform.contentSize = this.node.getComponent(UITransform).contentSize transform.contentSize = this.node.getComponent(UITransform).contentSize
this.getComponent(Widget)?.updateAlignment?.();
result.content = content result.content = content
} }
@@ -645,31 +647,11 @@ export class YXCollectionView extends Component {
/** /**
* 滚动过程中每多少帧回收一次不可见节点1表示每帧都回收0表示不在滚动过程中回收不可见节点 * 滚动过程中每多少帧回收一次不可见节点1表示每帧都回收0表示不在滚动过程中回收不可见节点
* @bug 滚动过程中如果实时的回收不可见节点,有时候会收不到 scroll view 的 cancel 事件,导致 scroll view 的滚动状态不会更新 (且收不到滚动结束事件) * @bug 滚动过程中如果实时的回收不可见节点,有时候会收不到 scroll view 的 cancel 事件,导致 scroll view 的滚动状态不会更新 (且收不到滚动结束事件)
* @bug 列表滚动时卡住不会正常回弹
* @fix 当这个属性设置为 0 时,只会在 `touch-up` 和 `scroll-ended` 里面回收不可见节点 * @fix 当这个属性设置为 0 时,只会在 `touch-up` 和 `scroll-ended` 里面回收不可见节点
*/ */
@property({ tooltip: `滚动过程中每多少帧回收一次不可见节点1表示每帧都回收0表示不在滚动过程中回收不可见节点` }) @property({ tooltip: `滚动过程中每多少帧回收一次不可见节点1表示每帧都回收0表示不在滚动过程中回收不可见节点` })
recycleInterval: number = 1 recycleInterval: number = 1
/**
* bug?? 还是特性?? 当列表快速滑动的时候会收到 `scroll-ended` 事件,但实际上快速滑动阶段只是手指频繁的松开按下,不应该定性为滚动结束
* 将这个属性设置为 `true` 后不会在快速滑动时发送 `scroll-ended` 事件
* 该属性为实验性的功能,暂时不清楚是否有其他隐患,如果碰到快速滑动行为引发一些奇怪问题时可以尝试修改此属性
*/
set ignoreScrollEndedDuringAutoScroll(value: boolean) {
this._scrollView.ignoreScrollEndedDuringAutoScroll = value
}
get ignoreScrollEndedDuringAutoScroll(): boolean {
return this._scrollView.ignoreScrollEndedDuringAutoScroll
}
/**
* 列表内的元素位置是在 `reloadData` 那一刻决定的,所以当列表有 Widget 组件或者其他一些情况导致列表节点自身大小改变了但子元素的位置未更新
* 打开这个属性会在列表节点自身大小变化时自动重新计算一遍布局信息
*/
@property({ tooltip: `如果列表有 Widget 组件或者希望列表大小改变时自动刷新列表,可以打开此开关` })
autoReloadOnSizeChange: boolean = false
/** /**
* 通过编辑器注册节点类型 * 通过编辑器注册节点类型
*/ */
@@ -756,10 +738,6 @@ export class YXCollectionView extends Component {
let cell = result.getComponent(_yx_node_element_comp) || result.addComponent(_yx_node_element_comp) let cell = result.getComponent(_yx_node_element_comp) || result.addComponent(_yx_node_element_comp)
cell.identifier = identifier cell.identifier = identifier
/**
* @todo 滑动很快的时候似乎偶尔会触发 `Error occurs in an event listener: touch-start`
* 复现条件: 列表嵌套 && 快速滑动 && 刷新列表,像是刷新后把 cell node 给回收了导致的
*/
result.on(NodeEventType.TOUCH_END, this.onTouchElement, this) result.on(NodeEventType.TOUCH_END, this.onTouchElement, this)
} }
return result return result
@@ -951,7 +929,7 @@ export class YXCollectionView extends Component {
* 刷新列表数据 * 刷新列表数据
*/ */
reloadData() { reloadData() {
if (this.node != null && this.node.activeInHierarchy && this.node.parent && this.layout != null) { if (this.node.activeInHierarchy && this.node.parent) {
this._reloadData() this._reloadData()
return return
} }
@@ -1286,7 +1264,6 @@ export class YXCollectionView extends Component {
this.node.on(ScrollView.EventType.SCROLLING, this.onScrolling, this) this.node.on(ScrollView.EventType.SCROLLING, this.onScrolling, this)
this.node.on(ScrollView.EventType.TOUCH_UP, this.onScrollTouchUp, this) this.node.on(ScrollView.EventType.TOUCH_UP, this.onScrollTouchUp, this)
this.node.on(ScrollView.EventType.SCROLL_ENDED, this.onScrollEnded, this) this.node.on(ScrollView.EventType.SCROLL_ENDED, this.onScrollEnded, this)
this.node.on(NodeEventType.SIZE_CHANGED, this.onSizeChange, this)
this._scrollView._yx_startAttenuatingAutoScrollTargetOffset = (touchMoveVelocity, startOffset, originTargetOffset, originScrollTime) => { this._scrollView._yx_startAttenuatingAutoScrollTargetOffset = (touchMoveVelocity, startOffset, originTargetOffset, originScrollTime) => {
return this.layout.targetOffset(this, touchMoveVelocity, startOffset, originTargetOffset, originScrollTime) return this.layout.targetOffset(this, touchMoveVelocity, startOffset, originTargetOffset, originScrollTime)
} }
@@ -1297,7 +1274,6 @@ export class YXCollectionView extends Component {
this.node.off(ScrollView.EventType.SCROLLING, this.onScrolling, this) this.node.off(ScrollView.EventType.SCROLLING, this.onScrolling, this)
this.node.off(ScrollView.EventType.TOUCH_UP, this.onScrollTouchUp, this) this.node.off(ScrollView.EventType.TOUCH_UP, this.onScrollTouchUp, this)
this.node.off(ScrollView.EventType.SCROLL_ENDED, this.onScrollEnded, this) this.node.off(ScrollView.EventType.SCROLL_ENDED, this.onScrollEnded, this)
this.node.off(NodeEventType.SIZE_CHANGED, this.onSizeChange, this)
this._scrollView._yx_startAttenuatingAutoScrollTargetOffset = null this._scrollView._yx_startAttenuatingAutoScrollTargetOffset = null
// 销毁当前所有正在显示的节点 // 销毁当前所有正在显示的节点
@@ -1444,12 +1420,6 @@ export class YXCollectionView extends Component {
this.recycleInvisibleNodes() this.recycleInvisibleNodes()
this.layout.onScrollEnded(this) this.layout.onScrollEnded(this)
} }
private onSizeChange() {
if (this.autoReloadOnSizeChange) {
this.reloadData()
}
}
} }
export namespace YXCollectionView { export namespace YXCollectionView {

View File

@@ -6,10 +6,6 @@ enum _yx_table_layout_supplementary_kinds {
FOOTER = 'footer', FOOTER = 'footer',
} }
/**
* TableView 布局
* 这个布局实现了 YXCollectionView 约定的大部分的概念,有想深入了解自定义布局的可以拿这套布局当作参考
*/
export class YXTableLayout extends YXLayout { export class YXTableLayout extends YXLayout {
/** /**
@@ -185,7 +181,7 @@ export class YXTableLayout extends YXLayout {
} }
// 重要: 设置内容区域总大小,只有确定了滚动区域的大小列表才能滚动 // 重要: 设置内容区域总大小,只有确定了滚动区域的大小列表才能滚动
this.contentSize = new math.Size(contentWidth, Math.max(contentHeight, collectionView.scrollView.view.height)) this.contentSize = new math.Size(contentWidth, contentHeight)
} }
initOffset(collectionView: YXCollectionView): void { initOffset(collectionView: YXCollectionView): void {

View File

@@ -3,6 +3,5 @@
"uuid": "d21c5c56-bc81-481d-b241-7ce394501071", "uuid": "d21c5c56-bc81-481d-b241-7ce394501071",
"creator": { "creator": {
"version": "3.8.0" "version": "3.8.0"
}, }
"description": "开源版本"
} }

View File

@@ -1,11 +1,3 @@
{ {
"__version__": "1.0.5", "__version__": "1.0.5"
"general": {
"designResolution": {
"width": 720,
"height": 1280,
"fitHeight": true,
"fitWidth": false
}
}
} }