From 3fb001d05f2a700ea677556c9aa081e4693d1dfa Mon Sep 17 00:00:00 2001 From: aziztek Date: Fri, 15 Aug 2025 19:26:13 +0300 Subject: [PATCH] Add UpdatablePickerOptions support to dynamically update picker settings at runtime Signed-off-by: aziztek --- api/@ohos.file.PhotoPickerComponent.d.ets | 162 ++++++++++++++++++++++ kits/@kit.MediaLibraryKit.d.ts | 4 +- 2 files changed, 164 insertions(+), 2 deletions(-) diff --git a/api/@ohos.file.PhotoPickerComponent.d.ets b/api/@ohos.file.PhotoPickerComponent.d.ets index 52885ab0e0..35c7db4ff7 100644 --- a/api/@ohos.file.PhotoPickerComponent.d.ets +++ b/api/@ohos.file.PhotoPickerComponent.d.ets @@ -301,6 +301,16 @@ export declare class PickerController { */ saveTrustedPhotoAssets(trustedUris: Array, callback: AsyncCallback>, configs?: Array, saveMode?: SaveMode): void; + + /** + * Update picker options + * + * @param { UpdatablePickerOptions } updatablePickerOptions - for update picker options + * @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @atomicservice + * @since 20 + */ + updatePickerOptions(updatablePickerOptions: UpdatablePickerOptions): Promise; } /** @@ -688,6 +698,158 @@ export declare class SingleLineConfig { itemGap?: Length; } +/** + * UpdatablePickerOptions + * + * Dynamic options that can be applied to PhotoPickerComponent at runtime. + * Use this to adjust filtering, selection limits, visuals and behavior without + * recreating the component. + * + * @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @atomicservice + * @since 20 + */ +export declare class UpdatablePickerOptions { + /** + * MIME types to display in the picker (photos, videos or both). + * + * @type { ?photoAccessHelper.PhotoViewMIMETypes } + * @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @atomicservice + * @since 20 + */ + MIMEType?: photoAccessHelper.PhotoViewMIMETypes; + + /** + * Fine-grained MIME type filter. When set, only items matching the filter are shown. + * Takes effect together with MIMEType; the intersection is applied. + * + * @type { ?photoAccessHelper.MimeTypeFilter } + * @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @atomicservice + * @since 20 + */ + mimeTypeFilter?: photoAccessHelper.MimeTypeFilter; + + /** + * Maximum total number of selectable items (photos + videos). + * If both per-type limits and this value are set, the strictest limit applies. + * + * @type { ?number } + * @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @atomicservice + * @since 20 + */ + maxSelectNumber?: number; + + /** + * Maximum number of selectable photos. + * + * @type { ?number } + * @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @atomicservice + * @since 20 + */ + maxPhotoSelectNumber?: number; + + /** + * Maximum number of selectable videos. + * + * @type { ?number } + * @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @atomicservice + * @since 20 + */ + maxVideoSelectNumber?: number; + + /** + * Selection mode for the picker grid and detail pages. + * Controls whether selection happens in grid, browser, or both. + * + * @type { ?SelectMode } + * @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @atomicservice + * @since 20 + */ + selectMode?: SelectMode; + + /** + * Single-selection behavior when SelectMode enforces single item selection. + * Defines how single selection is presented and toggled. + * + * @type { ?SingleSelectMode } + * @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @atomicservice + * @since 20 + */ + singleSelectionMode?: photoAccessHelper.SingleSelectionMode; + + /** + * Whether the same item can be selected repeatedly. If disabled, selecting an + * already-selected item has no effect; if enabled, re-selection may trigger + * selection callbacks again. + * + * @type { ?boolean } + * @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @atomicservice + * @since 20 + */ + isRepeatSelectSupported?: boolean; + + /** + * Initial or updated list of preselected item URIs. + * When set, the picker will reflect these items as selected. + * Behavior with existing selections depends on component policy (merge/replace). + * + * @type { ?Array } + * @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @atomicservice + * @since 20 + */ + preselectedUris?: Array; + + /** + * Checkbox fill/border color used for selection indicators. + * + * @type { ?string } + * @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @atomicservice + * @since 20 + */ + checkBoxColor?: string; + + /** + * Checkbox text/label color (e.g., count badges). + * + * @type { ?string } + * @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @atomicservice + * @since 20 + */ + checkBoxTextColor?: string; + + /** + * Background color of the picker grid surfaces. + * + * @type { ?string } + * @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @atomicservice + * @since 20 + */ + backgroundColor?: string; + + /** + * Background color mode for the photo browser (detail view). + * Useful for switching between light/dark/adaptive modes. + * + * @type { ?PickerColorMode } + * @syscap SystemCapability.FileManagement.PhotoAccessHelper.Core + * @atomicservice + * @since 20 + */ + photoBrowserBackgroundColorMode?: PickerColorMode; +} + /** * DataType represents the type of the data set to picker component * diff --git a/kits/@kit.MediaLibraryKit.d.ts b/kits/@kit.MediaLibraryKit.d.ts index 901d6bec14..a0c03acc66 100644 --- a/kits/@kit.MediaLibraryKit.d.ts +++ b/kits/@kit.MediaLibraryKit.d.ts @@ -27,7 +27,7 @@ import { DataType, BaseItemInfo, ItemInfo, PhotoBrowserInfo, AnimatorParams, MaxSelected, ItemType, ClickType, PickerOrientation, SelectMode, PickerColorMode, ReminderMode, MaxCountType, PhotoBrowserRange, - PhotoBrowserUIElement, ItemsDeletedCallback, ExceedMaxSelectedCallback, CurrentAlbumDeletedCallback + PhotoBrowserUIElement, ItemsDeletedCallback, ExceedMaxSelectedCallback, CurrentAlbumDeletedCallback, UpdatablePickerOptions } from '@ohos.file.PhotoPickerComponent'; import { RecentPhotoComponent, RecentPhotoCheckResultCallback, @@ -43,5 +43,5 @@ export { AlbumPickerComponent, AlbumPickerOptions, AlbumInfo, EmptyAreaClickCallback, AlbumPickerController, RecentPhotoComponent, RecentPhotoCheckResultCallback, RecentPhotoClickCallback, RecentPhotoOptions, PhotoSource, - PhotoBrowserUIElement, ItemsDeletedCallback, ExceedMaxSelectedCallback, CurrentAlbumDeletedCallback + PhotoBrowserUIElement, ItemsDeletedCallback, ExceedMaxSelectedCallback, CurrentAlbumDeletedCallback, UpdatablePickerOptions }; -- Gitee