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
1861847f8eSopenharmony_ci * @kit ArkUI
1961847f8eSopenharmony_ci */
2061847f8eSopenharmony_ci
2161847f8eSopenharmony_ci/**
2261847f8eSopenharmony_ci * Implement this interface to provide data prefetching for the LazyForEach component.
2361847f8eSopenharmony_ci *
2461847f8eSopenharmony_ci * @interface IDataSourcePrefetching
2561847f8eSopenharmony_ci * @extends IDataSource
2661847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full
2761847f8eSopenharmony_ci * @crossplatform
2861847f8eSopenharmony_ci * @atomicservice
2961847f8eSopenharmony_ci * @since 12
3061847f8eSopenharmony_ci */
3161847f8eSopenharmony_ciexport interface IDataSourcePrefetching extends IDataSource {
3261847f8eSopenharmony_ci  /**
3361847f8eSopenharmony_ci   * Prefetches data for the specified element in the data collection.
3461847f8eSopenharmony_ci   * This method can be either synchronous or asynchronous.
3561847f8eSopenharmony_ci   *
3661847f8eSopenharmony_ci   * @param { number } index - Index of the item in the collection.
3761847f8eSopenharmony_ci   * @returns { Promise<void> | void }
3861847f8eSopenharmony_ci   * @syscap SystemCapability.ArkUI.ArkUI.Full
3961847f8eSopenharmony_ci   * @crossplatform
4061847f8eSopenharmony_ci   * @atomicservice
4161847f8eSopenharmony_ci   * @since 12
4261847f8eSopenharmony_ci   */
4361847f8eSopenharmony_ci  prefetch(index: number): Promise<void> | void;
4461847f8eSopenharmony_ci
4561847f8eSopenharmony_ci  /**
4661847f8eSopenharmony_ci   * Cancels prefetching data for the specified element in the data collection.
4761847f8eSopenharmony_ci   * This method can be either synchronous or asynchronous.
4861847f8eSopenharmony_ci   *
4961847f8eSopenharmony_ci   * @param { number } index - Index of the item in the collection.
5061847f8eSopenharmony_ci   * @returns { Promise<void> | void }
5161847f8eSopenharmony_ci   * @syscap SystemCapability.ArkUI.ArkUI.Full
5261847f8eSopenharmony_ci   * @crossplatform
5361847f8eSopenharmony_ci   * @atomicservice
5461847f8eSopenharmony_ci   * @since 12
5561847f8eSopenharmony_ci   */
5661847f8eSopenharmony_ci  cancel?(index: number): Promise<void> | void;
5761847f8eSopenharmony_ci}
5861847f8eSopenharmony_ci
5961847f8eSopenharmony_ci/**
6061847f8eSopenharmony_ci * Implement this interface to provide prefetcher logic.
6161847f8eSopenharmony_ci *
6261847f8eSopenharmony_ci * @interface IPrefetcher
6361847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full
6461847f8eSopenharmony_ci * @crossplatform
6561847f8eSopenharmony_ci * @atomicservice
6661847f8eSopenharmony_ci * @since 12
6761847f8eSopenharmony_ci */
6861847f8eSopenharmony_ciexport interface IPrefetcher {
6961847f8eSopenharmony_ci  /**
7061847f8eSopenharmony_ci   * Sets the data source to bind to this prefetcher.
7161847f8eSopenharmony_ci   *
7261847f8eSopenharmony_ci   * @param { IDataSourcePrefetching } dataSource - Data source that supports prefetching.
7361847f8eSopenharmony_ci   * @syscap SystemCapability.ArkUI.ArkUI.Full
7461847f8eSopenharmony_ci   * @crossplatform
7561847f8eSopenharmony_ci   * @atomicservice
7661847f8eSopenharmony_ci   * @since 12
7761847f8eSopenharmony_ci   */
7861847f8eSopenharmony_ci  setDataSource(dataSource: IDataSourcePrefetching): void;
7961847f8eSopenharmony_ci
8061847f8eSopenharmony_ci  /**
8161847f8eSopenharmony_ci   * Call this method when the visible area boundaries were changed.
8261847f8eSopenharmony_ci   *
8361847f8eSopenharmony_ci   * @param { number } minVisible - Index of the first visible data item.
8461847f8eSopenharmony_ci   * @param { number } maxVisible - Index of the last visible data item.
8561847f8eSopenharmony_ci   * @syscap SystemCapability.ArkUI.ArkUI.Full
8661847f8eSopenharmony_ci   * @crossplatform
8761847f8eSopenharmony_ci   * @atomicservice
8861847f8eSopenharmony_ci   * @since 12
8961847f8eSopenharmony_ci   */
9061847f8eSopenharmony_ci  visibleAreaChanged(minVisible: number, maxVisible: number): void;
9161847f8eSopenharmony_ci}
9261847f8eSopenharmony_ci
9361847f8eSopenharmony_ci/**
9461847f8eSopenharmony_ci * Basic implementation of {@link IPrefetcher}.
9561847f8eSopenharmony_ci * It provides an intelligent data prefetching algorithm to make decisions about which data
9661847f8eSopenharmony_ci * items should be prefetched in response to the real-time changes of visible on-screen area
9761847f8eSopenharmony_ci * and changes in the duration of the prefetching. It also determines which prefetch requests
9861847f8eSopenharmony_ci * should be canceled based on user scrolling actions.
9961847f8eSopenharmony_ci *
10061847f8eSopenharmony_ci * @implements IPrefetcher
10161847f8eSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full
10261847f8eSopenharmony_ci * @crossplatform
10361847f8eSopenharmony_ci * @atomicservice
10461847f8eSopenharmony_ci * @since 12
10561847f8eSopenharmony_ci */
10661847f8eSopenharmony_ciexport class BasicPrefetcher implements IPrefetcher {
10761847f8eSopenharmony_ci  /**
10861847f8eSopenharmony_ci   * Constructs a basic prefetcher instance and optionally sets the data source.
10961847f8eSopenharmony_ci   *
11061847f8eSopenharmony_ci   * @param { IDataSourcePrefetching } dataSource - Data source that supports prefetching.
11161847f8eSopenharmony_ci   * @syscap SystemCapability.ArkUI.ArkUI.Full
11261847f8eSopenharmony_ci   * @crossplatform
11361847f8eSopenharmony_ci   * @atomicservice
11461847f8eSopenharmony_ci   * @since 12
11561847f8eSopenharmony_ci   */
11661847f8eSopenharmony_ci  constructor(dataSource?: IDataSourcePrefetching);
11761847f8eSopenharmony_ci
11861847f8eSopenharmony_ci  /**
11961847f8eSopenharmony_ci   * Sets the data source to bind to this prefetcher.
12061847f8eSopenharmony_ci   *
12161847f8eSopenharmony_ci   * @param { IDataSourcePrefetching } dataSource - Data source that supports prefetching.
12261847f8eSopenharmony_ci   * @syscap SystemCapability.ArkUI.ArkUI.Full
12361847f8eSopenharmony_ci   * @crossplatform
12461847f8eSopenharmony_ci   * @atomicservice
12561847f8eSopenharmony_ci   * @since 12
12661847f8eSopenharmony_ci   */
12761847f8eSopenharmony_ci  setDataSource(dataSource: IDataSourcePrefetching): void;
12861847f8eSopenharmony_ci
12961847f8eSopenharmony_ci  /**
13061847f8eSopenharmony_ci   * Call this method when the visible area changed.
13161847f8eSopenharmony_ci   *
13261847f8eSopenharmony_ci   * @param { number } minVisible - Index of the first visible data item.
13361847f8eSopenharmony_ci   * @param { number } maxVisible - Index of the last visible data item.
13461847f8eSopenharmony_ci   * @syscap SystemCapability.ArkUI.ArkUI.Full
13561847f8eSopenharmony_ci   * @crossplatform
13661847f8eSopenharmony_ci   * @atomicservice
13761847f8eSopenharmony_ci   * @since 12
13861847f8eSopenharmony_ci   */
13961847f8eSopenharmony_ci  visibleAreaChanged(minVisible: number, maxVisible: number): void;
14061847f8eSopenharmony_ci}
141