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

442 lines
18 KiB
TypeScript
Raw Normal View History

2025-01-08 23:39:02 +08:00
import { Component, math, Node, ScrollView } from 'cc';
2024-12-14 17:51:28 +08:00
/**
*
*/
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
}
/**
*
*/
2025-01-08 23:39:02 +08:00
export declare class YXIndexPath {
2024-12-14 17:51:28 +08:00
static ZERO: Readonly<YXIndexPath>;
/**
*
*/
2025-01-08 23:39:02 +08:00
get section(): number;
2024-12-14 17:51:28 +08:00
/**
*
*/
2025-01-08 23:39:02 +08:00
get item(): number;
/**
* item
*/
2024-12-14 17:51:28 +08:00
get row(): number;
constructor(section: number, item: number);
clone(): YXIndexPath;
equals(other: YXIndexPath): boolean;
toString(): string;
}
/**
*
*/
2025-01-08 23:39:02 +08:00
export declare class YXEdgeInsets {
2024-12-14 17:51:28 +08:00
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;
}
/**
2025-01-08 23:39:02 +08:00
*
2024-12-14 17:51:28 +08:00
*/
2025-01-08 23:39:02 +08:00
export declare class YXLayoutAttributes {
2024-12-14 17:51:28 +08:00
/**
2025-01-08 23:39:02 +08:00
* cell
2024-12-14 17:51:28 +08:00
*/
2025-01-08 23:39:02 +08:00
static layoutAttributesForCell(indexPath: YXIndexPath): YXLayoutAttributes;
2024-12-14 17:51:28 +08:00
/**
2025-01-08 23:39:02 +08:00
* supplementary
* @param kinds supplementaryKinds
2024-12-14 17:51:28 +08:00
*/
2025-01-08 23:39:02 +08:00
static layoutAttributesForSupplementary(indexPath: YXIndexPath, kinds: string): YXLayoutAttributes;
/**
* 访
*/
protected constructor();
2024-12-14 17:51:28 +08:00
/**
*
*/
get indexPath(): YXIndexPath;
2025-01-08 23:39:02 +08:00
/**
*
*/
get elementCategory(): "Cell" | "Supplementary";
/**
* Supplementary
*/
get supplementaryKinds(): string;
2024-12-14 17:51:28 +08:00
/**
*
* origin size
*/
2025-01-08 23:39:02 +08:00
get frame(): math.Rect;
2024-12-14 17:51:28 +08:00
/**
*
*
* 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
*
2025-01-08 23:39:02 +08:00
* prepare
2024-12-14 17:51:28 +08:00
*/
contentSize: math.Size;
/**
* @required
*
2025-01-08 23:39:02 +08:00
* prepare
* @todo 使
2024-12-14 17:51:28 +08:00
*/
attributes: YXLayoutAttributes[];
/**
* @required
*
2025-01-08 23:39:02 +08:00
* 注意: 必须初始化滚动区域大小并赋值给 contentSize
* 注意: 必须初始化所有的元素布局属性 attributes
2024-12-14 17:51:28 +08:00
* 可选: 根据 collectionView scrollDirection
*/
abstract prepare(collectionView: YXCollectionView): void;
/**
* @optional
*
*
2025-01-08 23:39:02 +08:00
*
* @example
* // 比如一个垂直列表希望初始化时从最顶部开始展示数据,那么可以在这个方法里通过 scrollToTop 实现
* initOffset(collectionView: YXCollectionView): void {
* collectionView.scrollView.scrollToTop()
* }
2024-12-14 17:51:28 +08:00
*/
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
2025-01-08 23:39:02 +08:00
*
* ( shouldUpdateAttributesForBoundsChange )
*
2024-12-14 17:51:28 +08:00
* @param rect
2025-01-08 23:39:02 +08:00
*
* @returns
*
* O(attributes.length)
2024-12-14 17:51:28 +08:00
*/
layoutAttributesForElementsInRect(rect: math.Rect, collectionView: YXCollectionView): YXLayoutAttributes[];
layoutAttributesForItemAtIndexPath(indexPath: YXIndexPath, collectionView: YXCollectionView): YXLayoutAttributes;
2025-01-08 23:39:02 +08:00
layoutAttributesForSupplementaryAtIndexPath(indexPath: YXIndexPath, collectionView: YXCollectionView, kinds: string): YXLayoutAttributes;
2024-12-14 17:51:28 +08:00
/**
* @optional
2025-01-08 23:39:02 +08:00
* scrollTo
2024-12-14 17:51:28 +08:00
*/
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;
/**
2025-01-08 23:39:02 +08:00
* @optional
*
2024-12-14 17:51:28 +08:00
*/
2025-01-08 23:39:02 +08:00
onDestroy(): void;
2024-12-14 17:51:28 +08:00
}
/**
* @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
2025-01-08 23:39:02 +08:00
* 备注: 如果使用的 YXLayout YXLayout 便
2024-12-14 17:51:28 +08:00
*/
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
2025-01-08 23:39:02 +08:00
* cell identifier
* @param identifier cell dequeueReusableCell cell
2024-12-14 17:51:28 +08:00
* @param maker
2025-01-08 23:39:02 +08:00
* @param poolComp () NodePool
*/
registerCell(identifier: string, maker: () => Node, poolComp?: (new (...args: any[]) => YXCollectionViewCell) | string | null): void;
/**
* supplementary registerCell
2024-12-14 17:51:28 +08:00
*/
2025-01-08 23:39:02 +08:00
registerSupplementary(identifier: string, maker: () => Node, poolComp?: (new (...args: any[]) => YXCollectionViewCell) | string | null): void;
2024-12-14 17:51:28 +08:00
/**
* cell
* @param identifier
*/
dequeueReusableCell(identifier: string): Node;
2025-01-08 23:39:02 +08:00
/**
* supplementary
* @param identifier
*/
dequeueReusableSupplementary(identifier: string): Node;
2024-12-14 17:51:28 +08:00
/**
* 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;
/**
2025-01-08 23:39:02 +08:00
* cellForItemAt dequeueReusableSupplementary Node
* @param kinds 使 layout
*/
supplementaryForItemAt: (indexPath: YXIndexPath, collectionView: YXCollectionView, kinds: string) => Node;
/**
* cell
2024-12-14 17:51:28 +08:00
*
*/
2025-01-08 23:39:02 +08:00
onCellDisplay: (node: Node, indexPath: YXIndexPath, collectionView: YXCollectionView) => void;
onCellEndDisplay: (node: Node, indexPath: YXIndexPath, collectionView: YXCollectionView) => void;
2024-12-14 17:51:28 +08:00
/**
2025-01-08 23:39:02 +08:00
* supplementary
2024-12-14 17:51:28 +08:00
*/
2025-01-08 23:39:02 +08:00
onSupplementaryDisplay: (node: Node, indexPath: YXIndexPath, collectionView: YXCollectionView, kinds: string) => void;
onSupplementaryEndDisplay: (node: Node, indexPath: YXIndexPath, collectionView: YXCollectionView, kinds: string) => void;
2024-12-14 17:51:28 +08:00
/**
2025-01-08 23:39:02 +08:00
* cell
2024-12-14 17:51:28 +08:00
*/
2025-01-08 23:39:02 +08:00
onTouchCellAt: (indexPath: YXIndexPath, collectionView: YXCollectionView) => void;
/**
* supplementary
*/
onTouchSupplementaryAt: (indexPath: YXIndexPath, collectionView: YXCollectionView, kinds: string) => void;
2024-12-14 17:51:28 +08:00
/**
*
*/
layout: YXLayout;
/**
*
*/
2025-01-08 23:39:02 +08:00
getVisibleRect(): math.Rect;
/**
* cell
*/
getVisibleCellNode(indexPath: YXIndexPath): Node;
/**
* supplementary
*/
getVisibleSupplementaryNode(indexPath: YXIndexPath, kinds: string): Node;
2024-12-14 17:51:28 +08:00
/**
2025-01-08 23:39:02 +08:00
* cell
2024-12-14 17:51:28 +08:00
*/
2025-01-08 23:39:02 +08:00
getVisibleCellNodes(): Node[];
2024-12-14 17:51:28 +08:00
/**
2025-01-08 23:39:02 +08:00
* supplementary
* @param kinds
2024-12-14 17:51:28 +08:00
*/
2025-01-08 23:39:02 +08:00
getVisibleSupplementaryNodes(kinds?: string): Node[];
2024-12-14 17:51:28 +08:00
/**
2025-01-08 23:39:02 +08:00
*
2024-12-14 17:51:28 +08:00
*/
2025-01-08 23:39:02 +08:00
getElementAttributes(node: Node): YXLayoutAttributes;
2024-12-14 17:51:28 +08:00
/**
*
*/
reloadData(): void;
2025-01-08 23:39:02 +08:00
/**
*
* @param force true: ; false:
*/
markForUpdateVisibleData(force?: boolean): void;
2024-12-14 17:51:28 +08:00
/**
*
2025-01-08 23:39:02 +08:00
* @todo .scrollView.scrollToOffset()
2024-12-14 17:51:28 +08:00
*/
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;
}
2025-01-08 23:39:02 +08:00
/**
* *****************************************************************************************
* *****************************************************************************************
*
* 使
* *****************************************************************************************
* *****************************************************************************************
*
* @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 {};