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/** 79 * Define a builder template option parameter. 80 * 81 * @interface TemplateOptions 82 * @syscap SystemCapability.ArkUI.ArkUI.Full 83 * @crossplatform 84 * @atomicservice 85 * @since 12 86 */ 87interface TemplateOptions { 88 /** 89 * The cached number of each template. 90 * 91 * @type { ?number } 92 * @syscap SystemCapability.ArkUI.ArkUI.Full 93 * @crossplatform 94 * @atomicservice 95 * @since 12 96 */ 97 cachedCount?: number 98} 99 100/** 101 * Function that return typed string to render one template. 102 * 103 * @typedef {function} TemplateTypedFunc<T> 104 * @param { T } item - data item. 105 * @param {number} index - data index number in array. 106 * @returns { string } template type. 107 * @syscap SystemCapability.ArkUI.ArkUI.Full 108 * @crossplatform 109 * @atomicservice 110 * @since 12 111 */ 112declare type TemplateTypedFunc<T> = (item : T, index : number) => string; 113 114/** 115 * Define builder function to render one template type. 116 * 117 * @typedef {function} RepeatItemBuilder<T> 118 * @param { RepeatItem<T> } repeatItem - the repeat item builder function. 119 * @syscap SystemCapability.ArkUI.ArkUI.Full 120 * @crossplatform 121 * @atomicservice 122 * @since 12 123 */ 124declare type RepeatItemBuilder<T> = (repeatItem: RepeatItem<T>) => void; 125 126/** 127 * Defines the Repeat component attribute functions. 128 * 129 * @syscap SystemCapability.ArkUI.ArkUI.Full 130 * @crossplatform 131 * @form 132 * @atomicservice 133 * @since 12 134 */ 135declare class RepeatAttribute<T> { 136 /** 137 * Executes itemGenerator of each item. 138 * 139 * @param { function } itemGenerator 140 * @returns { RepeatAttribute<T> } 141 * @syscap SystemCapability.ArkUI.ArkUI.Full 142 * @crossplatform 143 * @form 144 * @atomicservice 145 * @since 12 146 */ 147 each(itemGenerator: (repeatItem: RepeatItem<T>) => void): RepeatAttribute<T>; 148 /** 149 * Obtains key of each item. 150 * 151 * @param { function } keyGenerator 152 * @returns { RepeatAttribute<T> } 153 * @syscap SystemCapability.ArkUI.ArkUI.Full 154 * @crossplatform 155 * @form 156 * @atomicservice 157 * @since 12 158 */ 159 key(keyGenerator: (item: T, index: number) => string): RepeatAttribute<T>; 160 /** 161 * Enable UI lazy loading when scroll up or down. 162 * 163 * @param { VirtualScrollOptions } virtualScrollOptions that defines the options of repeat virtual scroll to implement reuse and lazy loading. 164 * @returns { RepeatAttribute<T> } 165 * @syscap SystemCapability.ArkUI.ArkUI.Full 166 * @crossplatform 167 * @atomicservice 168 * @since 12 169 */ 170 virtualScroll(virtualScrollOptions?: VirtualScrollOptions): RepeatAttribute<T>; 171 /** 172 * Type builder function to render specific type of data item. 173 * 174 * @param { string } type that defines the template id. 175 * @param { RepeatItemBuilder<T> } itemBuilder that defines UI builder function. 176 * @param { TemplateOptions } templateOptions that defines a builder template option parameter. 177 * @returns { RepeatAttribute<T> } 178 * @syscap SystemCapability.ArkUI.ArkUI.Full 179 * @crossplatform 180 * @atomicservice 181 * @since 12 182 */ 183 template(type : string, itemBuilder: RepeatItemBuilder<T>, templateOptions?: TemplateOptions): RepeatAttribute<T>; 184 /** 185 * Typed function to render specific type of data item. 186 * 187 * @param { TemplateTypedFunc<T> } typedFunc that define template typed function. 188 * @returns { RepeatAttribute<T> } 189 * @syscap SystemCapability.ArkUI.ArkUI.Full 190 * @crossplatform 191 * @atomicservice 192 * @since 12 193 */ 194 templateId(typedFunc: TemplateTypedFunc<T>): RepeatAttribute<T>; 195} 196 197/** 198 * Defines Repeat Component. 199 * 200 * @syscap SystemCapability.ArkUI.ArkUI.Full 201 * @crossplatform 202 * @form 203 * @atomicservice 204 * @since 12 205 */ 206declare const Repeat: <T>(arr: Array<T>) => RepeatAttribute<T>; 207