• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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 * @file Defines Repeat component.
18 * @kit ArkUI
19 */
20
21/**
22 * Construct a new type for each item.
23 *
24 * @interface RepeatItem
25 * @syscap SystemCapability.ArkUI.ArkUI.Full
26 * @crossplatform
27 * @form
28 * @atomicservice
29 * @since 12
30 */
31interface RepeatItem<T> {
32  /**
33   * The origin data.
34   *
35   * @type { T }
36   * @syscap SystemCapability.ArkUI.ArkUI.Full
37   * @crossplatform
38   * @form
39   * @atomicservice
40   * @since 12
41   */
42  item: T,
43  /**
44   * index of each item.
45   *
46   * @type { number }
47   * @syscap SystemCapability.ArkUI.ArkUI.Full
48   * @crossplatform
49   * @form
50   * @atomicservice
51   * @since 12
52   */
53  index: number
54}
55
56/**
57 * Define the options of repeat virtualScroll to implement reuse and lazy loading.
58 *
59 * @interface VirtualScrollOptions
60 * @syscap SystemCapability.ArkUI.ArkUI.Full
61 * @crossplatform
62 * @atomicservice
63 * @since 12
64 */
65interface VirtualScrollOptions {
66  /**
67   * Total data count.
68   *
69   * @type { ?number }
70   * @syscap SystemCapability.ArkUI.ArkUI.Full
71   * @crossplatform
72   * @atomicservice
73   * @since 12
74   */
75  totalCount?: number;
76
77  /**
78   * Reuse or not.
79   *
80   * @type { ?boolean }
81   * @syscap SystemCapability.ArkUI.ArkUI.Full
82   * @crossplatform
83   * @atomicservice
84   * @since 18
85   */
86  reusable?: boolean;
87
88  /**
89   * Data lazy loading
90   *
91   * @param { number } index
92   * @syscap SystemCapability.ArkUI.ArkUI.Full
93   * @crossplatform
94   * @atomicservice
95   * @since 19
96   */
97  onLazyLoading?(index: number): void;
98
99  /**
100   * The function of total data count.
101   *
102   * @returns { number } Returns the total data count.
103   * @syscap SystemCapability.ArkUI.ArkUI.Full
104   * @crossplatform
105   * @atomicservice
106   * @since 19
107   */
108  onTotalCount?(): number;
109}
110
111/**
112 * Define a builder template option parameter.
113 *
114 * @interface TemplateOptions
115 * @syscap SystemCapability.ArkUI.ArkUI.Full
116 * @crossplatform
117 * @atomicservice
118 * @since 12
119 */
120interface TemplateOptions {
121  /**
122   * The cached number of each template.
123   *
124   * @type { ?number }
125   * @syscap SystemCapability.ArkUI.ArkUI.Full
126   * @crossplatform
127   * @atomicservice
128   * @since 12
129   */
130  cachedCount?: number
131}
132
133/**
134 * Function that return typed string to render one template.
135 *
136 * @typedef {function} TemplateTypedFunc<T>
137 * @param { T } item - data item.
138 * @param {number} index - data index number in array.
139 * @returns { string } template type.
140 * @syscap SystemCapability.ArkUI.ArkUI.Full
141 * @crossplatform
142 * @atomicservice
143 * @since 12
144 */
145declare type TemplateTypedFunc<T> = (item: T, index: number) => string;
146
147/**
148 * Define builder function to render one template type.
149 *
150 * @typedef {function} RepeatItemBuilder<T>
151 * @param { RepeatItem<T> } repeatItem - the repeat item builder function.
152 * @syscap SystemCapability.ArkUI.ArkUI.Full
153 * @crossplatform
154 * @atomicservice
155 * @since 12
156 */
157declare type RepeatItemBuilder<T> = (repeatItem: RepeatItem<T>) => void;
158
159/**
160 * Defines the Repeat component attribute functions.
161 *
162 * @syscap SystemCapability.ArkUI.ArkUI.Full
163 * @crossplatform
164 * @form
165 * @atomicservice
166 * @since 12
167 */
168/**
169 * Defines the Repeat component attribute functions.
170 *
171 * @extends DynamicNode<RepeatAttribute<T>>
172 * @syscap SystemCapability.ArkUI.ArkUI.Full
173 * @crossplatform
174 * @form
175 * @atomicservice
176 * @since 19
177 */
178declare class RepeatAttribute<T> extends DynamicNode<RepeatAttribute<T>> {
179  /**
180   * Executes itemGenerator of each item.
181   *
182   * @param { function } itemGenerator
183   * @returns { RepeatAttribute<T> }
184   * @syscap SystemCapability.ArkUI.ArkUI.Full
185   * @crossplatform
186   * @form
187   * @atomicservice
188   * @since 12
189   */
190  each(itemGenerator: (repeatItem: RepeatItem<T>) => void): RepeatAttribute<T>;
191  /**
192   * Obtains key of each item.
193   *
194   * @param { function } keyGenerator
195   * @returns { RepeatAttribute<T> }
196   * @syscap SystemCapability.ArkUI.ArkUI.Full
197   * @crossplatform
198   * @form
199   * @atomicservice
200   * @since 12
201   */
202  key(keyGenerator: (item: T, index: number) => string): RepeatAttribute<T>;
203  /**
204   * Enable UI lazy loading when scroll up or down.
205   *
206   * @param { VirtualScrollOptions } virtualScrollOptions that defines the options of repeat virtual scroll to implement reuse and lazy loading.
207   * @returns { RepeatAttribute<T> }
208   * @syscap SystemCapability.ArkUI.ArkUI.Full
209   * @crossplatform
210   * @atomicservice
211   * @since 12
212   */
213  virtualScroll(virtualScrollOptions?: VirtualScrollOptions): RepeatAttribute<T>;
214  /**
215   * Type builder function to render specific type of data item.
216   *
217   * @param { string } type that defines the template id.
218   * @param { RepeatItemBuilder<T> } itemBuilder that defines UI builder function.
219   * @param { TemplateOptions } templateOptions that defines a builder template option parameter.
220   * @returns { RepeatAttribute<T> }
221   * @syscap SystemCapability.ArkUI.ArkUI.Full
222   * @crossplatform
223   * @atomicservice
224   * @since 12
225   */
226  template(type: string, itemBuilder: RepeatItemBuilder<T>, templateOptions?: TemplateOptions): RepeatAttribute<T>;
227  /**
228   * Typed function to render specific type of data item.
229   *
230   * @param { TemplateTypedFunc<T> } typedFunc that define template typed function.
231   * @returns { RepeatAttribute<T> }
232   * @syscap SystemCapability.ArkUI.ArkUI.Full
233   * @crossplatform
234   * @atomicservice
235   * @since 12
236   */
237  templateId(typedFunc: TemplateTypedFunc<T>): RepeatAttribute<T>;
238}
239
240/**
241 * Indicates the type of Repeat's Data Source.
242 *
243 * @typedef { Array<T> | ReadonlyArray<T> | Readonly<Array<T>> }
244 * @syscap SystemCapability.ArkUI.ArkUI.Full
245 * @crossplatform
246 * @form
247 * @atomicservice
248 * @since 18
249 */
250declare type RepeatArray<T> = Array<T> | ReadonlyArray<T> | Readonly<Array<T>>;
251
252/**
253 * Indicates the type of Repeat.
254 *
255 * @typedef { function } RepeatInterface
256 * @param { RepeatArray<T> } arr - The Data Source
257 * @returns { RepeatAttribute<T> }
258 * @syscap SystemCapability.ArkUI.ArkUI.Full
259 * @crossplatform
260 * @form
261 * @atomicservice
262 * @since 18
263 */
264declare type RepeatInterface = <T>(arr: RepeatArray<T>) => RepeatAttribute<T>;
265
266/**
267 * Defines Repeat Component.
268 *
269 * @type { <T>(arr: Array<T>) => RepeatAttribute<T> }
270 * @syscap SystemCapability.ArkUI.ArkUI.Full
271 * @crossplatform
272 * @form
273 * @atomicservice
274 * @since 12
275 */
276/**
277 * Defines Repeat Component, and Add More Array Type.
278 *
279 * @type { RepeatInterface }
280 * @syscap SystemCapability.ArkUI.ArkUI.Full
281 * @crossplatform
282 * @form
283 * @atomicservice
284 * @since 18
285 */
286declare const Repeat: RepeatInterface;
287