expo-image-picker 14.0.0 → 14.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/android/build.gradle +2 -2
- package/build/ImagePicker.d.ts +5 -3
- package/build/ImagePicker.d.ts.map +1 -1
- package/build/ImagePicker.js +5 -3
- package/build/ImagePicker.js.map +1 -1
- package/ios/ImagePickerOptions.swift +2 -0
- package/ios/MediaHandler.swift +49 -22
- package/package.json +2 -2
- package/src/ImagePicker.ts +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,18 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 14.0.2 — 2022-11-21
|
|
14
|
+
|
|
15
|
+
### 🐛 Bug fixes
|
|
16
|
+
|
|
17
|
+
- Fix support for animated GIFs on iOS. ([#20034](https://github.com/expo/expo/pull/20034) by [@barthap](https://github.com/barthap))
|
|
18
|
+
|
|
19
|
+
## 14.0.1 — 2022-11-08
|
|
20
|
+
|
|
21
|
+
### 🐛 Bug fixes
|
|
22
|
+
|
|
23
|
+
- Fix incorrect asset type for videos on iOS. ([#19932](https://github.com/expo/expo/pull/19932) by [@tsapeta](https://github.com/tsapeta))
|
|
24
|
+
|
|
13
25
|
## 14.0.0 — 2022-10-25
|
|
14
26
|
|
|
15
27
|
### 🛠 Breaking changes
|
package/android/build.gradle
CHANGED
|
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
|
|
|
3
3
|
apply plugin: 'maven-publish'
|
|
4
4
|
|
|
5
5
|
group = 'host.exp.exponent'
|
|
6
|
-
version = '14.0.
|
|
6
|
+
version = '14.0.2'
|
|
7
7
|
|
|
8
8
|
buildscript {
|
|
9
9
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
@@ -74,7 +74,7 @@ android {
|
|
|
74
74
|
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
75
75
|
targetSdkVersion safeExtGet("targetSdkVersion", 31)
|
|
76
76
|
versionCode 22
|
|
77
|
-
versionName "14.0.
|
|
77
|
+
versionName "14.0.2"
|
|
78
78
|
}
|
|
79
79
|
lintOptions {
|
|
80
80
|
abortOnError false
|
package/build/ImagePicker.d.ts
CHANGED
|
@@ -78,10 +78,12 @@ export declare function launchCameraAsync(options?: ImagePickerOptions): Promise
|
|
|
78
78
|
* Requires `Permissions.MEDIA_LIBRARY` on iOS 10 only. On mobile web, this must be called
|
|
79
79
|
* immediately in a user interaction like a button press, otherwise the browser will block the
|
|
80
80
|
* request without a warning.
|
|
81
|
-
*
|
|
82
|
-
*
|
|
81
|
+
*
|
|
82
|
+
* **Animated GIFs support:** On Android, if the selected image is an animated GIF, the result image will be an
|
|
83
|
+
* animated GIF too if and only if `quality` is explicitly set to `1.0` and `allowsEditing` is set to `false`.
|
|
83
84
|
* Otherwise compression and/or cropper will pick the first frame of the GIF and return it as the
|
|
84
|
-
* result (on Android the result will be a PNG
|
|
85
|
+
* result (on Android the result will be a PNG). On iOS, both quality and cropping are supported.
|
|
86
|
+
*
|
|
85
87
|
* > **Notes for Web:** The system UI can only be shown after user activation (e.g. a `Button` press).
|
|
86
88
|
* Therefore, calling `launchImageLibraryAsync` in `componentDidMount`, for example, will **not**
|
|
87
89
|
* work as intended. The `cancelled` event will not be returned in the browser due to platform
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImagePicker.d.ts","sourceRoot":"","sources":["../src/ImagePicker.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAInB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,wBAAwB,EACxB,8BAA8B,EAC9B,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,uBAAuB,EACvB,SAAS,EACT,y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@@ -160,10 +160,12 @@ export async function launchCameraAsync(options = {}) {
|
|
|
160
160
|
* Requires `Permissions.MEDIA_LIBRARY` on iOS 10 only. On mobile web, this must be called
|
|
161
161
|
* immediately in a user interaction like a button press, otherwise the browser will block the
|
|
162
162
|
* request without a warning.
|
|
163
|
-
*
|
|
164
|
-
*
|
|
163
|
+
*
|
|
164
|
+
* **Animated GIFs support:** On Android, if the selected image is an animated GIF, the result image will be an
|
|
165
|
+
* animated GIF too if and only if `quality` is explicitly set to `1.0` and `allowsEditing` is set to `false`.
|
|
165
166
|
* Otherwise compression and/or cropper will pick the first frame of the GIF and return it as the
|
|
166
|
-
* result (on Android the result will be a PNG
|
|
167
|
+
* result (on Android the result will be a PNG). On iOS, both quality and cropping are supported.
|
|
168
|
+
*
|
|
167
169
|
* > **Notes for Web:** The system UI can only be shown after user activation (e.g. a `Button` press).
|
|
168
170
|
* Therefore, calling `launchImageLibraryAsync` in `componentDidMount`, for example, will **not**
|
|
169
171
|
* work as intended. The `cancelled` event will not be returned in the browser due to platform
|
package/build/ImagePicker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImagePicker.js","sourceRoot":"","sources":["../src/ImagePicker.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAIhB,oBAAoB,EACpB,mBAAmB,EACnB,UAAU,GACX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAML,gBAAgB,EAEhB,iBAAiB,EAMjB,kCAAkC,EAClC,8BAA8B,GAC/B,MAAM,qBAAqB,CAAC;AAE7B,SAAS,eAAe,CAAC,OAA2B;IAClD,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC;IAEtD,IAAI,MAAM,IAAI,IAAI,EAAE;QAClB,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC;QAEtB,IAAI,CAAC,IAA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;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,UAA8B,EAAE;IAEhC,IAAI,CAAC,mBAAmB,CAAC,iBAAiB,EAAE;QAC1C,MAAM,IAAI,mBAAmB,CAAC,aAAa,EAAE,mBAAmB,CAAC,CAAC;KACnE;IACD,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,iBAAiB,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IACrF,OAAO,qBAAqB,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC;AAED,cAAc;AACd;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAA4B;IAE5B,IAAI,CAAC,mBAAmB,CAAC,uBAAuB,EAAE;QAChD,MAAM,IAAI,mBAAmB,CAAC,aAAa,EAAE,yBAAyB,CAAC,CAAC;KACzE;IACD,IAAI,OAAO,EAAE,aAAa,IAAI,OAAO,CAAC,uBAAuB,EAAE;QAC7D,OAAO,CAAC,IAAI,CACV,qHAAqH;YACnH,2FAA2F;YAC3F,sBAAsB,CACzB,CAAC;KACH;IACD,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,uBAAuB,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAChF,OAAO,qBAAqB,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC;AAED,OAAO,EACL,gBAAgB,EAKhB,iBAAiB,EAGjB,gBAAgB,EAQS,aAAa;AACtC,kCAAkC,EAClC,8BAA8B,GAC/B,CAAC","sourcesContent":["import {\n PermissionStatus,\n PermissionExpiration,\n PermissionHookOptions,\n PermissionResponse,\n createPermissionHook,\n UnavailabilityError,\n CodedError,\n} from 'expo-modules-core';\n\nimport ExponentImagePicker from './ExponentImagePicker';\nimport {\n CameraPermissionResponse,\n MediaLibraryPermissionResponse,\n ImagePickerResult,\n ImagePickerAsset,\n ImagePickerErrorResult,\n MediaTypeOptions,\n ImagePickerOptions,\n VideoExportPreset,\n ExpandImagePickerResult,\n ImageInfo,\n ImagePickerMultipleResult,\n ImagePickerCancelledResult,\n OpenFileBrowserOptions,\n UIImagePickerControllerQualityType,\n UIImagePickerPresentationStyle,\n} from './ImagePicker.types';\n\nfunction validateOptions(options: ImagePickerOptions) {\n const { aspect, quality, videoMaxDuration } = options;\n\n if (aspect != null) {\n const [x, y] = aspect;\n\n if (x <= 0 || y <= 0) {\n throw new CodedError(\n 'ERR_INVALID_ARGUMENT',\n `Invalid aspect ratio values ${x}:${y}. Provide positive numbers.`\n );\n }\n }\n\n if (quality && (quality < 0 || quality > 1)) {\n throw new CodedError(\n 'ERR_INVALID_ARGUMENT',\n `Invalid 'quality' value ${quality}. Provide a value between 0 and 1.`\n );\n }\n\n if (videoMaxDuration && videoMaxDuration < 0) {\n throw new CodedError(\n 'ERR_INVALID_ARGUMENT',\n `Invalid 'videoMaxDuration' value ${videoMaxDuration}. Provide a non-negative number.`\n );\n }\n\n return options;\n}\n\nconst DEPRECATED_RESULT_KEYS = [\n 'uri',\n 'assetId',\n 'width',\n 'height',\n 'type',\n 'exif',\n 'base64',\n 'duration',\n 'fileName',\n 'fileSize',\n];\nfunction mergeDeprecatedResult(result: ImagePickerResult): ImagePickerResult {\n const firstAsset = result.assets?.[0];\n const deprecatedResult = {\n ...result,\n get cancelled() {\n console.warn(\n 'Key \"cancelled\" in the image picker result is deprecated and will be removed in SDK 48, use \"canceled\" instead'\n );\n return this.canceled;\n },\n };\n for (const key of DEPRECATED_RESULT_KEYS) {\n Object.defineProperty(deprecatedResult, key, {\n get() {\n console.warn(\n `Key \"${key}\" in the image picker result is deprecated and will be removed in SDK 48, you can access selected assets through the \"assets\" array instead`\n );\n return firstAsset?.[key];\n },\n });\n }\n return deprecatedResult;\n}\n\n// @needsAudit\n/**\n * Checks user's permissions for accessing camera.\n * @return A promise that fulfills with an object of type [CameraPermissionResponse](#camerapermissionresponse).\n */\nexport async function getCameraPermissionsAsync(): Promise<CameraPermissionResponse> {\n return ExponentImagePicker.getCameraPermissionsAsync();\n}\n\n// @needsAudit\n/**\n * Checks user's permissions for accessing photos.\n * @param writeOnly Whether to request write or read and write permissions. Defaults to `false`\n * @return A promise that fulfills with an object of type [MediaLibraryPermissionResponse](#medialibrarypermissionresponse).\n */\nexport async function getMediaLibraryPermissionsAsync(\n writeOnly: boolean = false\n): Promise<MediaLibraryPermissionResponse> {\n return ExponentImagePicker.getMediaLibraryPermissionsAsync(writeOnly);\n}\n\n// @needsAudit\n/**\n * Asks the user to grant permissions for accessing camera. This does nothing on web because the\n * browser camera is not used.\n * @return A promise that fulfills with an object of type [CameraPermissionResponse](#camerarollpermissionresponse).\n */\nexport async function requestCameraPermissionsAsync(): Promise<CameraPermissionResponse> {\n return ExponentImagePicker.requestCameraPermissionsAsync();\n}\n\n// @needsAudit\n/**\n * Asks the user to grant permissions for accessing user's photo. This method does nothing on web.\n * @param writeOnly Whether to request write or read and write permissions. Defaults to `false`\n * @return A promise that fulfills with an object of type [MediaLibraryPermissionResponse](#medialibrarypermissionresponse).\n */\nexport async function requestMediaLibraryPermissionsAsync(\n writeOnly: boolean = false\n): Promise<MediaLibraryPermissionResponse> {\n const imagePickerMethod = ExponentImagePicker.requestMediaLibraryPermissionsAsync;\n return imagePickerMethod(writeOnly);\n}\n\n// @needsAudit\n/**\n * Check or request permissions to access the media library.\n * This uses both `requestMediaLibraryPermissionsAsync` and `getMediaLibraryPermissionsAsync` to interact with the permissions.\n *\n * @example\n * ```ts\n * const [status, requestPermission] = ImagePicker.useMediaLibraryPermissions();\n * ```\n */\nexport const useMediaLibraryPermissions = createPermissionHook<\n MediaLibraryPermissionResponse,\n { writeOnly?: boolean }\n>({\n // TODO(cedric): permission requesters should have an options param or a different requester\n getMethod: (options) => getMediaLibraryPermissionsAsync(options?.writeOnly),\n requestMethod: (options) => requestMediaLibraryPermissionsAsync(options?.writeOnly),\n});\n\n// @needsAudit\n/**\n * Check or request permissions to access the camera.\n * This uses both `requestCameraPermissionsAsync` and `getCameraPermissionsAsync` to interact with the permissions.\n *\n * @example\n * ```ts\n * const [status, requestPermission] = ImagePicker.useCameraPermissions();\n * ```\n */\nexport const useCameraPermissions = createPermissionHook({\n getMethod: getCameraPermissionsAsync,\n requestMethod: requestCameraPermissionsAsync,\n});\n\n// @needsAudit\n/**\n * Android system sometimes kills the `MainActivity` after the `ImagePicker` finishes. When this\n * happens, we lost the data selected from the `ImagePicker`. However, you can retrieve the lost\n * data by calling `getPendingResultAsync`. You can test this functionality by turning on\n * `Don't keep activities` in the developer options.\n * @return\n * - **On Android:** a promise that resolves to an array of objects of exactly same type as in\n * `ImagePicker.launchImageLibraryAsync` or `ImagePicker.launchCameraAsync` if the `ImagePicker`\n * finished successfully. Otherwise, to the array of [`ImagePickerErrorResult`](#imagepickerimagepickererrorresult).\n * - **On other platforms:** an empty array.\n */\nexport async function getPendingResultAsync(): Promise<\n (ImagePickerResult | ImagePickerErrorResult)[]\n> {\n if (ExponentImagePicker.getPendingResultAsync) {\n return ExponentImagePicker.getPendingResultAsync();\n }\n return [];\n}\n\n// @needsAudit\n/**\n * Display the system UI for taking a photo with the camera. Requires `Permissions.CAMERA`.\n * On Android and iOS 10 `Permissions.CAMERA_ROLL` is also required. On mobile web, this must be\n * called immediately in a user interaction like a button press, otherwise the browser will block\n * the request without a warning.\n * > **Note:** Make sure that you handle `MainActivity` destruction on **Android**. See [ImagePicker.getPendingResultAsync](#imagepickergetpendingresultasync).\n * > **Notes for Web:** The system UI can only be shown after user activation (e.g. a `Button` press).\n * Therefore, calling `launchCameraAsync` in `componentDidMount`, for example, will **not** work as\n * intended. The `cancelled` event will not be returned in the browser due to platform restrictions\n * and inconsistencies across browsers.\n * @param options An `ImagePickerOptions` object.\n * @return A promise that resolves to an object with `canceled` and `assets` fields.\n * When the user canceled the action the `assets` is always `null`, otherwise it's an array of\n * the selected media assets which have a form of [`ImagePickerAsset`](#imagepickerasset).\n */\nexport async function launchCameraAsync(\n options: ImagePickerOptions = {}\n): Promise<ImagePickerResult> {\n if (!ExponentImagePicker.launchCameraAsync) {\n throw new UnavailabilityError('ImagePicker', 'launchCameraAsync');\n }\n const result = await ExponentImagePicker.launchCameraAsync(validateOptions(options));\n return mergeDeprecatedResult(result);\n}\n\n// @needsAudit\n/**\n * Display the system UI for choosing an image or a video from the phone's library.\n * Requires `Permissions.MEDIA_LIBRARY` on iOS 10 only. On mobile web, this must be called\n * immediately in a user interaction like a button press, otherwise the browser will block the\n * request without a warning.\n * **Animated GIFs support** If the selected image is an animated GIF, the result image will be an\n * animated GIF too if and only if `quality` is set to `undefined` and `allowsEditing` is set to `false`.\n * Otherwise compression and/or cropper will pick the first frame of the GIF and return it as the\n * result (on Android the result will be a PNG, on iOS — GIF).\n * > **Notes for Web:** The system UI can only be shown after user activation (e.g. a `Button` press).\n * Therefore, calling `launchImageLibraryAsync` in `componentDidMount`, for example, will **not**\n * work as intended. The `cancelled` event will not be returned in the browser due to platform\n * restrictions and inconsistencies across browsers.\n * @param options An object extended by [`ImagePickerOptions`](#imagepickeroptions).\n * @return A promise that resolves to an object with `canceled` and `assets` fields.\n * When the user canceled the action the `assets` is always `null`, otherwise it's an array of\n * the selected media assets which have a form of [`ImagePickerAsset`](#imagepickerasset).\n */\nexport async function launchImageLibraryAsync(\n options?: ImagePickerOptions\n): Promise<ImagePickerResult> {\n if (!ExponentImagePicker.launchImageLibraryAsync) {\n throw new UnavailabilityError('ImagePicker', 'launchImageLibraryAsync');\n }\n if (options?.allowsEditing && options.allowsMultipleSelection) {\n console.warn(\n '[expo-image-picker] `allowsEditing` is not supported when `allowsMultipleSelection` is enabled and will be ignored.' +\n \"Disable either 'allowsEditing' or 'allowsMultipleSelection' in 'launchImageLibraryAsync' \" +\n 'to fix this warning.'\n );\n }\n const result = await ExponentImagePicker.launchImageLibraryAsync(options ?? {});\n return mergeDeprecatedResult(result);\n}\n\nexport {\n MediaTypeOptions,\n ImagePickerOptions,\n ImagePickerResult,\n ImagePickerErrorResult,\n ImagePickerAsset,\n VideoExportPreset,\n CameraPermissionResponse,\n MediaLibraryPermissionResponse,\n PermissionStatus,\n PermissionExpiration,\n PermissionHookOptions,\n PermissionResponse,\n ImageInfo, // deprecated\n ImagePickerMultipleResult, // deprecated\n ImagePickerCancelledResult, // deprecated\n OpenFileBrowserOptions,\n ExpandImagePickerResult, // deprecated\n UIImagePickerControllerQualityType,\n UIImagePickerPresentationStyle,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"ImagePicker.js","sourceRoot":"","sources":["../src/ImagePicker.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAIhB,oBAAoB,EACpB,mBAAmB,EACnB,UAAU,GACX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAML,gBAAgB,EAEhB,iBAAiB,EAMjB,kCAAkC,EAClC,8BAA8B,GAC/B,MAAM,qBAAqB,CAAC;AAE7B,SAAS,eAAe,CAAC,OAA2B;IAClD,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC;IAEtD,IAAI,MAAM,IAAI,IAAI,EAAE;QAClB,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC;QAEtB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACpB,MAAM,IAAI,UAAU,CAClB,sBAAsB,EACtB,+BAA+B,CAAC,IAAI,CAAC,6BAA6B,CACnE,CAAC;SACH;KACF;IAED,IAAI,OAAO,IAAI,CAAC,OAAO,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC,EAAE;QAC3C,MAAM,IAAI,UAAU,CAClB,sBAAsB,EACtB,2BAA2B,OAAO,oCAAoC,CACvE,CAAC;KACH;IAED,IAAI,gBAAgB,IAAI,gBAAgB,GAAG,CAAC,EAAE;QAC5C,MAAM,IAAI,UAAU,CAClB,sBAAsB,EACtB,oCAAoC,gBAAgB,kCAAkC,CACvF,CAAC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IAE5B,IAAI,CAAC,mBAAmB,CAAC,uBAAuB,EAAE;QAChD,MAAM,IAAI,mBAAmB,CAAC,aAAa,EAAE,yBAAyB,CAAC,CAAC;KACzE;IACD,IAAI,OAAO,EAAE,aAAa,IAAI,OAAO,CAAC,uBAAuB,EAAE;QAC7D,OAAO,CAAC,IAAI,CACV,qHAAqH;YACnH,2FAA2F;YAC3F,sBAAsB,CACzB,CAAC;KACH;IACD,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,uBAAuB,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAChF,OAAO,qBAAqB,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC;AAED,OAAO,EACL,gBAAgB,EAKhB,iBAAiB,EAGjB,gBAAgB,EAQS,aAAa;AACtC,kCAAkC,EAClC,8BAA8B,GAC/B,CAAC","sourcesContent":["import {\n PermissionStatus,\n PermissionExpiration,\n PermissionHookOptions,\n PermissionResponse,\n createPermissionHook,\n UnavailabilityError,\n CodedError,\n} from 'expo-modules-core';\n\nimport ExponentImagePicker from './ExponentImagePicker';\nimport {\n CameraPermissionResponse,\n MediaLibraryPermissionResponse,\n ImagePickerResult,\n ImagePickerAsset,\n ImagePickerErrorResult,\n MediaTypeOptions,\n ImagePickerOptions,\n VideoExportPreset,\n ExpandImagePickerResult,\n ImageInfo,\n ImagePickerMultipleResult,\n ImagePickerCancelledResult,\n OpenFileBrowserOptions,\n UIImagePickerControllerQualityType,\n UIImagePickerPresentationStyle,\n} from './ImagePicker.types';\n\nfunction validateOptions(options: ImagePickerOptions) {\n const { aspect, quality, videoMaxDuration } = options;\n\n if (aspect != null) {\n const [x, y] = aspect;\n\n if (x <= 0 || y <= 0) {\n throw new CodedError(\n 'ERR_INVALID_ARGUMENT',\n `Invalid aspect ratio values ${x}:${y}. Provide positive numbers.`\n );\n }\n }\n\n if (quality && (quality < 0 || quality > 1)) {\n throw new CodedError(\n 'ERR_INVALID_ARGUMENT',\n `Invalid 'quality' value ${quality}. Provide a value between 0 and 1.`\n );\n }\n\n if (videoMaxDuration && videoMaxDuration < 0) {\n throw new CodedError(\n 'ERR_INVALID_ARGUMENT',\n `Invalid 'videoMaxDuration' value ${videoMaxDuration}. Provide a non-negative number.`\n );\n }\n\n return options;\n}\n\nconst DEPRECATED_RESULT_KEYS = [\n 'uri',\n 'assetId',\n 'width',\n 'height',\n 'type',\n 'exif',\n 'base64',\n 'duration',\n 'fileName',\n 'fileSize',\n];\nfunction mergeDeprecatedResult(result: ImagePickerResult): ImagePickerResult {\n const firstAsset = result.assets?.[0];\n const deprecatedResult = {\n ...result,\n get cancelled() {\n console.warn(\n 'Key \"cancelled\" in the image picker result is deprecated and will be removed in SDK 48, use \"canceled\" instead'\n );\n return this.canceled;\n },\n };\n for (const key of DEPRECATED_RESULT_KEYS) {\n Object.defineProperty(deprecatedResult, key, {\n get() {\n console.warn(\n `Key \"${key}\" in the image picker result is deprecated and will be removed in SDK 48, you can access selected assets through the \"assets\" array instead`\n );\n return firstAsset?.[key];\n },\n });\n }\n return deprecatedResult;\n}\n\n// @needsAudit\n/**\n * Checks user's permissions for accessing camera.\n * @return A promise that fulfills with an object of type [CameraPermissionResponse](#camerapermissionresponse).\n */\nexport async function getCameraPermissionsAsync(): Promise<CameraPermissionResponse> {\n return ExponentImagePicker.getCameraPermissionsAsync();\n}\n\n// @needsAudit\n/**\n * Checks user's permissions for accessing photos.\n * @param writeOnly Whether to request write or read and write permissions. Defaults to `false`\n * @return A promise that fulfills with an object of type [MediaLibraryPermissionResponse](#medialibrarypermissionresponse).\n */\nexport async function getMediaLibraryPermissionsAsync(\n writeOnly: boolean = false\n): Promise<MediaLibraryPermissionResponse> {\n return ExponentImagePicker.getMediaLibraryPermissionsAsync(writeOnly);\n}\n\n// @needsAudit\n/**\n * Asks the user to grant permissions for accessing camera. This does nothing on web because the\n * browser camera is not used.\n * @return A promise that fulfills with an object of type [CameraPermissionResponse](#camerarollpermissionresponse).\n */\nexport async function requestCameraPermissionsAsync(): Promise<CameraPermissionResponse> {\n return ExponentImagePicker.requestCameraPermissionsAsync();\n}\n\n// @needsAudit\n/**\n * Asks the user to grant permissions for accessing user's photo. This method does nothing on web.\n * @param writeOnly Whether to request write or read and write permissions. Defaults to `false`\n * @return A promise that fulfills with an object of type [MediaLibraryPermissionResponse](#medialibrarypermissionresponse).\n */\nexport async function requestMediaLibraryPermissionsAsync(\n writeOnly: boolean = false\n): Promise<MediaLibraryPermissionResponse> {\n const imagePickerMethod = ExponentImagePicker.requestMediaLibraryPermissionsAsync;\n return imagePickerMethod(writeOnly);\n}\n\n// @needsAudit\n/**\n * Check or request permissions to access the media library.\n * This uses both `requestMediaLibraryPermissionsAsync` and `getMediaLibraryPermissionsAsync` to interact with the permissions.\n *\n * @example\n * ```ts\n * const [status, requestPermission] = ImagePicker.useMediaLibraryPermissions();\n * ```\n */\nexport const useMediaLibraryPermissions = createPermissionHook<\n MediaLibraryPermissionResponse,\n { writeOnly?: boolean }\n>({\n // TODO(cedric): permission requesters should have an options param or a different requester\n getMethod: (options) => getMediaLibraryPermissionsAsync(options?.writeOnly),\n requestMethod: (options) => requestMediaLibraryPermissionsAsync(options?.writeOnly),\n});\n\n// @needsAudit\n/**\n * Check or request permissions to access the camera.\n * This uses both `requestCameraPermissionsAsync` and `getCameraPermissionsAsync` to interact with the permissions.\n *\n * @example\n * ```ts\n * const [status, requestPermission] = ImagePicker.useCameraPermissions();\n * ```\n */\nexport const useCameraPermissions = createPermissionHook({\n getMethod: getCameraPermissionsAsync,\n requestMethod: requestCameraPermissionsAsync,\n});\n\n// @needsAudit\n/**\n * Android system sometimes kills the `MainActivity` after the `ImagePicker` finishes. When this\n * happens, we lost the data selected from the `ImagePicker`. However, you can retrieve the lost\n * data by calling `getPendingResultAsync`. You can test this functionality by turning on\n * `Don't keep activities` in the developer options.\n * @return\n * - **On Android:** a promise that resolves to an array of objects of exactly same type as in\n * `ImagePicker.launchImageLibraryAsync` or `ImagePicker.launchCameraAsync` if the `ImagePicker`\n * finished successfully. Otherwise, to the array of [`ImagePickerErrorResult`](#imagepickerimagepickererrorresult).\n * - **On other platforms:** an empty array.\n */\nexport async function getPendingResultAsync(): Promise<\n (ImagePickerResult | ImagePickerErrorResult)[]\n> {\n if (ExponentImagePicker.getPendingResultAsync) {\n return ExponentImagePicker.getPendingResultAsync();\n }\n return [];\n}\n\n// @needsAudit\n/**\n * Display the system UI for taking a photo with the camera. Requires `Permissions.CAMERA`.\n * On Android and iOS 10 `Permissions.CAMERA_ROLL` is also required. On mobile web, this must be\n * called immediately in a user interaction like a button press, otherwise the browser will block\n * the request without a warning.\n * > **Note:** Make sure that you handle `MainActivity` destruction on **Android**. See [ImagePicker.getPendingResultAsync](#imagepickergetpendingresultasync).\n * > **Notes for Web:** The system UI can only be shown after user activation (e.g. a `Button` press).\n * Therefore, calling `launchCameraAsync` in `componentDidMount`, for example, will **not** work as\n * intended. The `cancelled` event will not be returned in the browser due to platform restrictions\n * and inconsistencies across browsers.\n * @param options An `ImagePickerOptions` object.\n * @return A promise that resolves to an object with `canceled` and `assets` fields.\n * When the user canceled the action the `assets` is always `null`, otherwise it's an array of\n * the selected media assets which have a form of [`ImagePickerAsset`](#imagepickerasset).\n */\nexport async function launchCameraAsync(\n options: ImagePickerOptions = {}\n): Promise<ImagePickerResult> {\n if (!ExponentImagePicker.launchCameraAsync) {\n throw new UnavailabilityError('ImagePicker', 'launchCameraAsync');\n }\n const result = await ExponentImagePicker.launchCameraAsync(validateOptions(options));\n return mergeDeprecatedResult(result);\n}\n\n// @needsAudit\n/**\n * Display the system UI for choosing an image or a video from the phone's library.\n * Requires `Permissions.MEDIA_LIBRARY` on iOS 10 only. On mobile web, this must be called\n * immediately in a user interaction like a button press, otherwise the browser will block the\n * request without a warning.\n *\n * **Animated GIFs support:** On Android, if the selected image is an animated GIF, the result image will be an\n * animated GIF too if and only if `quality` is explicitly set to `1.0` and `allowsEditing` is set to `false`.\n * Otherwise compression and/or cropper will pick the first frame of the GIF and return it as the\n * result (on Android the result will be a PNG). On iOS, both quality and cropping are supported.\n *\n * > **Notes for Web:** The system UI can only be shown after user activation (e.g. a `Button` press).\n * Therefore, calling `launchImageLibraryAsync` in `componentDidMount`, for example, will **not**\n * work as intended. The `cancelled` event will not be returned in the browser due to platform\n * restrictions and inconsistencies across browsers.\n * @param options An object extended by [`ImagePickerOptions`](#imagepickeroptions).\n * @return A promise that resolves to an object with `canceled` and `assets` fields.\n * When the user canceled the action the `assets` is always `null`, otherwise it's an array of\n * the selected media assets which have a form of [`ImagePickerAsset`](#imagepickerasset).\n */\nexport async function launchImageLibraryAsync(\n options?: ImagePickerOptions\n): Promise<ImagePickerResult> {\n if (!ExponentImagePicker.launchImageLibraryAsync) {\n throw new UnavailabilityError('ImagePicker', 'launchImageLibraryAsync');\n }\n if (options?.allowsEditing && options.allowsMultipleSelection) {\n console.warn(\n '[expo-image-picker] `allowsEditing` is not supported when `allowsMultipleSelection` is enabled and will be ignored.' +\n \"Disable either 'allowsEditing' or 'allowsMultipleSelection' in 'launchImageLibraryAsync' \" +\n 'to fix this warning.'\n );\n }\n const result = await ExponentImagePicker.launchImageLibraryAsync(options ?? {});\n return mergeDeprecatedResult(result);\n}\n\nexport {\n MediaTypeOptions,\n ImagePickerOptions,\n ImagePickerResult,\n ImagePickerErrorResult,\n ImagePickerAsset,\n VideoExportPreset,\n CameraPermissionResponse,\n MediaLibraryPermissionResponse,\n PermissionStatus,\n PermissionExpiration,\n PermissionHookOptions,\n PermissionResponse,\n ImageInfo, // deprecated\n ImagePickerMultipleResult, // deprecated\n ImagePickerCancelledResult, // deprecated\n OpenFileBrowserOptions,\n ExpandImagePickerResult, // deprecated\n UIImagePickerControllerQualityType,\n UIImagePickerPresentationStyle,\n};\n"]}
|
package/ios/MediaHandler.swift
CHANGED
|
@@ -126,6 +126,7 @@ internal struct MediaHandler {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
let (imageData, fileExtension) = try ImageUtils.readDataAndFileExtension(image: image,
|
|
129
|
+
rawData: rawData,
|
|
129
130
|
itemProvider: itemProvider,
|
|
130
131
|
options: self.options)
|
|
131
132
|
|
|
@@ -186,6 +187,7 @@ internal struct MediaHandler {
|
|
|
186
187
|
let fileName = asset?.value(forKey: "filename") as? String
|
|
187
188
|
let fileSize = getFileSize(from: targetUrl)
|
|
188
189
|
let videoInfo = AssetInfo(assetId: asset?.localIdentifier,
|
|
190
|
+
type: "video",
|
|
189
191
|
uri: targetUrl.absoluteString,
|
|
190
192
|
width: dimensions.width,
|
|
191
193
|
height: dimensions.height,
|
|
@@ -269,6 +271,7 @@ internal struct MediaHandler {
|
|
|
269
271
|
let fileSize = getFileSize(from: videoUrl)
|
|
270
272
|
|
|
271
273
|
let result = AssetInfo(assetId: assetId,
|
|
274
|
+
type: "video",
|
|
272
275
|
uri: videoUrl.absoluteString,
|
|
273
276
|
width: size.width,
|
|
274
277
|
height: size.height,
|
|
@@ -343,11 +346,17 @@ private struct ImageUtils {
|
|
|
343
346
|
return (nil, ".bmp")
|
|
344
347
|
|
|
345
348
|
case .some(let s) where s.contains("ext=GIF"):
|
|
349
|
+
var rawData: Data?
|
|
350
|
+
if let imgUrl = mediaInfo[.imageURL] as? URL {
|
|
351
|
+
rawData = try? Data(contentsOf: imgUrl)
|
|
352
|
+
}
|
|
353
|
+
let inputData = rawData ?? image.jpegData(compressionQuality: compressionQuality)
|
|
346
354
|
let metadata = mediaInfo[.mediaMetadata] as? [String: Any]
|
|
347
|
-
let
|
|
355
|
+
let cropRect = options.allowsEditing ? mediaInfo[.cropRect] as? CGRect : nil
|
|
356
|
+
let gifData = try processGifData(inputData: inputData,
|
|
348
357
|
compressionQuality: options.quality,
|
|
349
|
-
initialMetadata: metadata
|
|
350
|
-
|
|
358
|
+
initialMetadata: metadata,
|
|
359
|
+
cropRect: cropRect)
|
|
351
360
|
return (gifData, ".gif")
|
|
352
361
|
default:
|
|
353
362
|
let data = image.jpegData(compressionQuality: compressionQuality)
|
|
@@ -358,6 +367,7 @@ private struct ImageUtils {
|
|
|
358
367
|
@available(iOS 14, *)
|
|
359
368
|
static func readDataAndFileExtension(
|
|
360
369
|
image: UIImage,
|
|
370
|
+
rawData: Data,
|
|
361
371
|
itemProvider: NSItemProvider,
|
|
362
372
|
options: ImagePickerOptions
|
|
363
373
|
) throws -> (imageData: Data?, fileExtension: String) {
|
|
@@ -369,7 +379,7 @@ private struct ImageUtils {
|
|
|
369
379
|
let data = image.pngData()
|
|
370
380
|
return (data, ".png")
|
|
371
381
|
case UTType.gif.identifier:
|
|
372
|
-
let gifData = try
|
|
382
|
+
let gifData = try processGifData(inputData: rawData,
|
|
373
383
|
compressionQuality: options.quality,
|
|
374
384
|
initialMetadata: nil)
|
|
375
385
|
return (gifData, ".gif")
|
|
@@ -506,37 +516,54 @@ private struct ImageUtils {
|
|
|
506
516
|
return exif
|
|
507
517
|
}
|
|
508
518
|
|
|
509
|
-
static func
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
519
|
+
static func processGifData(
|
|
520
|
+
inputData: Data?,
|
|
521
|
+
compressionQuality quality: Double?,
|
|
522
|
+
initialMetadata: [String: Any]?,
|
|
523
|
+
cropRect: CGRect? = nil
|
|
524
|
+
) throws -> Data? {
|
|
525
|
+
// for uncropped, maximum quality image we can just pass through the raw data
|
|
526
|
+
if cropRect == nil,
|
|
527
|
+
quality == nil || (quality ?? -1) >= MAXIMUM_QUALITY {
|
|
528
|
+
return inputData
|
|
514
529
|
}
|
|
515
530
|
|
|
531
|
+
guard let sourceData = inputData,
|
|
532
|
+
let imageSource = CGImageSourceCreateWithData(sourceData as CFData, nil)
|
|
533
|
+
else {
|
|
534
|
+
throw FailedToReadImageException()
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
let gifProperties = CGImageSourceCopyProperties(imageSource, nil) as? [String: Any]
|
|
538
|
+
let frameCount = CGImageSourceGetCount(imageSource)
|
|
539
|
+
|
|
516
540
|
let destinationData = NSMutableData()
|
|
517
|
-
guard let imageDestination = CGImageDestinationCreateWithData(destinationData, kUTTypeGIF,
|
|
518
|
-
let cgImage = image.cgImage
|
|
541
|
+
guard let imageDestination = CGImageDestinationCreateWithData(destinationData, kUTTypeGIF, frameCount, nil)
|
|
519
542
|
else {
|
|
520
543
|
throw FailedToCreateGifException()
|
|
521
544
|
}
|
|
522
545
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
let cgImageSource = CGImageSourceCreateWithData(data as CFData, nil),
|
|
526
|
-
let properties = CGImageSourceCopyPropertiesAtIndex(cgImageSource, 0, nil) as? [String: Any] {
|
|
527
|
-
metadata = properties
|
|
528
|
-
}
|
|
546
|
+
let gifMetadata = initialMetadata ?? gifProperties
|
|
547
|
+
CGImageDestinationSetProperties(imageDestination, gifMetadata as CFDictionary?)
|
|
529
548
|
|
|
530
|
-
|
|
531
|
-
|
|
549
|
+
for frameIndex in 0 ..< frameCount {
|
|
550
|
+
guard var cgImage = CGImageSourceCreateImageAtIndex(imageSource, frameIndex, nil),
|
|
551
|
+
var frameProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, frameIndex, nil) as? [String: Any]
|
|
552
|
+
else {
|
|
553
|
+
throw FailedToCreateGifException()
|
|
554
|
+
}
|
|
555
|
+
if cropRect != nil {
|
|
556
|
+
cgImage = cgImage.cropping(to: cropRect!)!
|
|
557
|
+
}
|
|
558
|
+
if quality != nil {
|
|
559
|
+
frameProperties[kCGImageDestinationLossyCompressionQuality as String] = quality
|
|
560
|
+
}
|
|
561
|
+
CGImageDestinationAddImage(imageDestination, cgImage, frameProperties as CFDictionary)
|
|
532
562
|
}
|
|
533
563
|
|
|
534
|
-
CGImageDestinationAddImage(imageDestination, cgImage, metadata as CFDictionary)
|
|
535
|
-
|
|
536
564
|
if !CGImageDestinationFinalize(imageDestination) {
|
|
537
565
|
throw FailedToExportGifException()
|
|
538
566
|
}
|
|
539
|
-
|
|
540
567
|
return destinationData as Data
|
|
541
568
|
}
|
|
542
569
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-image-picker",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.0.2",
|
|
4
4
|
"description": "Provides access to the system's UI for selecting images and videos from the phone's library or taking a photo with the camera.",
|
|
5
5
|
"main": "build/ImagePicker.js",
|
|
6
6
|
"types": "build/ImagePicker.d.ts",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"expo": "*"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "7cc0ce2b21febcaf96e875d8a8aff10b320e1b5f"
|
|
49
49
|
}
|
package/src/ImagePicker.ts
CHANGED
|
@@ -225,10 +225,12 @@ export async function launchCameraAsync(
|
|
|
225
225
|
* Requires `Permissions.MEDIA_LIBRARY` on iOS 10 only. On mobile web, this must be called
|
|
226
226
|
* immediately in a user interaction like a button press, otherwise the browser will block the
|
|
227
227
|
* request without a warning.
|
|
228
|
-
*
|
|
229
|
-
*
|
|
228
|
+
*
|
|
229
|
+
* **Animated GIFs support:** On Android, if the selected image is an animated GIF, the result image will be an
|
|
230
|
+
* animated GIF too if and only if `quality` is explicitly set to `1.0` and `allowsEditing` is set to `false`.
|
|
230
231
|
* Otherwise compression and/or cropper will pick the first frame of the GIF and return it as the
|
|
231
|
-
* result (on Android the result will be a PNG
|
|
232
|
+
* result (on Android the result will be a PNG). On iOS, both quality and cropping are supported.
|
|
233
|
+
*
|
|
232
234
|
* > **Notes for Web:** The system UI can only be shown after user activation (e.g. a `Button` press).
|
|
233
235
|
* Therefore, calling `launchImageLibraryAsync` in `componentDidMount`, for example, will **not**
|
|
234
236
|
* work as intended. The `cancelled` event will not be returned in the browser due to platform
|