creator-collection-view/doc/declarations/yx-collection-view.d.ts

403 lines
15 KiB
TypeScript
Raw Normal View History

2024-12-14 17:51:28 +08:00
import { Component, math, Node, ScrollView, ValueType } from 'cc';
type _yx_readonly_deep<T> = {
readonly [P in keyof T]: T[P] extends Record<string, any> ? _yx_readonly_deep<T[P]> : T[P];
};
/**
*
*/
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 extends ValueType {
static ZERO: Readonly<YXIndexPath>;
/**
*
*/
section: number;
/**
*
*/
item: number;
set row(value: number);
get row(): number;
constructor(section: number, item: number);
clone(): YXIndexPath;
equals(other: YXIndexPath): boolean;
set(other: YXIndexPath): void;
toString(): string;
}
/**
*
*/
export declare class YXEdgeInsets extends ValueType {
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;
}
/**
*
* cell YXCollectionView
*/
declare class _cell_ extends Component {
/**
*
*/
identifier: string;
/**
*
*/
attributes: YXLayoutAttributes;
}
/**
*
*/
export declare class YXLayoutAttributes {
/**
*
*/
get indexPath(): YXIndexPath;
constructor(indexPath: YXIndexPath);
/**
*
* origin size
*/
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
*/
attributes: YXLayoutAttributes[];
/**
* @required
*
* 注意: 必须初始化滚动区域大小并赋值给 @contentSize
* 注意: 必须初始化所有的元素布局属性 @attributes
* 可选: 根据 collectionView scrollDirection
*/
abstract prepare(collectionView: YXCollectionView): void;
/**
* @optional
*
*
*/
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
*
* @param collectionView
*/
onScrollEnded(collectionView: YXCollectionView): void;
/**
* @optional
* ( shouldUpdateAttributesForBoundsChange )
*
* () ()
* @param rect
*/
layoutAttributesForElementsInRect(rect: math.Rect, collectionView: YXCollectionView): YXLayoutAttributes[];
/**
* @optional
* Array.find()
* @param indexPath
* @param collectionView
*/
layoutAttributesForItemAtIndexPath(indexPath: YXIndexPath, collectionView: YXCollectionView): YXLayoutAttributes;
/**
* @optional
* YXCollectionView @scrollTo
* @param indexPath
* @returns
*/
scrollTo(indexPath: YXIndexPath, collectionView: YXCollectionView): math.Vec2;
/**
* @optional
* @see YXLayoutAttributes.zIndex
* @returns
*/
shouldUpdateAttributesZIndex(): boolean;
/**
* @optional
* @see YXLayoutAttributes.opacity
* @returns
*/
shouldUpdateAttributesOpacity(): boolean;
/**
* @optional
*
* @returns true YXCollectionView frameInterval
*/
shouldUpdateAttributesForBoundsChange(): boolean;
}
/**
*
* 使
*/
export declare abstract class YXBinaryLayout extends YXLayout {
/**
* @bug
* @fix
*
*
*/
extraVisibleCount: number;
layoutAttributesForElementsInRect(rect: math.Rect, collectionView: YXCollectionView): YXLayoutAttributes[];
layoutAttributesForItemAtIndexPath(indexPath: YXIndexPath, collectionView: YXCollectionView): YXLayoutAttributes;
}
/**
* @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
*/
scrollDirection: YXCollectionView.ScrollDirection;
/**
*
*/
mode: YXCollectionView.Mode;
/**
*
*/
preloadNodesLimitPerFrame: number;
/**
*
*/
preloadProgress: (current: number, total: number) => void;
/**
* 1
*/
frameInterval: number;
/**
* 10
* @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
*/
register(identifier: string, maker: () => Node, poolComp?: (new (...args: any[]) => YXCollectionViewCell) | string | null): void;
/**
* cell
* @param identifier
* @returns
*/
dequeueReusableCell(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;
/**
* cell
*
*/
onCellDisplay: (cell: Node, indexPath: YXIndexPath, collectionView: YXCollectionView) => void;
/**
* cell
*/
onCellEndDisplay: (cell: Node, indexPath: YXIndexPath, collectionView: YXCollectionView) => void;
/**
*
*/
onTouchItemAt: (indexPath: YXIndexPath, collectionView: YXCollectionView) => void;
/**
*
*/
layout: YXLayout;
/**
*
*/
get visibleRect(): math.Rect;
/**
* /
*/
get visibleNodes(): Node[];
get visibleCells(): YXCollectionView.Cell[];
/**
* /
* @param indexPath
*/
getVisibleNode(indexPath: YXIndexPath): Node | null;
getVisibleCell(indexPath: YXIndexPath): YXCollectionView.Cell | null;
/**
* cell
*/
getCellComp(node: Node): YXCollectionView.Cell | null;
/**
*
*/
reloadData(): void;
/**
*
* @returns
*/
scrollTo(indexPath: YXIndexPath, timeInSecond?: number, attenuated?: boolean): void;
/**
*
*/
protected onLoad(): void;
protected onDestroy(): void;
protected update(dt: number): void;
/**
*
* @param force true: false:
*/
markForUpdateVisibleData(force?: boolean): void;
}
export declare namespace YXCollectionView {
/**
*
*/
type ScrollDirection = _yx_collection_view_scroll_direction;
type Mode = _yx_collection_view_list_mode;
type Cell = _yx_readonly_deep<_cell_>;
}
export { };