1e41f4b71Sopenharmony_ci# @ohos.file.PhotoPickerComponent (PhotoPickerComponent)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **PhotoPickerComponent** component embedded in the UI of an application allows the application to access images or video files in the user directory without any permission. This component grants the application only the read permission.
4e41f4b71Sopenharmony_ciThe user can directly tap this component to select images or videos.
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci> **NOTE**
7e41f4b71Sopenharmony_ci>
8e41f4b71Sopenharmony_ci> This component is supported since API version 12. Updates will be marked with a superscript to indicate their earliest API version.
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Modules to Import
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci```ts
13e41f4b71Sopenharmony_ciimport {
14e41f4b71Sopenharmony_ci  PhotoPickerComponent, PickerController, PickerOptions,
15e41f4b71Sopenharmony_ci  DataType, BaseItemInfo, ItemInfo, PhotoBrowserInfo, AnimatorParams,
16e41f4b71Sopenharmony_ci  MaxSelected, ItemType, ClickType, PickerOrientation,
17e41f4b71Sopenharmony_ci  SelectMode, PickerColorMode, ReminderMode, MaxCountType, PhotoBrowserRange
18e41f4b71Sopenharmony_ci} from '@ohos.file.PhotoPickerComponent';
19e41f4b71Sopenharmony_ci```
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci## Properties
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ciThe [universal properties](../apis-arkui/arkui-ts/ts-universal-attributes-size.md) are supported.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci## PhotoPickerComponent
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ciPhotoPickerComponent({
28e41f4b71Sopenharmony_ci  pickerOptions?: PickerOptions,
29e41f4b71Sopenharmony_ci  onSelect?: (uri: string) => void,
30e41f4b71Sopenharmony_ci  onDeselect?: (uri: string) => void,
31e41f4b71Sopenharmony_ci  onItemClicked?: (itemInfo: ItemInfo, clickType: ClickType) => boolean,
32e41f4b71Sopenharmony_ci  onEnterPhotoBrowser?: (photoBrowserInfo: PhotoBrowserInfo) => boolean,
33e41f4b71Sopenharmony_ci  onExitPhotoBrowser?: (photoBrowserInfo: PhotoBrowserInfo) => boolean,
34e41f4b71Sopenharmony_ci  onPickerControllerReady?: () => void,
35e41f4b71Sopenharmony_ci  onPhotoBrowserChanged?: (browserItemInfo: BaseItemInfo) => boolean,
36e41f4b71Sopenharmony_ci  pickerController: PickerController
37e41f4b71Sopenharmony_ci})
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ciAllows the application to access images or video files in the user directory without any permission.
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci> **NOTE**
42e41f4b71Sopenharmony_ci> 
43e41f4b71Sopenharmony_ci>If **PhotoPickerComponent** is used with the **Tabs** component, the swipe gestures of the **Tabs** component conflict with those of the photo browser page. To prevent this problem, you can disable the swipe operation for the **Tabs** component in **onEnterPhotoBrowser()** and enable it in **onExitPhotoBrowser()**. This conflict will be resolved in later versions.
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci**Decorator**: @Component
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci**Parameters**
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci| Name         | Type           | Mandatory | Decorator Description     | Description      |
54e41f4b71Sopenharmony_ci|---------------|----------------|-----|------------|--------------------------|
55e41f4b71Sopenharmony_ci| pickerOptions  | [PickerOptions](#pickeroptions)       | No  | - | Configuration of Picker. |
56e41f4b71Sopenharmony_ci| onSelect       | (uri: string) => void                 | No  | - | Callback to be invoked when an image is selected by using **PhotoPickerComponent**. This callback returns the URI of the image selected to the application.            |
57e41f4b71Sopenharmony_ci| onDeselect     | (uri: string) => void                 | No  | - | Callback to be invoked when an image is deselected by using **PhotoPickerComponent**. This callback returns the URI of the image deselected to the application. |
58e41f4b71Sopenharmony_ci| onItemClicked  | (itemInfo: [ItemInfo](#iteminfo), clickType: [ClickType](#clicktype)) => boolean  | No  | - | Callback to be invoked when an item in a Picker component is clicked.<br>For an image (thumbnail item), if **true** is returned, the image is selected. Otherwise, the image is not selected and the URI is not granted with the permission. For a camera item, if **true** is returned, the system camera is started. Otherwise, the camera is not started and the application handles the request.|
59e41f4b71Sopenharmony_ci| onEnterPhotoBrowser | (photoBrowserInfo: [PhotoBrowserInfo](#photobrowserinfo)) => boolean   | No  | - | Callback to be invoked when the photo browser page is displayed. The callback returns photo browser information to the application.  |
60e41f4b71Sopenharmony_ci| onExitPhotoBrowser | (photoBrowserInfo: [PhotoBrowserInfo](#photobrowserinfo)) => boolean   | No  | - | Callback to be invoked when the photo browser page exits. The callback returns photo browser information to the application.          |
61e41f4b71Sopenharmony_ci| onPickerControllerReady | () => void   | No  | - | Callback to be invoked when **pickerController** is available.<br>The **PickerController** APIs can be called only after this callback is invoked.         |
62e41f4b71Sopenharmony_ci| onPhotoBrowserChanged | (browserItemInfo: [BaseItemInfo](#baseiteminfo)) => boolean   | No  | - | Callback to be invoked when the photo browser page is swiped left or right. The callback returns photo browser information to the application.          |
63e41f4b71Sopenharmony_ci| pickerController         | [PickerController](#pickercontroller) | No  | @ObjectLink | Instance used to send data to **PhotoPickerComponent**.              |
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci## PickerOptions
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ciDefines the configuration of Picker. It inherits from [BaseSelectOptions](js-apis-photoAccessHelper.md#baseselectoptions12).
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci 
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci| Name                    | Type                                     | Mandatory | Description  |
76e41f4b71Sopenharmony_ci|-------------------------|-----------------------------------------|-----|--------|
77e41f4b71Sopenharmony_ci| checkBoxColor                 | string                                  | No  | Background color of the check box. The value is an 8-digit hexadecimal color code.                              |
78e41f4b71Sopenharmony_ci| backgroundColor               | string                                  | No  | Background color of the Picker grid page. The value is an 8-digit hexadecimal color code.                        |
79e41f4b71Sopenharmony_ci| isRepeatSelectSupported       | boolean                                 | No  | Whether to support repeated selection of a single image. The value **true** means a single image can be repeatedly selected.                              |
80e41f4b71Sopenharmony_ci| checkboxTextColor             | string                                  | No  | Text color in the check box. The value is an 8-digit hexadecimal color code. (This capability is not supported currently.)                            |
81e41f4b71Sopenharmony_ci| photoBrowserBackgroundColorMode | [PickerColorMode](#pickercolormode)     | No  | Background color of the photo browser page. The options are **AUTO**, **LIGHT**, and **DARK**. The default value is **AUTO**.               |
82e41f4b71Sopenharmony_ci| maxSelectedReminderMode | [ReminderMode](#remindermode)           | No  | Mode of the reminder when the number of selected items reaches the maximum. The options are **NONE**, **TOAST**, and **MASK**. The default value **TOAST**.|
83e41f4b71Sopenharmony_ci| orientation                   | [PickerOrientation](#pickerorientation) | No  | Sliding preview direction of the grid page. The options are **HORIZONTAL** and **VERTICAL**. The default value is **VERTICAL**. (This capability is not supported currently.)                 |
84e41f4b71Sopenharmony_ci| selectMode                    | [SelectMode](#selectmode)               | No  | Select mode, which can be **SINGLE_SELECT** or **MULTI_SELECT**. The default value is **MULTI_SELECT**.                             |
85e41f4b71Sopenharmony_ci| maxPhotoSelectNumber          | number                                  | No  | Maximum number of images that can be selected. The maximum value is **500**, which is limited by **MaxSelected**.              |
86e41f4b71Sopenharmony_ci| maxVideoSelectNumber          | number                                  | No  | Maximum number of videos that can be selected. The maximum value is **500**, which is limited by **MaxSelected**.              |
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci## PickerController
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ciDefines an instance used to send data to the **PhotoPicker** component.
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci**Decorator Type**: @Observed
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci### setData
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_cisetData(dataType: DataType, data: Object): void
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ciSends data to **PhotoPickerComponent**. **DataType** specifies the type of data to be sent.
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci**Parameters**
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci|  Name       | Type                                   | Mandatory | Description |
111e41f4b71Sopenharmony_ci| ------------------------- | ------------------ | ----- | --------------- |
112e41f4b71Sopenharmony_ci| dataType | [DataType](#datatype) | Yes| Type of the data to send.|
113e41f4b71Sopenharmony_ci| data | Object | Yes| Data to send.|
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci### setMaxSelected
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_cisetMaxSelected(maxSelected: MaxSelected): void
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ciSets the maximum number of images, maximum number of videos, and maximum number of total media assets that can be selected on a real-time basis.
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci**Parameters**
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci|  Name       | Type                                   | Mandatory | Description    |
128e41f4b71Sopenharmony_ci| ------------------------- | ------------------ | ----- | --------------- |
129e41f4b71Sopenharmony_ci| maxSelected | [MaxSelected](#maxselected) | Yes| Maximum number of items that can be selected at a time.|
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci### setPhotoBrowserItem
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_cisetPhotoBrowserItem(uri: string, photoBrowserRange?: PhotoBrowserRange): void
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ciSwitches from the Picker component to the photo browser page or from the photo browser page to the image to be viewed.
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci**Parameters**
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci|  Name       | Type                                   | Mandatory | Description |
144e41f4b71Sopenharmony_ci| ------------------------- | ------------------ | ----- | --------------- |
145e41f4b71Sopenharmony_ci| uri | string | Yes| URI of the image to view. Only the images selected by the user are supported.|
146e41f4b71Sopenharmony_ci| photoBrowserRange | [PhotoBrowserRange](#photobrowserrange) | No| View range on the photo browser page. The value can be **ALL** or **SELECTED_ONLY**. The default value is **ALL**, which means to view all images and videos.|
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci## BaseItemInfo
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ciRepresents image and video information.
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci| Name    | Type   | Mandatory | Description                                               |
157e41f4b71Sopenharmony_ci|----------|--------|-----|---------------------------------------------------|
158e41f4b71Sopenharmony_ci| uri      | string                | No  | Image or video URI. This parameter is mandatory when **itemType** is **THUMBNAIL**. Otherwise, it is left empty.           |
159e41f4b71Sopenharmony_ci| mimeType | string                | No  | MIME type of the image or video. This parameter is mandatory when **itemType** is **THUMBNAIL**. Otherwise, it is left empty.      |
160e41f4b71Sopenharmony_ci| width    | number                | No  | Width of the image or video, in pixels. This parameter is mandatory when **itemType** is **THUMBNAIL**. Otherwise, it is left empty.      |
161e41f4b71Sopenharmony_ci| height   | number                | No  | Height of the image or video, in pixels. This parameter is mandatory when **itemType** is **THUMBNAIL**. Otherwise, it is left empty.      |
162e41f4b71Sopenharmony_ci| size     | number                | No  | Size of the image or video, in kilobytes. This parameter is mandatory when **itemType** is **THUMBNAIL**. Otherwise, it is left empty.    |
163e41f4b71Sopenharmony_ci| duration   | number                | No  | Video duration, in ms. This parameter is mandatory when **itemType** is **THUMBNAIL**. Otherwise, it is left empty.<br>The value **-1** indicates an image.|
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ci## ItemInfo
166e41f4b71Sopenharmony_ci
167e41f4b71Sopenharmony_ciRepresents image and video information. It inherits from **BaseItemInfo** and contains only the parameter **itemType**.
168e41f4b71Sopenharmony_ci
169e41f4b71Sopenharmony_ci 
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
174e41f4b71Sopenharmony_ci
175e41f4b71Sopenharmony_ci| Name    | Type   | Mandatory | Description                                               |
176e41f4b71Sopenharmony_ci|----------|--------|-----|---------------------------------------------------|
177e41f4b71Sopenharmony_ci| itemType | [ItemType](#itemtype) | No  | Type of the item clicked, which can be **THUMBNAIL** or **CAMERA**.                     |
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_ci## PhotoBrowserInfo
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ciRepresents information about the photo browser page.
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci| Name    | Type   | Mandatory | Description    |
188e41f4b71Sopenharmony_ci|----------|--------|-----|---------|
189e41f4b71Sopenharmony_ci| animatorParams | [AnimatorParams](#animatorparams) | No  | Parameters for the animation for entering or exiting the photo browser page.|
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ci## AnimatorParams
192e41f4b71Sopenharmony_ci
193e41f4b71Sopenharmony_ciAnimation parameters for entering or exiting the photo browser page.
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
196e41f4b71Sopenharmony_ci
197e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
198e41f4b71Sopenharmony_ci
199e41f4b71Sopenharmony_ci| Name    | Type   | Mandatory | Description          |
200e41f4b71Sopenharmony_ci|----------|--------|-----|--------------|
201e41f4b71Sopenharmony_ci| duration | number  | No           | Animation duration, in ms.|
202e41f4b71Sopenharmony_ci| curve      | [Curve](../apis-arkui/js-apis-curve.md#curve) &verbar; [ICurve](../apis-arkui/js-apis-curve.md#icurve9) &verbar; string | No  | Animation curve.       |
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci## MaxSelected
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_ciMaximum number of items that can be selected at a time.
207e41f4b71Sopenharmony_ci
208e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
209e41f4b71Sopenharmony_ci
210e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_ci| Name    | Type   | Mandatory | Description    |
213e41f4b71Sopenharmony_ci|----------|--------|-----|---------|
214e41f4b71Sopenharmony_ci| data | Map&lt;[MaxCountType](#maxcounttype), number&gt; | No            | Maximum number of images that can be selected, maximum number of videos that can be selected, and maximum number of total items that can be selected.|
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_ci## DataType
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ciEnumerates the types of data sent from **PickerController** to the **PhotoPicker** component.
219e41f4b71Sopenharmony_ci
220e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
221e41f4b71Sopenharmony_ci
222e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
223e41f4b71Sopenharmony_ci
224e41f4b71Sopenharmony_ci| Name               | Value  | Description                                                                                                                |
225e41f4b71Sopenharmony_ci|-------------------|-----|--------------------------------------------------------------------------------------------------------------------|
226e41f4b71Sopenharmony_ci| SET_SELECTED_URIS | 1   | Send a list of selected items to instruct the Picker component to refresh the selection status. A string array needs to be passed in.<br>For example, after an image is deleted from an application's page, the application calls **setData()** to notify the Picker component of the remaining selected items. Then, the Picker component refreshes the check box status.|
227e41f4b71Sopenharmony_ci| SET_ALBUM_URI | 2   | Maximum number of images that can be selected, maximum number of videos that can be selected, and maximum number of total items that can be selected.|
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ci## ItemType
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ciEnumerates the types of the item clicked.
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
236e41f4b71Sopenharmony_ci
237e41f4b71Sopenharmony_ci| Name               | Value  | Description        |
238e41f4b71Sopenharmony_ci|-------------------|-----|------------|
239e41f4b71Sopenharmony_ci| THUMBNAIL | 0   | Image or video (thumbnail).|
240e41f4b71Sopenharmony_ci| CAMERA | 1   | Camera item.   |
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci## ClickType
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ciEnumerates the click operation types.
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
249e41f4b71Sopenharmony_ci
250e41f4b71Sopenharmony_ci| Name               | Value  | Description                    |
251e41f4b71Sopenharmony_ci|-------------------|-----|------------------------|
252e41f4b71Sopenharmony_ci| SELECTED | 0   | Select (select an image or click a camera item).|
253e41f4b71Sopenharmony_ci| DESELECTED | 1   | Deselect (deselect an image).      |
254e41f4b71Sopenharmony_ci
255e41f4b71Sopenharmony_ci## PickerOrientation
256e41f4b71Sopenharmony_ci
257e41f4b71Sopenharmony_ciEnumerates the sliding preview directions of the Picker grid page. (This capability is not supported currently.)
258e41f4b71Sopenharmony_ci
259e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
260e41f4b71Sopenharmony_ci
261e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ci| Name               | Value  | Description   |
264e41f4b71Sopenharmony_ci|-------------------|-----|-------|
265e41f4b71Sopenharmony_ci| VERTICAL | 0   | Vertical direction.|
266e41f4b71Sopenharmony_ci| HORIZONTAL | 1   | Horizontal direction.|
267e41f4b71Sopenharmony_ci
268e41f4b71Sopenharmony_ci## SelectMode
269e41f4b71Sopenharmony_ci
270e41f4b71Sopenharmony_ciEnumerates the select modes.
271e41f4b71Sopenharmony_ci
272e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
273e41f4b71Sopenharmony_ci
274e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
275e41f4b71Sopenharmony_ci
276e41f4b71Sopenharmony_ci| Name               | Value  | Description   |
277e41f4b71Sopenharmony_ci|-------------------|-----|-------|
278e41f4b71Sopenharmony_ci| SINGLE_SELECT | 0   | Select a single option.|
279e41f4b71Sopenharmony_ci| MULTI_SELECT | 1   | Select multiple options.|
280e41f4b71Sopenharmony_ci
281e41f4b71Sopenharmony_ci## PickerColorMode
282e41f4b71Sopenharmony_ci
283e41f4b71Sopenharmony_ciEnumerates the Picker color modes.
284e41f4b71Sopenharmony_ci
285e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
286e41f4b71Sopenharmony_ci
287e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
288e41f4b71Sopenharmony_ci
289e41f4b71Sopenharmony_ci| Name               | Value  | Description   |
290e41f4b71Sopenharmony_ci|-------------------|-----|-------|
291e41f4b71Sopenharmony_ci| AUTO | 0   | Same with the system.|
292e41f4b71Sopenharmony_ci| LIGHT | 1   | Light mode.|
293e41f4b71Sopenharmony_ci| DARK | 2   | Dark mode.|
294e41f4b71Sopenharmony_ci
295e41f4b71Sopenharmony_ci## ReminderMode
296e41f4b71Sopenharmony_ci
297e41f4b71Sopenharmony_ciEnumerates the types of the reminder when the number of selected items reaches the maximum.
298e41f4b71Sopenharmony_ci
299e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
300e41f4b71Sopenharmony_ci
301e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
302e41f4b71Sopenharmony_ci
303e41f4b71Sopenharmony_ci| Name               | Value  | Description       |
304e41f4b71Sopenharmony_ci|-------------------|-----|-----------|
305e41f4b71Sopenharmony_ci| NONE | 0   | No reminder.     |
306e41f4b71Sopenharmony_ci| TOAST | 1   | Toast message.|
307e41f4b71Sopenharmony_ci| MASK | 2   | Grayed-out hint.    |
308e41f4b71Sopenharmony_ci
309e41f4b71Sopenharmony_ci## MaxCountType
310e41f4b71Sopenharmony_ci
311e41f4b71Sopenharmony_ciEnumerates the types of the maximum count.
312e41f4b71Sopenharmony_ci
313e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
314e41f4b71Sopenharmony_ci
315e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
316e41f4b71Sopenharmony_ci
317e41f4b71Sopenharmony_ci| Name               | Value  | Description                       |
318e41f4b71Sopenharmony_ci|-------------------|-----|---------------------------|
319e41f4b71Sopenharmony_ci| TOTAL_MAX_COUNT | 0   | Maximum number of total items that can be selected.                |
320e41f4b71Sopenharmony_ci| PHOTO_MAX_COUNT | 1   | Maximum number of images that can be selected. The value cannot be greater than **Total_MAX_Count**.|
321e41f4b71Sopenharmony_ci| VIDEO_MAX_COUNT | 2   | Maximum number of videos that can be selected. The value cannot be greater than **Total_MAX_Count**.|
322e41f4b71Sopenharmony_ci
323e41f4b71Sopenharmony_ci## PhotoBrowserRange
324e41f4b71Sopenharmony_ci
325e41f4b71Sopenharmony_ciEnumerates the view range on the photo browser page.
326e41f4b71Sopenharmony_ci
327e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
328e41f4b71Sopenharmony_ci
329e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
330e41f4b71Sopenharmony_ci
331e41f4b71Sopenharmony_ci| Name               | Value  | Description                       |
332e41f4b71Sopenharmony_ci|-------------------|-----|---------------------------|
333e41f4b71Sopenharmony_ci| ALL | 0   | View all images and videos.                |
334e41f4b71Sopenharmony_ci| SELECTED_ONLY | 1   | View selected images and videos only.|
335e41f4b71Sopenharmony_ci
336e41f4b71Sopenharmony_ci## Example
337e41f4b71Sopenharmony_ci
338e41f4b71Sopenharmony_ci```ts
339e41f4b71Sopenharmony_ci// xxx.ets
340e41f4b71Sopenharmony_ciimport {
341e41f4b71Sopenharmony_ci  PhotoPickerComponent, PickerController, PickerOptions,
342e41f4b71Sopenharmony_ci  DataType, BaseItemInfo, ItemInfo, PhotoBrowserInfo, AnimatorParams,
343e41f4b71Sopenharmony_ci  MaxSelected, ItemType, ClickType, PickerOrientation,
344e41f4b71Sopenharmony_ci  SelectMode, PickerColorMode, ReminderMode, MaxCountType, PhotoBrowserRange
345e41f4b71Sopenharmony_ci} from '@ohos.file.PhotoPickerComponent';
346e41f4b71Sopenharmony_ciimport photoAccessHelper from '@ohos.file.photoAccessHelper';
347e41f4b71Sopenharmony_ci
348e41f4b71Sopenharmony_ci@Entry
349e41f4b71Sopenharmony_ci@Component
350e41f4b71Sopenharmony_cistruct PickerDemo {
351e41f4b71Sopenharmony_ci  pickerOptions: PickerOptions = new PickerOptions();
352e41f4b71Sopenharmony_ci  @State pickerController: PickerController = new PickerController();
353e41f4b71Sopenharmony_ci  @State selectUris: Array<string> = new Array<string>();
354e41f4b71Sopenharmony_ci  @State currentUri: string = '';
355e41f4b71Sopenharmony_ci  @State isBrowserShow: boolean = false;
356e41f4b71Sopenharmony_ci
357e41f4b71Sopenharmony_ci  aboutToAppear() {
358e41f4b71Sopenharmony_ci    this.pickerOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_VIDEO_TYPE;
359e41f4b71Sopenharmony_ci    this.pickerOptions.maxSelectNumber = 5;
360e41f4b71Sopenharmony_ci    this.pickerOptions.isSearchSupported = false;
361e41f4b71Sopenharmony_ci    this.pickerOptions.isPhotoTakingSupported = false;
362e41f4b71Sopenharmony_ci    // Other attributes
363e41f4b71Sopenharmony_ci  }
364e41f4b71Sopenharmony_ci  
365e41f4b71Sopenharmony_ci  private onSelect(uri: string): void {
366e41f4b71Sopenharmony_ci    // Add
367e41f4b71Sopenharmony_ci    if (uri) {
368e41f4b71Sopenharmony_ci      this.selectUris.push(uri);
369e41f4b71Sopenharmony_ci    }
370e41f4b71Sopenharmony_ci  }
371e41f4b71Sopenharmony_ci
372e41f4b71Sopenharmony_ci  private onDeselect(uri: string): void {
373e41f4b71Sopenharmony_ci    // Remove
374e41f4b71Sopenharmony_ci    if (uri) {
375e41f4b71Sopenharmony_ci      this.selectUris = this.selectUris.filter((item: string) => {
376e41f4b71Sopenharmony_ci        return item != uri;
377e41f4b71Sopenharmony_ci      })
378e41f4b71Sopenharmony_ci    }
379e41f4b71Sopenharmony_ci  }
380e41f4b71Sopenharmony_ci  
381e41f4b71Sopenharmony_ci  private onItemClicked(itemInfo: ItemInfo, clickType: ClickType): boolean {
382e41f4b71Sopenharmony_ci    if (!itemInfo) {
383e41f4b71Sopenharmony_ci       return false;
384e41f4b71Sopenharmony_ci    }
385e41f4b71Sopenharmony_ci    let type: ItemType | undefined = itemInfo.itemType;
386e41f4b71Sopenharmony_ci    let uri: string | undefined = itemInfo.uri;
387e41f4b71Sopenharmony_ci    if (type === ItemType.CAMERA) {
388e41f4b71Sopenharmony_ci      // Click a camera item.
389e41f4b71Sopenharmony_ci      return true; // If true is returned, the system camera is started. If false is returned, the app processes its services.
390e41f4b71Sopenharmony_ci    } else {
391e41f4b71Sopenharmony_ci      if (clickType === ClickType.SELECTED) {
392e41f4b71Sopenharmony_ci        // The application processes its services.
393e41f4b71Sopenharmony_ci        if (uri) {
394e41f4b71Sopenharmony_ci          this.selectUris.push(uri);
395e41f4b71Sopenharmony_ci          this.pickerOptions.preselectedUris = [...this.selectUris];
396e41f4b71Sopenharmony_ci        }
397e41f4b71Sopenharmony_ci        return true; // If true is returned, the check box is selected. Otherwise, the check box is not selected.
398e41f4b71Sopenharmony_ci      } else {
399e41f4b71Sopenharmony_ci        if (uri) {
400e41f4b71Sopenharmony_ci          this.selectUris = this.selectUris.filter((item: string) => {
401e41f4b71Sopenharmony_ci          return item != uri;
402e41f4b71Sopenharmony_ci          });
403e41f4b71Sopenharmony_ci          this.pickerOptions.preselectedUris = [...this.selectUris];
404e41f4b71Sopenharmony_ci        }
405e41f4b71Sopenharmony_ci      }
406e41f4b71Sopenharmony_ci      return true;
407e41f4b71Sopenharmony_ci    }
408e41f4b71Sopenharmony_ci  }
409e41f4b71Sopenharmony_ci  
410e41f4b71Sopenharmony_ci  private onEnterPhotoBrowser(photoBrowserInfo: PhotoBrowserInfo): boolean {
411e41f4b71Sopenharmony_ci    // Callback to be invoked when the photo browser page is displayed.
412e41f4b71Sopenharmony_ci    this.isBrowserShow = true;
413e41f4b71Sopenharmony_ci    return true;
414e41f4b71Sopenharmony_ci  }
415e41f4b71Sopenharmony_ci  
416e41f4b71Sopenharmony_ci  private onExitPhotoBrowser(photoBrowserInfo: PhotoBrowserInfo): boolean {
417e41f4b71Sopenharmony_ci    // Callback to be invoked when the photo browser page is closed.
418e41f4b71Sopenharmony_ci    this.isBrowserShow = false;
419e41f4b71Sopenharmony_ci    return true;
420e41f4b71Sopenharmony_ci  }
421e41f4b71Sopenharmony_ci  
422e41f4b71Sopenharmony_ci  private onPickerControllerReady(): void {
423e41f4b71Sopenharmony_ci    // After the callback is called, pickerController APIs can be called to send data to Picker. Before the callback is called, pickerController APIs do not take effect.
424e41f4b71Sopenharmony_ci  }
425e41f4b71Sopenharmony_ci
426e41f4b71Sopenharmony_ci  private onPhotoBrowserChanged(browserItemInfo: BaseItemInfo): boolean {
427e41f4b71Sopenharmony_ci    // Callback to be invoked when the photo browser is swiped left or right.
428e41f4b71Sopenharmony_ci    this.currentUri = browserItemInfo.uri ?? '';
429e41f4b71Sopenharmony_ci    return true;
430e41f4b71Sopenharmony_ci  }
431e41f4b71Sopenharmony_ci
432e41f4b71Sopenharmony_ci  build() {
433e41f4b71Sopenharmony_ci    Flex({
434e41f4b71Sopenharmony_ci      direction: FlexDirection.Column,
435e41f4b71Sopenharmony_ci      justifyContent: FlexAlign.Center,
436e41f4b71Sopenharmony_ci      alignItems: ItemAlign.Center
437e41f4b71Sopenharmony_ci    }) {
438e41f4b71Sopenharmony_ci      PhotoPickerComponent({
439e41f4b71Sopenharmony_ci        pickerOptions: this.pickerOptions,
440e41f4b71Sopenharmony_ci        // onSelect: (uri: string): void => this.onSelect(uri),
441e41f4b71Sopenharmony_ci        // onDeselect: (uri: string): void => this.onDeselect(uri), 
442e41f4b71Sopenharmony_ci        onItemClicked: (itemInfo: ItemInfo, clickType: ClickType): boolean => this.onItemClicked(itemInfo, clickType), // This API can replace the preceding two APIs.
443e41f4b71Sopenharmony_ci        onEnterPhotoBrowser: (photoBrowserInfo: PhotoBrowserInfo): boolean => this.onEnterPhotoBrowser(photoBrowserInfo),
444e41f4b71Sopenharmony_ci        onExitPhotoBrowser: (photoBrowserInfo: PhotoBrowserInfo): boolean => this.onExitPhotoBrowser(photoBrowserInfo),
445e41f4b71Sopenharmony_ci        onPickerControllerReady: (): void => this.onPickerControllerReady(),
446e41f4b71Sopenharmony_ci        onPhotoBrowserChanged: (browserItemInfo: BaseItemInfo): boolean => this.onPhotoBrowserChanged(browserItemInfo),
447e41f4b71Sopenharmony_ci        pickerController: this.pickerController,
448e41f4b71Sopenharmony_ci      }).height('60%').width('100%')
449e41f4b71Sopenharmony_ci
450e41f4b71Sopenharmony_ci
451e41f4b71Sopenharmony_ci      // Simulate the selection bar at the bottom of the application.
452e41f4b71Sopenharmony_ci      if (this.isBrowserShow) {
453e41f4b71Sopenharmony_ci        Row() {
454e41f4b71Sopenharmony_ci          ForEach(this.selectUris, (uri: string) => {
455e41f4b71Sopenharmony_ci            if (uri === this.currentUri) {
456e41f4b71Sopenharmony_ci              Image(uri).height('10%').width('10%').onClick(() => {
457e41f4b71Sopenharmony_ci              }).borderWidth(1).borderColor('red')
458e41f4b71Sopenharmony_ci            } else {
459e41f4b71Sopenharmony_ci              Image(uri).height('10%').width('10%').onClick(() => {
460e41f4b71Sopenharmony_ci                this.pickerController.setData(DataType.SET_SELECTED_URIS, this.selectUris);
461e41f4b71Sopenharmony_ci                this.pickerController.setPhotoBrowserItem(uri, PhotoBrowserRange.ALL);
462e41f4b71Sopenharmony_ci              })
463e41f4b71Sopenharmony_ci            }
464e41f4b71Sopenharmony_ci          }, (uri: string) => JSON.stringify(uri))
465e41f4b71Sopenharmony_ci        }
466e41f4b71Sopenharmony_ci      } else {
467e41f4b71Sopenharmony_ci        Button ('Preview').width ('33%').height('5%').onClick(() => {
468e41f4b71Sopenharmony_ci          if (this.selectUris.length > 0) {
469e41f4b71Sopenharmony_ci            this.pickerController.setPhotoBrowserItem(this.selectUris[0], PhotoBrowserRange.SELECTED_ONLY);
470e41f4b71Sopenharmony_ci          }
471e41f4b71Sopenharmony_ci        })
472e41f4b71Sopenharmony_ci      }
473e41f4b71Sopenharmony_ci    }
474e41f4b71Sopenharmony_ci  }
475e41f4b71Sopenharmony_ci}
476e41f4b71Sopenharmony_ci```
477