• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * ForEach for partial update
18 * Repeat aka ForEach and LazyForEach with child update
19 *
20 * all definitions in this file are framework internal
21 *
22 * Note: the API for ForEach with partial update and with full update
23 * are different. Only this declaration file or the one for full update
24 * can be used. Using both would lead to syntax error.
25 *
26 */
27
28declare class ForEach {
29  static create(): void;
30  static pop(): void;
31  static setIdArray(elmtId: number, newIdArray: string[], diffIndexArray: number[],
32    duplicateIds: number[], removedChildElmtIds: number[]): void;
33  static createNewChildStart(id: string, parentView: NativeViewPartialUpdate): void;
34  static createNewChildFinish(id: string, parentView: NativeViewPartialUpdate): void;
35}
36
37// Repeat maps to C++ RepeatNode
38declare class RepeatNative {
39  static startRender(): void;
40  static finishRender(removedChildElmtIds: Array<number>): void;
41  static moveChild(fromIndex: number): void;
42  static createNewChildStart(id: string): void;
43  static createNewChildFinish(id: string): void;
44  static afterAddChild(): void;
45  static onMove(handler: (from: number, to: number) => void, eventHandler?: ItemDragEventHandler);
46}
47
48// Repeat.virtualScroll maps to C++ RepeatVirtualScrollNode
49declare class RepeatVirtualScrollNative {
50  static create(
51    totalCount: number,
52    templateOptions: [string, RepeatTemplateOptions][],
53    handlers: {
54      onCreateNode: (forIndex: number) => void;
55      onUpdateNode: (fromKey: string, forIndex: number) => void;
56      onGetKeys4Range: (from: number, toNumber: number) => Array<string>;
57      onGetTypes4Range: (from: number, toNumber: number) => Array<string>;
58      onSetActiveRange: (from: number, to: number) => void;
59    },
60    reusable: boolean
61  ): void;
62  // invalidate caches in C++ side, trigger render if needed
63  static updateRenderState(totalCount: number, visibleItemsChanged: boolean): void;
64  // drag and drop
65  static onMove(handler: (from: number, to: number) => void, eventHandler?: ItemDragEventHandler);
66  static setCreateByTemplate(isCreatedByTemplate: boolean): void;
67}
68
69// Repeat.virtualScroll (v2) maps to C++ RepeatVirtualScroll2Node
70declare class RepeatVirtualScroll2Native {
71  static create(
72    arrLen: number,
73    totalCount: number,
74    handlers: {
75      onGetRid4Index: (forIndex: number) => [number, number],
76      onRecycleItems: (fromIndex: number, toIndex: number) => void,
77      onActiveRange: (fromIndex: number, toIndex: number, vStart: number, vEnd: number, isLoop: boolean) => void,
78      onMoveFromTo: (moveFrom: number, moveTo: number) => void,
79      onPurge: () => void;
80    }
81  ): void;
82
83  // purge node with given Repeat Item Id (Rid)
84  static removeNode(rid: number): void;
85
86  // Drop node with given Repeat Item Id (Rid) from L1 cache
87  static setInvalid(repeatelmtId: number, rid: number): void;
88
89  // invalidate owning Container layout starting from Repeat child index
90  static requestContainerReLayout(repeatElmtId: number, arrLen: number, totalCount: number, index?: number): void;
91
92  static notifyContainerLayoutChange(repeatElmtId: number, arrLen: number, totalCount: number,
93    index: number, count: number, notificationType: number): void;
94
95  static updateL1Rid4Index(repeatElmtId: number,
96    arrLen: number,
97    totalCount: number,
98    invalidateContainerLayoutFromChildIndex: number,
99    l1rid4index: Array<Array<number>>,
100    ridNeedToRecycle: Array<number>): void;
101
102  // drag and drop
103  static onMove(repeatElmtId: number, handler: (from: number, to: number) => void, eventHandler?: ItemDragEventHandler);
104  static setCreateByTemplate(isCreatedByTemplate: boolean): void;
105}