From a4b0228720f271ed145721ea8335dbd6fcd1ffc2 Mon Sep 17 00:00:00 2001 From: liubihao Date: Thu, 7 Aug 2025 16:33:13 +0800 Subject: [PATCH] add arkts_1.2 spec for prefetcher. Signed-off-by: liubihao --- api/@ohos.arkui.Prefetcher.static.d.ets | 121 ++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 api/@ohos.arkui.Prefetcher.static.d.ets diff --git a/api/@ohos.arkui.Prefetcher.static.d.ets b/api/@ohos.arkui.Prefetcher.static.d.ets new file mode 100644 index 00000000000..c174af04541 --- /dev/null +++ b/api/@ohos.arkui.Prefetcher.static.d.ets @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2025 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 + * @kit ArkUI + * @arkts 1.2 + */ + +/** + * Implement this interface to provide data prefetching for the LazyForEach component. + * + * @extends IDataSource + * @interface IDataSourcePrefetching + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +export interface IDataSourcePrefetching extends IDataSource { + /** + * Prefetches data for the specified element in the data collection. + * This method can be either synchronous or asynchronous. + * + * @param { int } index - Index of the item in the collection. + * @returns { Promise | void } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + prefetch(index: int): Promise | void; + + /** + * Cancels prefetching data for the specified element in the data collection. + * This method can be either synchronous or asynchronous. + * + * @param { int } index - Index of the item in the collection. + * @returns { Promise | void } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + cancel?(index: int): Promise | void; +} + +/** + * Implement this interface to provide prefetcher logic. + * + * @interface IPrefetcher + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +export interface IPrefetcher { + /** + * Sets the data source to bind to this prefetcher. + * + * @param { IDataSourcePrefetching } dataSource - Data source that supports prefetching. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + setDataSource(dataSource: IDataSourcePrefetching): void; + + /** + * Call this method when the visible area boundaries were changed. + * + * @param { int } minVisible - Index of the first visible data item. + * @param { int } maxVisible - Index of the last visible data item. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + visibleAreaChanged(minVisible: int, maxVisible: int): void; +} + +/** + * Basic implementation of {@link IPrefetcher}. + * It provides an intelligent data prefetching algorithm to make decisions about which data + * items should be prefetched in response to the real-time changes of visible on-screen area + * and changes in the duration of the prefetching. It also determines which prefetch requests + * should be canceled based on user scrolling actions. + * + * @implements IPrefetcher + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +export class BasicPrefetcher implements IPrefetcher { + /** + * Constructs a basic prefetcher instance and optionally sets the data source. + * + * @param { IDataSourcePrefetching } [dataSource] - Data source that supports prefetching. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + constructor(dataSource?: IDataSourcePrefetching); + + /** + * Sets the data source to bind to this prefetcher. + * + * @param { IDataSourcePrefetching } dataSource - Data source that supports prefetching. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + setDataSource(dataSource: IDataSourcePrefetching): void; + + /** + * Call this method when the visible area changed. + * + * @param { int } minVisible - Index of the first visible data item. + * @param { int } maxVisible - Index of the last visible data item. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + visibleAreaChanged(minVisible: int, maxVisible: int): void; +} -- Gitee