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 18 * @kit ArkUI 19 */ 20 21/** 22 * Implement this interface to provide data prefetching for the LazyForEach component. 23 * 24 * @interface IDataSourcePrefetching 25 * @extends IDataSource 26 * @syscap SystemCapability.ArkUI.ArkUI.Full 27 * @crossplatform 28 * @atomicservice 29 * @since 12 30 */ 31export interface IDataSourcePrefetching extends IDataSource { 32 /** 33 * Prefetches data for the specified element in the data collection. 34 * This method can be either synchronous or asynchronous. 35 * 36 * @param { number } index - Index of the item in the collection. 37 * @returns { Promise<void> | void } 38 * @syscap SystemCapability.ArkUI.ArkUI.Full 39 * @crossplatform 40 * @atomicservice 41 * @since 12 42 */ 43 prefetch(index: number): Promise<void> | void; 44 45 /** 46 * Cancels prefetching data for the specified element in the data collection. 47 * This method can be either synchronous or asynchronous. 48 * 49 * @param { number } index - Index of the item in the collection. 50 * @returns { Promise<void> | void } 51 * @syscap SystemCapability.ArkUI.ArkUI.Full 52 * @crossplatform 53 * @atomicservice 54 * @since 12 55 */ 56 cancel?(index: number): Promise<void> | void; 57} 58 59/** 60 * Implement this interface to provide prefetcher logic. 61 * 62 * @interface IPrefetcher 63 * @syscap SystemCapability.ArkUI.ArkUI.Full 64 * @crossplatform 65 * @atomicservice 66 * @since 12 67 */ 68export interface IPrefetcher { 69 /** 70 * Sets the data source to bind to this prefetcher. 71 * 72 * @param { IDataSourcePrefetching } dataSource - Data source that supports prefetching. 73 * @syscap SystemCapability.ArkUI.ArkUI.Full 74 * @crossplatform 75 * @atomicservice 76 * @since 12 77 */ 78 setDataSource(dataSource: IDataSourcePrefetching): void; 79 80 /** 81 * Call this method when the visible area boundaries were changed. 82 * 83 * @param { number } minVisible - Index of the first visible data item. 84 * @param { number } maxVisible - Index of the last visible data item. 85 * @syscap SystemCapability.ArkUI.ArkUI.Full 86 * @crossplatform 87 * @atomicservice 88 * @since 12 89 */ 90 visibleAreaChanged(minVisible: number, maxVisible: number): void; 91} 92 93/** 94 * Basic implementation of {@link IPrefetcher}. 95 * It provides an intelligent data prefetching algorithm to make decisions about which data 96 * items should be prefetched in response to the real-time changes of visible on-screen area 97 * and changes in the duration of the prefetching. It also determines which prefetch requests 98 * should be canceled based on user scrolling actions. 99 * 100 * @implements IPrefetcher 101 * @syscap SystemCapability.ArkUI.ArkUI.Full 102 * @crossplatform 103 * @atomicservice 104 * @since 12 105 */ 106export class BasicPrefetcher implements IPrefetcher { 107 /** 108 * Constructs a basic prefetcher instance and optionally sets the data source. 109 * 110 * @param { IDataSourcePrefetching } dataSource - Data source that supports prefetching. 111 * @syscap SystemCapability.ArkUI.ArkUI.Full 112 * @crossplatform 113 * @atomicservice 114 * @since 12 115 */ 116 constructor(dataSource?: IDataSourcePrefetching); 117 118 /** 119 * Sets the data source to bind to this prefetcher. 120 * 121 * @param { IDataSourcePrefetching } dataSource - Data source that supports prefetching. 122 * @syscap SystemCapability.ArkUI.ArkUI.Full 123 * @crossplatform 124 * @atomicservice 125 * @since 12 126 */ 127 setDataSource(dataSource: IDataSourcePrefetching): void; 128 129 /** 130 * Call this method when the visible area changed. 131 * 132 * @param { number } minVisible - Index of the first visible data item. 133 * @param { number } maxVisible - Index of the last visible data item. 134 * @syscap SystemCapability.ArkUI.ArkUI.Full 135 * @crossplatform 136 * @atomicservice 137 * @since 12 138 */ 139 visibleAreaChanged(minVisible: number, maxVisible: number): void; 140} 141