• 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/**
90 * Define a builder template option parameter.
91 *
92 * @interface TemplateOptions
93 * @syscap SystemCapability.ArkUI.ArkUI.Full
94 * @crossplatform
95 * @atomicservice
96 * @since 12
97 */
98interface TemplateOptions {
99  /**
100   * The cached number of each template.
101   *
102   * @type { ?number }
103   * @syscap SystemCapability.ArkUI.ArkUI.Full
104   * @crossplatform
105   * @atomicservice
106   * @since 12
107   */
108  cachedCount?: number
109}
110
111/**
112 * Function that return typed string to render one template.
113 *
114 * @typedef {function} TemplateTypedFunc<T>
115 * @param { T } item - data item.
116 * @param {number} index - data index number in array.
117 * @returns { string } template type.
118 * @syscap SystemCapability.ArkUI.ArkUI.Full
119 * @crossplatform
120 * @atomicservice
121 * @since 12
122 */
123declare type TemplateTypedFunc<T> = (item : T, index : number) => string;
124
125/**
126 * Define builder function to render one template type.
127 *
128 * @typedef {function} RepeatItemBuilder<T>
129 * @param { RepeatItem<T> } repeatItem - the repeat item builder function.
130 * @syscap SystemCapability.ArkUI.ArkUI.Full
131 * @crossplatform
132 * @atomicservice
133 * @since 12
134 */
135declare type RepeatItemBuilder<T> = (repeatItem: RepeatItem<T>) => void;
136
137/**
138 * Defines the Repeat component attribute functions.
139 *
140 * @syscap SystemCapability.ArkUI.ArkUI.Full
141 * @crossplatform
142 * @form
143 * @atomicservice
144 * @since 12
145 */
146declare class RepeatAttribute<T> {
147  /**
148   * Executes itemGenerator of each item.
149   *
150   * @param { function } itemGenerator
151   * @returns { RepeatAttribute<T> }
152   * @syscap SystemCapability.ArkUI.ArkUI.Full
153   * @crossplatform
154   * @form
155   * @atomicservice
156   * @since 12
157   */
158  each(itemGenerator: (repeatItem: RepeatItem<T>) => void): RepeatAttribute<T>;
159  /**
160   * Obtains key of each item.
161   *
162   * @param { function } keyGenerator
163   * @returns { RepeatAttribute<T> }
164   * @syscap SystemCapability.ArkUI.ArkUI.Full
165   * @crossplatform
166   * @form
167   * @atomicservice
168   * @since 12
169   */
170  key(keyGenerator: (item: T, index: number) => string): RepeatAttribute<T>;
171  /**
172   * Enable UI lazy loading when scroll up or down.
173   *
174   * @param { VirtualScrollOptions } virtualScrollOptions that defines the options of repeat virtual scroll to implement reuse and lazy loading.
175   * @returns { RepeatAttribute<T> }
176   * @syscap SystemCapability.ArkUI.ArkUI.Full
177   * @crossplatform
178   * @atomicservice
179   * @since 12
180   */
181  virtualScroll(virtualScrollOptions?: VirtualScrollOptions): RepeatAttribute<T>;
182  /**
183   * Type builder function to render specific type of data item.
184   *
185   * @param { string } type that defines the template id.
186   * @param { RepeatItemBuilder<T> } itemBuilder that defines UI builder function.
187   * @param { TemplateOptions } templateOptions that defines a builder template option parameter.
188   * @returns { RepeatAttribute<T> }
189   * @syscap SystemCapability.ArkUI.ArkUI.Full
190   * @crossplatform
191   * @atomicservice
192   * @since 12
193   */
194  template(type : string, itemBuilder: RepeatItemBuilder<T>, templateOptions?: TemplateOptions): RepeatAttribute<T>;
195  /**
196   * Typed function to render specific type of data item.
197   *
198   * @param { TemplateTypedFunc<T> } typedFunc that define template typed function.
199   * @returns { RepeatAttribute<T> }
200   * @syscap SystemCapability.ArkUI.ArkUI.Full
201   * @crossplatform
202   * @atomicservice
203   * @since 12
204   */
205  templateId(typedFunc: TemplateTypedFunc<T>): RepeatAttribute<T>;
206}
207
208/**
209 * Indicates the type of Repeat's Data Source.
210 *
211 * @typedef { Array<T> | ReadonlyArray<T> | Readonly<Array<T>> }
212 * @syscap SystemCapability.ArkUI.ArkUI.Full
213 * @crossplatform
214 * @form
215 * @atomicservice
216 * @since 18
217 */
218declare type RepeatArray<T> = Array<T> | ReadonlyArray<T> | Readonly<Array<T>>;
219
220/**
221 * Indicates the type of Repeat.
222 *
223 * @typedef { function } RepeatInterface
224 * @param { RepeatArray<T> } arr - The Data Source
225 * @returns { RepeatAttribute<T> }
226 * @syscap SystemCapability.ArkUI.ArkUI.Full
227 * @crossplatform
228 * @form
229 * @atomicservice
230 * @since 18
231 */
232declare type RepeatInterface = <T>(arr: RepeatArray<T>) => RepeatAttribute<T>;
233
234/**
235 * Defines Repeat Component.
236 *
237 * @type { <T>(arr: Array<T>) => RepeatAttribute<T> }
238 * @syscap SystemCapability.ArkUI.ArkUI.Full
239 * @crossplatform
240 * @form
241 * @atomicservice
242 * @since 12
243 */
244/**
245 * Defines Repeat Component, and Add More Array Type.
246 *
247 * @type { RepeatInterface }
248 * @syscap SystemCapability.ArkUI.ArkUI.Full
249 * @crossplatform
250 * @form
251 * @atomicservice
252 * @since 18
253 */
254declare const Repeat: RepeatInterface;
255