/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @file Defines Repeat component. * @kit ArkUI */ /** * Construct a new type for each item. * * @interface RepeatItem * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @form * @atomicservice * @since 12 */ interface RepeatItem { /** * The origin data. * * @type { T } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @form * @atomicservice * @since 12 */ item: T, /** * index of each item. * * @type { number } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @form * @atomicservice * @since 12 */ index: number } /** * Define the options of repeat virtualScroll to implement reuse and lazy loading. * * @interface VirtualScrollOptions * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ interface VirtualScrollOptions { /** * Total data count. * * @type { ?number } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ totalCount?: number; /** * Reuse or not. * * @type { ?boolean } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 18 */ reusable?: boolean; /** * Data lazy loading * * @param { number } index * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 19 */ onLazyLoading?(index: number): void; /** * The function of total data count. * * @returns { number } Returns the total data count. * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 19 */ onTotalCount?(): number; } /** * Define a builder template option parameter. * * @interface TemplateOptions * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ interface TemplateOptions { /** * The cached number of each template. * * @type { ?number } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ cachedCount?: number } /** * Function that return typed string to render one template. * * @typedef {function} TemplateTypedFunc * @param { T } item - data item. * @param {number} index - data index number in array. * @returns { string } template type. * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ declare type TemplateTypedFunc = (item: T, index: number) => string; /** * Define builder function to render one template type. * * @typedef {function} RepeatItemBuilder * @param { RepeatItem } repeatItem - the repeat item builder function. * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ declare type RepeatItemBuilder = (repeatItem: RepeatItem) => void; /** * Defines the Repeat component attribute functions. * * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @form * @atomicservice * @since 12 */ /** * Defines the Repeat component attribute functions. * * @extends DynamicNode> * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @form * @atomicservice * @since 19 */ declare class RepeatAttribute extends DynamicNode> { /** * Executes itemGenerator of each item. * * @param { function } itemGenerator * @returns { RepeatAttribute } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @form * @atomicservice * @since 12 */ each(itemGenerator: (repeatItem: RepeatItem) => void): RepeatAttribute; /** * Obtains key of each item. * * @param { function } keyGenerator * @returns { RepeatAttribute } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @form * @atomicservice * @since 12 */ key(keyGenerator: (item: T, index: number) => string): RepeatAttribute; /** * Enable UI lazy loading when scroll up or down. * * @param { VirtualScrollOptions } virtualScrollOptions that defines the options of repeat virtual scroll to implement reuse and lazy loading. * @returns { RepeatAttribute } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ virtualScroll(virtualScrollOptions?: VirtualScrollOptions): RepeatAttribute; /** * Type builder function to render specific type of data item. * * @param { string } type that defines the template id. * @param { RepeatItemBuilder } itemBuilder that defines UI builder function. * @param { TemplateOptions } templateOptions that defines a builder template option parameter. * @returns { RepeatAttribute } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ template(type: string, itemBuilder: RepeatItemBuilder, templateOptions?: TemplateOptions): RepeatAttribute; /** * Typed function to render specific type of data item. * * @param { TemplateTypedFunc } typedFunc that define template typed function. * @returns { RepeatAttribute } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 12 */ templateId(typedFunc: TemplateTypedFunc): RepeatAttribute; } /** * Indicates the type of Repeat's Data Source. * * @typedef { Array | ReadonlyArray | Readonly> } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @form * @atomicservice * @since 18 */ declare type RepeatArray = Array | ReadonlyArray | Readonly>; /** * Indicates the type of Repeat. * * @typedef { function } RepeatInterface * @param { RepeatArray } arr - The Data Source * @returns { RepeatAttribute } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @form * @atomicservice * @since 18 */ declare type RepeatInterface = (arr: RepeatArray) => RepeatAttribute; /** * Defines Repeat Component. * * @type { (arr: Array) => RepeatAttribute } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @form * @atomicservice * @since 12 */ /** * Defines Repeat Component, and Add More Array Type. * * @type { RepeatInterface } * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @form * @atomicservice * @since 18 */ declare const Repeat: RepeatInterface;