161847f8eSopenharmony_ci/*
261847f8eSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
461847f8eSopenharmony_ci * you may not use this file except in compliance with the License.
561847f8eSopenharmony_ci * You may obtain a copy of the License at
661847f8eSopenharmony_ci *
761847f8eSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
861847f8eSopenharmony_ci *
961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and
1361847f8eSopenharmony_ci * limitations under the License.
1461847f8eSopenharmony_ci */
1561847f8eSopenharmony_ci
1661847f8eSopenharmony_ci/**
1761847f8eSopenharmony_ci * @file Defines Repeat component.
1861847f8eSopenharmony_ci * @kit ArkUI
1961847f8eSopenharmony_ci */
2061847f8eSopenharmony_ci
2161847f8eSopenharmony_ci/**
2261847f8eSopenharmony_ci * Construct a new type for each item.
2361847f8eSopenharmony_ci *
2461847f8eSopenharmony_ci * @interface RepeatItem
2561847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full
2661847f8eSopenharmony_ci * @crossplatform
2761847f8eSopenharmony_ci * @form
2861847f8eSopenharmony_ci * @atomicservice
2961847f8eSopenharmony_ci * @since 12
3061847f8eSopenharmony_ci */
3161847f8eSopenharmony_ciinterface RepeatItem<T> {
3261847f8eSopenharmony_ci  /**
3361847f8eSopenharmony_ci   * The origin data.
3461847f8eSopenharmony_ci   *
3561847f8eSopenharmony_ci   * @type { T }
3661847f8eSopenharmony_ci   * @syscap SystemCapability.ArkUI.ArkUI.Full
3761847f8eSopenharmony_ci   * @crossplatform
3861847f8eSopenharmony_ci   * @form
3961847f8eSopenharmony_ci   * @atomicservice
4061847f8eSopenharmony_ci   * @since 12
4161847f8eSopenharmony_ci   */
4261847f8eSopenharmony_ci  item: T,
4361847f8eSopenharmony_ci  /**
4461847f8eSopenharmony_ci   * index of each item.
4561847f8eSopenharmony_ci   *
4661847f8eSopenharmony_ci   * @type { number }
4761847f8eSopenharmony_ci   * @syscap SystemCapability.ArkUI.ArkUI.Full
4861847f8eSopenharmony_ci   * @crossplatform
4961847f8eSopenharmony_ci   * @form
5061847f8eSopenharmony_ci   * @atomicservice
5161847f8eSopenharmony_ci   * @since 12
5261847f8eSopenharmony_ci   */
5361847f8eSopenharmony_ci  index: number
5461847f8eSopenharmony_ci}
5561847f8eSopenharmony_ci
5661847f8eSopenharmony_ci/**
5761847f8eSopenharmony_ci * Define the options of repeat virtualScroll to implement reuse and lazy loading.
5861847f8eSopenharmony_ci *
5961847f8eSopenharmony_ci * @interface VirtualScrollOptions
6061847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full
6161847f8eSopenharmony_ci * @crossplatform
6261847f8eSopenharmony_ci * @atomicservice
6361847f8eSopenharmony_ci * @since 12
6461847f8eSopenharmony_ci */
6561847f8eSopenharmony_ciinterface VirtualScrollOptions {
6661847f8eSopenharmony_ci  /**
6761847f8eSopenharmony_ci   * Total data count.
6861847f8eSopenharmony_ci   *
6961847f8eSopenharmony_ci   * @type { ?number }
7061847f8eSopenharmony_ci   * @syscap SystemCapability.ArkUI.ArkUI.Full
7161847f8eSopenharmony_ci   * @crossplatform
7261847f8eSopenharmony_ci   * @atomicservice
7361847f8eSopenharmony_ci   * @since 12
7461847f8eSopenharmony_ci   */
7561847f8eSopenharmony_ci  totalCount?: number;
7661847f8eSopenharmony_ci}
7761847f8eSopenharmony_ci
7861847f8eSopenharmony_ci/**
7961847f8eSopenharmony_ci * Define a builder template option parameter.
8061847f8eSopenharmony_ci *
8161847f8eSopenharmony_ci * @interface TemplateOptions
8261847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full
8361847f8eSopenharmony_ci * @crossplatform
8461847f8eSopenharmony_ci * @atomicservice
8561847f8eSopenharmony_ci * @since 12
8661847f8eSopenharmony_ci */
8761847f8eSopenharmony_ciinterface TemplateOptions {
8861847f8eSopenharmony_ci  /**
8961847f8eSopenharmony_ci   * The cached number of each template.
9061847f8eSopenharmony_ci   *
9161847f8eSopenharmony_ci   * @type { ?number }
9261847f8eSopenharmony_ci   * @syscap SystemCapability.ArkUI.ArkUI.Full
9361847f8eSopenharmony_ci   * @crossplatform
9461847f8eSopenharmony_ci   * @atomicservice
9561847f8eSopenharmony_ci   * @since 12
9661847f8eSopenharmony_ci   */
9761847f8eSopenharmony_ci  cachedCount?: number
9861847f8eSopenharmony_ci}
9961847f8eSopenharmony_ci
10061847f8eSopenharmony_ci/**
10161847f8eSopenharmony_ci * Function that return typed string to render one template.
10261847f8eSopenharmony_ci *
10361847f8eSopenharmony_ci * @typedef {function} TemplateTypedFunc<T>
10461847f8eSopenharmony_ci * @param { T } item - data item.
10561847f8eSopenharmony_ci * @param {number} index - data index number in array.
10661847f8eSopenharmony_ci * @returns { string } template type.
10761847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full
10861847f8eSopenharmony_ci * @crossplatform
10961847f8eSopenharmony_ci * @atomicservice
11061847f8eSopenharmony_ci * @since 12
11161847f8eSopenharmony_ci */
11261847f8eSopenharmony_cideclare type TemplateTypedFunc<T> = (item : T, index : number) => string;
11361847f8eSopenharmony_ci
11461847f8eSopenharmony_ci/**
11561847f8eSopenharmony_ci * Define builder function to render one template type.
11661847f8eSopenharmony_ci *
11761847f8eSopenharmony_ci * @typedef {function} RepeatItemBuilder<T>
11861847f8eSopenharmony_ci * @param { RepeatItem<T> } repeatItem - the repeat item builder function.
11961847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full
12061847f8eSopenharmony_ci * @crossplatform
12161847f8eSopenharmony_ci * @atomicservice
12261847f8eSopenharmony_ci * @since 12
12361847f8eSopenharmony_ci */
12461847f8eSopenharmony_cideclare type RepeatItemBuilder<T> = (repeatItem: RepeatItem<T>) => void;
12561847f8eSopenharmony_ci
12661847f8eSopenharmony_ci/**
12761847f8eSopenharmony_ci * Defines the Repeat component attribute functions.
12861847f8eSopenharmony_ci *
12961847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full
13061847f8eSopenharmony_ci * @crossplatform
13161847f8eSopenharmony_ci * @form
13261847f8eSopenharmony_ci * @atomicservice
13361847f8eSopenharmony_ci * @since 12
13461847f8eSopenharmony_ci */
13561847f8eSopenharmony_cideclare class RepeatAttribute<T> {
13661847f8eSopenharmony_ci  /**
13761847f8eSopenharmony_ci   * Executes itemGenerator of each item.
13861847f8eSopenharmony_ci   *
13961847f8eSopenharmony_ci   * @param { function } itemGenerator
14061847f8eSopenharmony_ci   * @returns { RepeatAttribute<T> }
14161847f8eSopenharmony_ci   * @syscap SystemCapability.ArkUI.ArkUI.Full
14261847f8eSopenharmony_ci   * @crossplatform
14361847f8eSopenharmony_ci   * @form
14461847f8eSopenharmony_ci   * @atomicservice
14561847f8eSopenharmony_ci   * @since 12
14661847f8eSopenharmony_ci   */
14761847f8eSopenharmony_ci  each(itemGenerator: (repeatItem: RepeatItem<T>) => void): RepeatAttribute<T>;
14861847f8eSopenharmony_ci  /**
14961847f8eSopenharmony_ci   * Obtains key of each item.
15061847f8eSopenharmony_ci   *
15161847f8eSopenharmony_ci   * @param { function } keyGenerator
15261847f8eSopenharmony_ci   * @returns { RepeatAttribute<T> }
15361847f8eSopenharmony_ci   * @syscap SystemCapability.ArkUI.ArkUI.Full
15461847f8eSopenharmony_ci   * @crossplatform
15561847f8eSopenharmony_ci   * @form
15661847f8eSopenharmony_ci   * @atomicservice
15761847f8eSopenharmony_ci   * @since 12
15861847f8eSopenharmony_ci   */
15961847f8eSopenharmony_ci  key(keyGenerator: (item: T, index: number) => string): RepeatAttribute<T>;
16061847f8eSopenharmony_ci  /**
16161847f8eSopenharmony_ci   * Enable UI lazy loading when scroll up or down.
16261847f8eSopenharmony_ci   *
16361847f8eSopenharmony_ci   * @param { VirtualScrollOptions } virtualScrollOptions that defines the options of repeat virtual scroll to implement reuse and lazy loading.
16461847f8eSopenharmony_ci   * @returns { RepeatAttribute<T> }
16561847f8eSopenharmony_ci   * @syscap SystemCapability.ArkUI.ArkUI.Full
16661847f8eSopenharmony_ci   * @crossplatform
16761847f8eSopenharmony_ci   * @atomicservice
16861847f8eSopenharmony_ci   * @since 12
16961847f8eSopenharmony_ci   */
17061847f8eSopenharmony_ci  virtualScroll(virtualScrollOptions?: VirtualScrollOptions): RepeatAttribute<T>;
17161847f8eSopenharmony_ci  /**
17261847f8eSopenharmony_ci   * Type builder function to render specific type of data item.
17361847f8eSopenharmony_ci   *
17461847f8eSopenharmony_ci   * @param { string } type that defines the template id.
17561847f8eSopenharmony_ci   * @param { RepeatItemBuilder<T> } itemBuilder that defines UI builder function.
17661847f8eSopenharmony_ci   * @param { TemplateOptions } templateOptions that defines a builder template option parameter.
17761847f8eSopenharmony_ci   * @returns { RepeatAttribute<T> }
17861847f8eSopenharmony_ci   * @syscap SystemCapability.ArkUI.ArkUI.Full
17961847f8eSopenharmony_ci   * @crossplatform
18061847f8eSopenharmony_ci   * @atomicservice
18161847f8eSopenharmony_ci   * @since 12
18261847f8eSopenharmony_ci   */
18361847f8eSopenharmony_ci  template(type : string, itemBuilder: RepeatItemBuilder<T>, templateOptions?: TemplateOptions): RepeatAttribute<T>;
18461847f8eSopenharmony_ci  /**
18561847f8eSopenharmony_ci   * Typed function to render specific type of data item.
18661847f8eSopenharmony_ci   *
18761847f8eSopenharmony_ci   * @param { TemplateTypedFunc<T> } typedFunc that define template typed function.
18861847f8eSopenharmony_ci   * @returns { RepeatAttribute<T> }
18961847f8eSopenharmony_ci   * @syscap SystemCapability.ArkUI.ArkUI.Full
19061847f8eSopenharmony_ci   * @crossplatform
19161847f8eSopenharmony_ci   * @atomicservice
19261847f8eSopenharmony_ci   * @since 12
19361847f8eSopenharmony_ci   */
19461847f8eSopenharmony_ci  templateId(typedFunc: TemplateTypedFunc<T>): RepeatAttribute<T>;
19561847f8eSopenharmony_ci}
19661847f8eSopenharmony_ci
19761847f8eSopenharmony_ci/**
19861847f8eSopenharmony_ci * Defines Repeat Component.
19961847f8eSopenharmony_ci *
20061847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full
20161847f8eSopenharmony_ci * @crossplatform
20261847f8eSopenharmony_ci * @form
20361847f8eSopenharmony_ci * @atomicservice
20461847f8eSopenharmony_ci * @since 12
20561847f8eSopenharmony_ci */
20661847f8eSopenharmony_cideclare const Repeat: <T>(arr: Array<T>) => RepeatAttribute<T>;
207