expo-image-picker 11.0.2 → 12.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 +25 -2
- package/README.md +1 -1
- package/android/build.gradle +16 -18
- package/android/src/main/java/expo/modules/imagepicker/ImagePickerModule.kt +1 -0
- package/android/src/main/java/expo/modules/imagepicker/ImagePickerOptions.kt +1 -0
- package/android/src/main/java/expo/modules/imagepicker/ImagePickerUtils.kt +1 -7
- package/build/ExponentImagePicker.web.js +4 -3
- package/build/ExponentImagePicker.web.js.map +1 -1
- package/build/ImagePicker.d.ts +70 -5
- package/build/ImagePicker.js +78 -14
- package/build/ImagePicker.js.map +1 -1
- package/build/ImagePicker.types.d.ts +215 -13
- package/build/ImagePicker.types.js +86 -0
- package/build/ImagePicker.types.js.map +1 -1
- package/ios/EXImagePicker/EXImagePicker.h +1 -1
- package/ios/EXImagePicker/EXImagePicker.m +8 -0
- package/package.json +6 -4
- package/plugin/build/withImagePicker.js +3 -3
- package/src/ExponentImagePicker.web.ts +4 -3
- package/src/ImagePicker.ts +89 -16
- package/src/ImagePicker.types.ts +231 -7
package/CHANGELOG.md
CHANGED
|
@@ -10,9 +10,32 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## 12.0.2 — 2022-02-01
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
### 🐛 Bug fixes
|
|
16
|
+
|
|
17
|
+
- Fix `Plugin with id 'maven' not found` build error from Android Gradle 7. ([#16080](https://github.com/expo/expo/pull/16080) by [@kudo](https://github.com/kudo))
|
|
18
|
+
|
|
19
|
+
## 12.0.1 — 2021-12-15
|
|
20
|
+
|
|
21
|
+
### 🐛 Bug fixes
|
|
22
|
+
|
|
23
|
+
- Fix unresolved promise when picker was dismissed with a swipe-down on iOS. ([#15511](https://github.com/expo/expo/pull/15511) by [@barthap](https://github.com/barthap))
|
|
24
|
+
|
|
25
|
+
## 12.0.0 — 2021-12-03
|
|
26
|
+
|
|
27
|
+
### 🛠 Breaking changes
|
|
28
|
+
|
|
29
|
+
- Remove typo workaround for `getMediaLibaryPermissionsAsync` method. ([#14646](https://github.com/expo/expo/pull/14646) by [@Simek](https://github.com/Simek))
|
|
30
|
+
|
|
31
|
+
### 🐛 Bug fixes
|
|
32
|
+
|
|
33
|
+
- On Web add missing `cancelled` property to the return values of `launchCameraAsync` and `launchImageLibraryAsync` methods. ([#14646](https://github.com/expo/expo/pull/14646) by [@Simek](https://github.com/Simek))
|
|
34
|
+
|
|
35
|
+
### 💡 Others
|
|
36
|
+
|
|
37
|
+
- Export missing types: `ImageInfo`, `ImagePickerMultipleResult`, `OpenFileBrowserOptions`, `ExpandImagePickerResult`, `UIImagePickerControllerQualityType` and `UIImagePickerPresentationStyle`. ([#14646](https://github.com/expo/expo/pull/14646) by [@Simek](https://github.com/Simek))
|
|
38
|
+
- Extract return object containing `{ cancelled: true }` to separate type `ImagePickerCancelledResult` for `launchCameraAsync` and `launchImageLibraryAsync` methods. ([#14646](https://github.com/expo/expo/pull/14646) by [@Simek](https://github.com/Simek))
|
|
16
39
|
|
|
17
40
|
## 11.0.1 — 2021-10-01
|
|
18
41
|
|
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ For managed [managed](https://docs.expo.io/versions/latest/introduction/managed-
|
|
|
13
13
|
|
|
14
14
|
# Installation in bare React Native projects
|
|
15
15
|
|
|
16
|
-
For bare React Native projects, you must ensure that you have [installed and configured the `
|
|
16
|
+
For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
|
|
17
17
|
|
|
18
18
|
### Add the package to your npm dependencies
|
|
19
19
|
|
package/android/build.gradle
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
2
|
apply plugin: 'kotlin-android'
|
|
3
|
-
apply plugin: 'maven'
|
|
3
|
+
apply plugin: 'maven-publish'
|
|
4
4
|
|
|
5
5
|
group = 'host.exp.exponent'
|
|
6
|
-
version = '
|
|
6
|
+
version = '12.0.2'
|
|
7
7
|
|
|
8
8
|
buildscript {
|
|
9
9
|
// Simple helper that allows the root project to override versions declared by this library.
|
|
@@ -21,27 +21,25 @@ buildscript {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
// Upload android library to maven with javadoc and android sources
|
|
25
|
-
configurations {
|
|
26
|
-
deployerJars
|
|
27
|
-
}
|
|
28
|
-
|
|
29
24
|
// Creating sources with comments
|
|
30
25
|
task androidSourcesJar(type: Jar) {
|
|
31
26
|
classifier = 'sources'
|
|
32
27
|
from android.sourceSets.main.java.srcDirs
|
|
33
28
|
}
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
30
|
+
afterEvaluate {
|
|
31
|
+
publishing {
|
|
32
|
+
publications {
|
|
33
|
+
release(MavenPublication) {
|
|
34
|
+
from components.release
|
|
35
|
+
// Add additional sourcesJar to artifacts
|
|
36
|
+
artifact(androidSourcesJar)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
repositories {
|
|
40
|
+
maven {
|
|
41
|
+
url = mavenLocal().url
|
|
42
|
+
}
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
}
|
|
@@ -58,7 +56,7 @@ android {
|
|
|
58
56
|
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
59
57
|
targetSdkVersion safeExtGet("targetSdkVersion", 30)
|
|
60
58
|
versionCode 22
|
|
61
|
-
versionName "
|
|
59
|
+
versionName "12.0.2"
|
|
62
60
|
}
|
|
63
61
|
lintOptions {
|
|
64
62
|
abortOnError false
|
|
@@ -22,6 +22,7 @@ import expo.modules.core.interfaces.ExpoMethod
|
|
|
22
22
|
import expo.modules.core.interfaces.LifecycleEventListener
|
|
23
23
|
import expo.modules.core.interfaces.services.UIManager
|
|
24
24
|
import expo.modules.core.utilities.FileUtilities.generateOutputPath
|
|
25
|
+
import expo.modules.core.utilities.ifNull
|
|
25
26
|
import expo.modules.imagepicker.ImagePickerOptions.Companion.optionsFromMap
|
|
26
27
|
import expo.modules.imagepicker.exporters.CompressionImageExporter
|
|
27
28
|
import expo.modules.imagepicker.exporters.CropImageExporter
|
|
@@ -8,16 +8,10 @@ import android.webkit.MimeTypeMap
|
|
|
8
8
|
import androidx.core.content.FileProvider
|
|
9
9
|
import androidx.exifinterface.media.ExifInterface
|
|
10
10
|
import expo.modules.core.utilities.FileUtilities.generateOutputPath
|
|
11
|
+
import expo.modules.core.utilities.ifNull
|
|
11
12
|
import java.io.File
|
|
12
13
|
import java.io.IOException
|
|
13
14
|
|
|
14
|
-
inline fun <T> T?.ifNull(block: () -> T): T {
|
|
15
|
-
if (this == null) {
|
|
16
|
-
return block()
|
|
17
|
-
}
|
|
18
|
-
return this
|
|
19
|
-
}
|
|
20
|
-
|
|
21
15
|
private fun getTypeFromFileUrl(url: String): String? {
|
|
22
16
|
val extension = MimeTypeMap.getFileExtensionFromUrl(url)
|
|
23
17
|
return if (extension != null) MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) else null
|
|
@@ -81,7 +81,6 @@ function openFileBrowserAsync({ mediaTypes, capture = false, allowsMultipleSelec
|
|
|
81
81
|
if (!allowsMultipleSelection) {
|
|
82
82
|
const img = await readFile(input.files[0], { base64 });
|
|
83
83
|
resolve({
|
|
84
|
-
cancelled: false,
|
|
85
84
|
...img,
|
|
86
85
|
});
|
|
87
86
|
}
|
|
@@ -111,14 +110,16 @@ function readFile(targetFile, options) {
|
|
|
111
110
|
uri,
|
|
112
111
|
width: 0,
|
|
113
112
|
height: 0,
|
|
113
|
+
cancelled: false,
|
|
114
114
|
});
|
|
115
|
-
if (typeof
|
|
115
|
+
if (typeof uri === 'string') {
|
|
116
116
|
const image = new Image();
|
|
117
|
-
image.src =
|
|
117
|
+
image.src = uri;
|
|
118
118
|
image.onload = () => resolve({
|
|
119
119
|
uri,
|
|
120
120
|
width: image.naturalWidth ?? image.width,
|
|
121
121
|
height: image.naturalHeight ?? image.height,
|
|
122
|
+
cancelled: false,
|
|
122
123
|
// The blob's result cannot be directly decoded as Base64 without
|
|
123
124
|
// first removing the Data-URL declaration preceding the
|
|
124
125
|
// Base64-encoded data. To retrieve only the Base64 encoded string,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExponentImagePicker.web.js","sourceRoot":"","sources":["../src/ExponentImagePicker.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,gBAAgB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAE1B,OAAO,EAKL,gBAAgB,GAEjB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,cAAc,GAAG;IACrB,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,uDAAuD;IAC/E,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,SAAS;IACpC,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,+CAA+C;CAC3E,CAAC;AAEF,eAAe;IACb,IAAI,IAAI;QACN,OAAO,qBAAqB,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,EAC5B,UAAU,GAAG,gBAAgB,CAAC,MAAM,EACpC,uBAAuB,GAAG,KAAK,EAC/B,MAAM,GAAG,KAAK,GACf;QACC,YAAY;QACZ,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE;YAC5B,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;SAC5B;QACD,OAAO,MAAM,oBAAoB,CAAC;YAChC,UAAU;YACV,uBAAuB;YACvB,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,EACtB,UAAU,GAAG,gBAAgB,CAAC,MAA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AChB,iEAAiE;oBACjE,wDAAwD;oBACxD,mEAAmE;oBACnE,iDAAiD;oBACjD,4EAA4E;oBAC5E,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;iBACpE,CAAC,CAAC;gBACL,KAAK,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,SAAS,EAAE,CAAC;aACnC;iBAAM;gBACL,SAAS,EAAE,CAAC;aACb;QACH,CAAC,CAAC;QAEF,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { PermissionResponse, PermissionStatus, Platform } from 'expo-modules-core';\nimport { v4 } from 'uuid';\n\nimport {\n ExpandImagePickerResult,\n ImageInfo,\n ImagePickerMultipleResult,\n ImagePickerResult,\n MediaTypeOptions,\n OpenFileBrowserOptions,\n} from './ImagePicker.types';\n\nconst MediaTypeInput = {\n [MediaTypeOptions.All]: 'video/mp4,video/quicktime,video/x-m4v,video/*,image/*',\n [MediaTypeOptions.Images]: 'image/*',\n [MediaTypeOptions.Videos]: 'video/mp4,video/quicktime,video/x-m4v,video/*',\n};\n\nexport default {\n get name(): string {\n return 'ExponentImagePicker';\n },\n\n async launchImageLibraryAsync({\n mediaTypes = MediaTypeOptions.Images,\n allowsMultipleSelection = false,\n base64 = false,\n }): Promise<ImagePickerResult | ImagePickerMultipleResult> {\n // SSR guard\n if (!Platform.isDOMAvailable) {\n return { cancelled: true };\n }\n return await openFileBrowserAsync({\n mediaTypes,\n allowsMultipleSelection,\n base64,\n });\n },\n\n async launchCameraAsync({\n mediaTypes = MediaTypeOptions.Images,\n allowsMultipleSelection = false,\n base64 = false,\n }): Promise<ImagePickerResult | ImagePickerMultipleResult> {\n // SSR guard\n if (!Platform.isDOMAvailable) {\n return { cancelled: true };\n }\n return await openFileBrowserAsync({\n mediaTypes,\n allowsMultipleSelection,\n capture: true,\n base64,\n });\n },\n\n /*\n * Delegate to expo-permissions to request camera permissions\n */\n async getCameraPermissionsAsync() {\n return permissionGrantedResponse();\n },\n async requestCameraPermissionsAsync() {\n return permissionGrantedResponse();\n },\n\n /*\n * Camera roll permissions don't need to be requested on web, so we always\n * respond with granted.\n */\n async getMediaLibraryPermissionsAsync(_writeOnly: boolean) {\n return permissionGrantedResponse();\n },\n async requestMediaLibraryPermissionsAsync(_writeOnly: boolean): Promise<PermissionResponse> {\n return permissionGrantedResponse();\n },\n};\n\nfunction permissionGrantedResponse(): PermissionResponse {\n return {\n status: PermissionStatus.GRANTED,\n expires: 'never',\n granted: true,\n canAskAgain: true,\n };\n}\n\nfunction openFileBrowserAsync<T extends OpenFileBrowserOptions>({\n mediaTypes,\n capture = false,\n allowsMultipleSelection = false,\n base64,\n}: T): Promise<ExpandImagePickerResult<T>> {\n const mediaTypeFormat = MediaTypeInput[mediaTypes];\n\n const input = document.createElement('input');\n input.style.display = 'none';\n input.setAttribute('type', 'file');\n input.setAttribute('accept', mediaTypeFormat);\n input.setAttribute('id', v4());\n if (allowsMultipleSelection) {\n input.setAttribute('multiple', 'multiple');\n }\n if (capture) {\n input.setAttribute('capture', 'camera');\n }\n document.body.appendChild(input);\n\n return new Promise((resolve, reject) => {\n input.addEventListener('change', async () => {\n if (input.files) {\n if (!allowsMultipleSelection) {\n const img: ImageInfo = await readFile(input.files[0], { base64 });\n resolve({\n ...img,\n } as ExpandImagePickerResult<T>);\n } else {\n const imgs: ImageInfo[] = await Promise.all(\n Array.from(input.files).map((file) => readFile(file, { base64 }))\n );\n resolve({\n cancelled: false,\n selected: imgs,\n } as ExpandImagePickerResult<T>);\n }\n }\n document.body.removeChild(input);\n });\n\n const event = new MouseEvent('click');\n input.dispatchEvent(event);\n });\n}\n\nfunction readFile(targetFile: Blob, options: { base64: boolean }): Promise<ImageInfo> {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.onerror = () => {\n reject(new Error(`Failed to read the selected media because the operation failed.`));\n };\n reader.onload = ({ target }) => {\n const uri = (target as any).result;\n const returnRaw = () =>\n resolve({\n uri,\n width: 0,\n height: 0,\n cancelled: false,\n });\n\n if (typeof uri === 'string') {\n const image = new Image();\n image.src = uri;\n image.onload = () =>\n resolve({\n uri,\n width: image.naturalWidth ?? image.width,\n height: image.naturalHeight ?? image.height,\n cancelled: false,\n // The blob's result cannot be directly decoded as Base64 without\n // first removing the Data-URL declaration preceding the\n // Base64-encoded data. To retrieve only the Base64 encoded string,\n // first remove data:*/*;base64, from the result.\n // https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL\n ...(options.base64 && { base64: uri.substr(uri.indexOf(',') + 1) }),\n });\n image.onerror = () => returnRaw();\n } else {\n returnRaw();\n }\n };\n\n reader.readAsDataURL(targetFile);\n });\n}\n"]}
|
package/build/ImagePicker.d.ts
CHANGED
|
@@ -1,16 +1,35 @@
|
|
|
1
1
|
import { PermissionStatus, PermissionExpiration, PermissionHookOptions } from 'expo-modules-core';
|
|
2
|
-
import { CameraPermissionResponse, CameraRollPermissionResponse, MediaLibraryPermissionResponse, ImagePickerResult, ImagePickerErrorResult, MediaTypeOptions, ImagePickerOptions, VideoExportPreset, ExpandImagePickerResult } from './ImagePicker.types';
|
|
2
|
+
import { CameraPermissionResponse, CameraRollPermissionResponse, MediaLibraryPermissionResponse, ImagePickerResult, ImagePickerErrorResult, MediaTypeOptions, ImagePickerOptions, VideoExportPreset, ExpandImagePickerResult, ImageInfo, ImagePickerMultipleResult, ImagePickerCancelledResult, OpenFileBrowserOptions, UIImagePickerControllerQualityType, UIImagePickerPresentationStyle } from './ImagePicker.types';
|
|
3
|
+
/**
|
|
4
|
+
* Checks user's permissions for accessing camera.
|
|
5
|
+
* @return A promise that fulfills with an object of type [CameraPermissionResponse](#imagepickercamerapermissionresponse).
|
|
6
|
+
*/
|
|
3
7
|
export declare function getCameraPermissionsAsync(): Promise<CameraPermissionResponse>;
|
|
4
8
|
/**
|
|
5
|
-
* @deprecated
|
|
9
|
+
* @deprecated Use `getMediaLibraryPermissionsAsync()` instead.
|
|
6
10
|
*/
|
|
7
11
|
export declare function getCameraRollPermissionsAsync(): Promise<MediaLibraryPermissionResponse>;
|
|
12
|
+
/**
|
|
13
|
+
* Checks user's permissions for accessing photos.
|
|
14
|
+
* @param writeOnly Whether to request write or read and write permissions. Defaults to `false`
|
|
15
|
+
* @return A promise that fulfills with an object of type [MediaLibraryPermissionResponse](#imagepickercamerarollpermissionresponse).
|
|
16
|
+
*/
|
|
8
17
|
export declare function getMediaLibraryPermissionsAsync(writeOnly?: boolean): Promise<MediaLibraryPermissionResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Asks the user to grant permissions for accessing camera. This does nothing on web because the
|
|
20
|
+
* browser camera is not used.
|
|
21
|
+
* @return A promise that fulfills with an object of type [CameraPermissionResponse](#imagepickercamerapermissionresponse).
|
|
22
|
+
*/
|
|
9
23
|
export declare function requestCameraPermissionsAsync(): Promise<CameraPermissionResponse>;
|
|
10
24
|
/**
|
|
11
|
-
* @deprecated
|
|
25
|
+
* @deprecated Use `requestMediaLibraryPermissionsAsync()` instead.
|
|
12
26
|
*/
|
|
13
27
|
export declare function requestCameraRollPermissionsAsync(): Promise<MediaLibraryPermissionResponse>;
|
|
28
|
+
/**
|
|
29
|
+
* Asks the user to grant permissions for accessing user's photo. This method does nothing on web.
|
|
30
|
+
* @param writeOnly Whether to request write or read and write permissions. Defaults to `false`
|
|
31
|
+
* @return A promise that fulfills with an object of type [MediaLibraryPermissionResponse](#imagepickercamerarollpermissionresponse).
|
|
32
|
+
*/
|
|
14
33
|
export declare function requestMediaLibraryPermissionsAsync(writeOnly?: boolean): Promise<MediaLibraryPermissionResponse>;
|
|
15
34
|
/**
|
|
16
35
|
* Check or request permissions to access the media library.
|
|
@@ -33,8 +52,54 @@ export declare const useMediaLibraryPermissions: (options?: PermissionHookOption
|
|
|
33
52
|
* const [status, requestPermission] = ImagePicker.useCameraPermissions();
|
|
34
53
|
* ```
|
|
35
54
|
*/
|
|
36
|
-
export declare const useCameraPermissions: (options?: PermissionHookOptions<object> | undefined) => [
|
|
55
|
+
export declare const useCameraPermissions: (options?: PermissionHookOptions<object> | undefined) => [import("expo-modules-core").PermissionResponse | null, () => Promise<import("expo-modules-core").PermissionResponse>, () => Promise<import("expo-modules-core").PermissionResponse>];
|
|
56
|
+
/**
|
|
57
|
+
* Android system sometimes kills the `MainActivity` after the `ImagePicker` finishes. When this
|
|
58
|
+
* happens, we lost the data selected from the `ImagePicker`. However, you can retrieve the lost
|
|
59
|
+
* data by calling `getPendingResultAsync`. You can test this functionality by turning on
|
|
60
|
+
* `Don't keep activities` in the developer options.
|
|
61
|
+
* @return
|
|
62
|
+
* - **On Android:** a promise that resolves to an array of objects of exactly same type as in
|
|
63
|
+
* `ImagePicker.launchImageLibraryAsync` or `ImagePicker.launchCameraAsync` if the `ImagePicker`
|
|
64
|
+
* finished successfully. Otherwise, to the array of [`ImagePickerErrorResult`](#imagepickerimagepickererrorresult).
|
|
65
|
+
* - **On other platforms:** an empty array.
|
|
66
|
+
*/
|
|
37
67
|
export declare function getPendingResultAsync(): Promise<(ImagePickerResult | ImagePickerErrorResult)[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Display the system UI for taking a photo with the camera. Requires `Permissions.CAMERA`.
|
|
70
|
+
* On Android and iOS 10 `Permissions.CAMERA_ROLL` is also required. On mobile web, this must be
|
|
71
|
+
* called immediately in a user interaction like a button press, otherwise the browser will bloc
|
|
72
|
+
* the request without a warning.
|
|
73
|
+
* > **Note:** Make sure that you handle `MainActivity` destruction on **Android**. See [ImagePicker.getPendingResultAsync](#imagepickergetpendingresultasync).
|
|
74
|
+
* > **Notes for Web:** The system UI can only be shown after user activation (e.g. a `Button` press).
|
|
75
|
+
* Therefore, calling `launchCameraAsync` in `componentDidMount`, for example, will **not** work as
|
|
76
|
+
* intended. The `cancelled` event will not be returned in the browser due to platform restrictions
|
|
77
|
+
* and inconsistencies across browsers.
|
|
78
|
+
* @param options An `ImagePickerOptions` object.
|
|
79
|
+
* @return If the user cancelled the action, the method returns `{ cancelled: true }`. Otherwise,
|
|
80
|
+
* this method returns information about the selected media item. When the chosen item is an image,
|
|
81
|
+
* this method returns `{ cancelled: false, type: 'image', uri, width, height, exif, base64 }`;
|
|
82
|
+
* when the item is a video, this method returns `{ cancelled: false, type: 'video', uri, width, height, duration }`.
|
|
83
|
+
*/
|
|
38
84
|
export declare function launchCameraAsync(options?: ImagePickerOptions): Promise<ImagePickerResult>;
|
|
85
|
+
/**
|
|
86
|
+
* Display the system UI for choosing an image or a video from the phone's library.
|
|
87
|
+
* Requires `Permissions.MEDIA_LIBRARY` on iOS 10 only. On mobile web, this must be called
|
|
88
|
+
* immediately in a user interaction like a button press, otherwise the browser will block the
|
|
89
|
+
* request without a warning.
|
|
90
|
+
* **Animated GIFs support** If the selected image is an animated GIF, the result image will be an
|
|
91
|
+
* animated GIF too if and only if `quality` is set to `undefined` and `allowsEditing` is set to `false`.
|
|
92
|
+
* Otherwise compression and/or cropper will pick the first frame of the GIF and return it as the
|
|
93
|
+
* result (on Android the result will be a PNG, on iOS — GIF).
|
|
94
|
+
* > **Notes for Web:** The system UI can only be shown after user activation (e.g. a `Button` press).
|
|
95
|
+
* Therefore, calling `launchImageLibraryAsync` in `componentDidMount`, for example, will **not**
|
|
96
|
+
* work as intended. The `cancelled` event will not be returned in the browser due to platform
|
|
97
|
+
* restrictions and inconsistencies across browsers.
|
|
98
|
+
* @param options An object extended by [`ImagePickerOptions`](#imagepickeroptions).
|
|
99
|
+
* @return If the user cancelled the action, the method returns `{ cancelled: true }`. Otherwise,
|
|
100
|
+
* this method returns information about the selected media item. When the chosen item is an image,
|
|
101
|
+
* this method returns `{ cancelled: false, type: 'image', uri, width, height, exif, base64 }`;
|
|
102
|
+
* when the item is a video, this method returns `{ cancelled: false, type: 'video', uri, width, height, duration }`.
|
|
103
|
+
*/
|
|
39
104
|
export declare function launchImageLibraryAsync<T extends ImagePickerOptions>(options?: T): Promise<ExpandImagePickerResult<T>>;
|
|
40
|
-
export { MediaTypeOptions, ImagePickerOptions, ImagePickerResult, ImagePickerErrorResult, VideoExportPreset, CameraPermissionResponse, CameraRollPermissionResponse, MediaLibraryPermissionResponse, PermissionStatus, PermissionExpiration, PermissionHookOptions, };
|
|
105
|
+
export { MediaTypeOptions, ImagePickerOptions, ImagePickerResult, ImagePickerErrorResult, VideoExportPreset, CameraPermissionResponse, CameraRollPermissionResponse, MediaLibraryPermissionResponse, PermissionStatus, PermissionExpiration, PermissionHookOptions, ImageInfo, ImagePickerMultipleResult, ImagePickerCancelledResult, OpenFileBrowserOptions, ExpandImagePickerResult, UIImagePickerControllerQualityType, UIImagePickerPresentationStyle, };
|
package/build/ImagePicker.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PermissionStatus, createPermissionHook, UnavailabilityError, CodedError, } from 'expo-modules-core';
|
|
2
2
|
import ExponentImagePicker from './ExponentImagePicker';
|
|
3
|
-
import { MediaTypeOptions, VideoExportPreset, } from './ImagePicker.types';
|
|
3
|
+
import { MediaTypeOptions, VideoExportPreset, UIImagePickerControllerQualityType, UIImagePickerPresentationStyle, } from './ImagePicker.types';
|
|
4
4
|
function validateOptions(options) {
|
|
5
5
|
const { aspect, quality, videoMaxDuration } = options;
|
|
6
6
|
if (aspect != null) {
|
|
@@ -17,40 +17,55 @@ function validateOptions(options) {
|
|
|
17
17
|
}
|
|
18
18
|
return options;
|
|
19
19
|
}
|
|
20
|
+
// @needsAudit
|
|
21
|
+
/**
|
|
22
|
+
* Checks user's permissions for accessing camera.
|
|
23
|
+
* @return A promise that fulfills with an object of type [CameraPermissionResponse](#imagepickercamerapermissionresponse).
|
|
24
|
+
*/
|
|
20
25
|
export async function getCameraPermissionsAsync() {
|
|
21
26
|
return ExponentImagePicker.getCameraPermissionsAsync();
|
|
22
27
|
}
|
|
23
28
|
/**
|
|
24
|
-
* @deprecated
|
|
29
|
+
* @deprecated Use `getMediaLibraryPermissionsAsync()` instead.
|
|
25
30
|
*/
|
|
26
31
|
export async function getCameraRollPermissionsAsync() {
|
|
27
32
|
console.warn('ImagePicker.getCameraRollPermissionsAsync() is deprecated in favour of ImagePicker.getMediaLibraryPermissionsAsync()');
|
|
28
33
|
return getMediaLibraryPermissionsAsync();
|
|
29
34
|
}
|
|
35
|
+
// @needsAudit
|
|
36
|
+
/**
|
|
37
|
+
* Checks user's permissions for accessing photos.
|
|
38
|
+
* @param writeOnly Whether to request write or read and write permissions. Defaults to `false`
|
|
39
|
+
* @return A promise that fulfills with an object of type [MediaLibraryPermissionResponse](#imagepickercamerarollpermissionresponse).
|
|
40
|
+
*/
|
|
30
41
|
export async function getMediaLibraryPermissionsAsync(writeOnly = false) {
|
|
31
|
-
|
|
32
|
-
// todo: remove this workaround for SDK 41
|
|
33
|
-
const imagePickerMethod = typeof ExponentImagePicker.getMediaLibaryPermissionsAsync === 'function'
|
|
34
|
-
? ExponentImagePicker.getMediaLibaryPermissionsAsync
|
|
35
|
-
: ExponentImagePicker.getMediaLibraryPermissionsAsync;
|
|
42
|
+
const imagePickerMethod = ExponentImagePicker.getMediaLibraryPermissionsAsync;
|
|
36
43
|
return imagePickerMethod(writeOnly);
|
|
37
44
|
}
|
|
45
|
+
// @needsAudit
|
|
46
|
+
/**
|
|
47
|
+
* Asks the user to grant permissions for accessing camera. This does nothing on web because the
|
|
48
|
+
* browser camera is not used.
|
|
49
|
+
* @return A promise that fulfills with an object of type [CameraPermissionResponse](#imagepickercamerapermissionresponse).
|
|
50
|
+
*/
|
|
38
51
|
export async function requestCameraPermissionsAsync() {
|
|
39
52
|
return ExponentImagePicker.requestCameraPermissionsAsync();
|
|
40
53
|
}
|
|
41
54
|
/**
|
|
42
|
-
* @deprecated
|
|
55
|
+
* @deprecated Use `requestMediaLibraryPermissionsAsync()` instead.
|
|
43
56
|
*/
|
|
44
57
|
export async function requestCameraRollPermissionsAsync() {
|
|
45
58
|
console.warn('ImagePicker.requestCameraRollPermissionsAsync() is deprecated in favour of ImagePicker.requestMediaLibraryPermissionsAsync()');
|
|
46
59
|
return requestMediaLibraryPermissionsAsync();
|
|
47
60
|
}
|
|
61
|
+
// @needsAudit
|
|
62
|
+
/**
|
|
63
|
+
* Asks the user to grant permissions for accessing user's photo. This method does nothing on web.
|
|
64
|
+
* @param writeOnly Whether to request write or read and write permissions. Defaults to `false`
|
|
65
|
+
* @return A promise that fulfills with an object of type [MediaLibraryPermissionResponse](#imagepickercamerarollpermissionresponse).
|
|
66
|
+
*/
|
|
48
67
|
export async function requestMediaLibraryPermissionsAsync(writeOnly = false) {
|
|
49
|
-
|
|
50
|
-
// todo: remove this workaround for SDK 41
|
|
51
|
-
const imagePickerMethod = typeof ExponentImagePicker.requestMediaLibaryPermissionsAsync === 'function'
|
|
52
|
-
? ExponentImagePicker.requestMediaLibaryPermissionsAsync
|
|
53
|
-
: ExponentImagePicker.requestMediaLibraryPermissionsAsync;
|
|
68
|
+
const imagePickerMethod = ExponentImagePicker.requestMediaLibraryPermissionsAsync;
|
|
54
69
|
return imagePickerMethod(writeOnly);
|
|
55
70
|
}
|
|
56
71
|
// @needsAudit
|
|
@@ -82,23 +97,72 @@ export const useCameraPermissions = createPermissionHook({
|
|
|
82
97
|
getMethod: getCameraPermissionsAsync,
|
|
83
98
|
requestMethod: requestCameraPermissionsAsync,
|
|
84
99
|
});
|
|
100
|
+
// @needsAudit
|
|
101
|
+
/**
|
|
102
|
+
* Android system sometimes kills the `MainActivity` after the `ImagePicker` finishes. When this
|
|
103
|
+
* happens, we lost the data selected from the `ImagePicker`. However, you can retrieve the lost
|
|
104
|
+
* data by calling `getPendingResultAsync`. You can test this functionality by turning on
|
|
105
|
+
* `Don't keep activities` in the developer options.
|
|
106
|
+
* @return
|
|
107
|
+
* - **On Android:** a promise that resolves to an array of objects of exactly same type as in
|
|
108
|
+
* `ImagePicker.launchImageLibraryAsync` or `ImagePicker.launchCameraAsync` if the `ImagePicker`
|
|
109
|
+
* finished successfully. Otherwise, to the array of [`ImagePickerErrorResult`](#imagepickerimagepickererrorresult).
|
|
110
|
+
* - **On other platforms:** an empty array.
|
|
111
|
+
*/
|
|
85
112
|
export async function getPendingResultAsync() {
|
|
86
113
|
if (ExponentImagePicker.getPendingResultAsync) {
|
|
87
114
|
return ExponentImagePicker.getPendingResultAsync();
|
|
88
115
|
}
|
|
89
116
|
return [];
|
|
90
117
|
}
|
|
118
|
+
// @needsAudit
|
|
119
|
+
/**
|
|
120
|
+
* Display the system UI for taking a photo with the camera. Requires `Permissions.CAMERA`.
|
|
121
|
+
* On Android and iOS 10 `Permissions.CAMERA_ROLL` is also required. On mobile web, this must be
|
|
122
|
+
* called immediately in a user interaction like a button press, otherwise the browser will bloc
|
|
123
|
+
* the request without a warning.
|
|
124
|
+
* > **Note:** Make sure that you handle `MainActivity` destruction on **Android**. See [ImagePicker.getPendingResultAsync](#imagepickergetpendingresultasync).
|
|
125
|
+
* > **Notes for Web:** The system UI can only be shown after user activation (e.g. a `Button` press).
|
|
126
|
+
* Therefore, calling `launchCameraAsync` in `componentDidMount`, for example, will **not** work as
|
|
127
|
+
* intended. The `cancelled` event will not be returned in the browser due to platform restrictions
|
|
128
|
+
* and inconsistencies across browsers.
|
|
129
|
+
* @param options An `ImagePickerOptions` object.
|
|
130
|
+
* @return If the user cancelled the action, the method returns `{ cancelled: true }`. Otherwise,
|
|
131
|
+
* this method returns information about the selected media item. When the chosen item is an image,
|
|
132
|
+
* this method returns `{ cancelled: false, type: 'image', uri, width, height, exif, base64 }`;
|
|
133
|
+
* when the item is a video, this method returns `{ cancelled: false, type: 'video', uri, width, height, duration }`.
|
|
134
|
+
*/
|
|
91
135
|
export async function launchCameraAsync(options = {}) {
|
|
92
136
|
if (!ExponentImagePicker.launchCameraAsync) {
|
|
93
137
|
throw new UnavailabilityError('ImagePicker', 'launchCameraAsync');
|
|
94
138
|
}
|
|
95
139
|
return await ExponentImagePicker.launchCameraAsync(validateOptions(options));
|
|
96
140
|
}
|
|
141
|
+
// @needsAudit
|
|
142
|
+
/**
|
|
143
|
+
* Display the system UI for choosing an image or a video from the phone's library.
|
|
144
|
+
* Requires `Permissions.MEDIA_LIBRARY` on iOS 10 only. On mobile web, this must be called
|
|
145
|
+
* immediately in a user interaction like a button press, otherwise the browser will block the
|
|
146
|
+
* request without a warning.
|
|
147
|
+
* **Animated GIFs support** If the selected image is an animated GIF, the result image will be an
|
|
148
|
+
* animated GIF too if and only if `quality` is set to `undefined` and `allowsEditing` is set to `false`.
|
|
149
|
+
* Otherwise compression and/or cropper will pick the first frame of the GIF and return it as the
|
|
150
|
+
* result (on Android the result will be a PNG, on iOS — GIF).
|
|
151
|
+
* > **Notes for Web:** The system UI can only be shown after user activation (e.g. a `Button` press).
|
|
152
|
+
* Therefore, calling `launchImageLibraryAsync` in `componentDidMount`, for example, will **not**
|
|
153
|
+
* work as intended. The `cancelled` event will not be returned in the browser due to platform
|
|
154
|
+
* restrictions and inconsistencies across browsers.
|
|
155
|
+
* @param options An object extended by [`ImagePickerOptions`](#imagepickeroptions).
|
|
156
|
+
* @return If the user cancelled the action, the method returns `{ cancelled: true }`. Otherwise,
|
|
157
|
+
* this method returns information about the selected media item. When the chosen item is an image,
|
|
158
|
+
* this method returns `{ cancelled: false, type: 'image', uri, width, height, exif, base64 }`;
|
|
159
|
+
* when the item is a video, this method returns `{ cancelled: false, type: 'video', uri, width, height, duration }`.
|
|
160
|
+
*/
|
|
97
161
|
export async function launchImageLibraryAsync(options) {
|
|
98
162
|
if (!ExponentImagePicker.launchImageLibraryAsync) {
|
|
99
163
|
throw new UnavailabilityError('ImagePicker', 'launchImageLibraryAsync');
|
|
100
164
|
}
|
|
101
165
|
return await ExponentImagePicker.launchImageLibraryAsync(options ?? {});
|
|
102
166
|
}
|
|
103
|
-
export { MediaTypeOptions, VideoExportPreset, PermissionStatus, };
|
|
167
|
+
export { MediaTypeOptions, VideoExportPreset, PermissionStatus, UIImagePickerControllerQualityType, UIImagePickerPresentationStyle, };
|
|
104
168
|
//# sourceMappingURL=ImagePicker.js.map
|
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,EAGhB,oBAAoB,EACpB,mBAAmB,EACnB,UAAU,GACX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,mBAAmB,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAML,gBAAgB,EAEhB,iBAAiB,GAElB,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;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,yBAAyB;IAC7C,OAAO,mBAAmB,CAAC,yBAAyB,EAAE,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,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ACpF,CAAC,CAAC;AAEH,cAAc;AACd;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,oBAAoB,CAAC;IACvD,SAAS,EAAE,yBAAyB;IACpC,aAAa,EAAE,6BAA6B;CAC7C,CAAC,CAAC;AAEH,MAAM,CAAC,KAAK,UAAU,qBAAqB;IAGzC,IAAI,mBAAmB,CAAC,qBAAqB,EAAE;QAC7C,OAAO,mBAAmB,CAAC,qBAAqB,EAAE,CAAC;KACpD;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,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,OAAO,MAAM,mBAAmB,CAAC,iBAAiB,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;AAC/E,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAAW;IAEX,IAAI,CAAC,mBAAmB,CAAC,uBAAuB,EAAE;QAChD,MAAM,IAAI,mBAAmB,CAAC,aAAa,EAAE,yBAAyB,CAAC,CAAC;KACzE;IACD,OAAO,MAAM,mBAAmB,CAAC,uBAAuB,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;AAC1E,CAAC;AAED,OAAO,EACL,gBAAgB,EAIhB,iBAAiB,EAIjB,gBAAgB,GAGjB,CAAC","sourcesContent":["import {\n PermissionStatus,\n PermissionExpiration,\n PermissionHookOptions,\n createPermissionHook,\n UnavailabilityError,\n CodedError,\n} from 'expo-modules-core';\n\nimport ExponentImagePicker from './ExponentImagePicker';\nimport {\n CameraPermissionResponse,\n CameraRollPermissionResponse,\n MediaLibraryPermissionResponse,\n ImagePickerResult,\n ImagePickerErrorResult,\n MediaTypeOptions,\n ImagePickerOptions,\n VideoExportPreset,\n ExpandImagePickerResult,\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\nexport async function getCameraPermissionsAsync(): Promise<CameraPermissionResponse> {\n return ExponentImagePicker.getCameraPermissionsAsync();\n}\n\n/**\n * @deprecated in favor of getMediaLibraryPermissionsAsync()\n */\nexport async function getCameraRollPermissionsAsync(): Promise<MediaLibraryPermissionResponse> {\n console.warn(\n 'ImagePicker.getCameraRollPermissionsAsync() is deprecated in favour of ImagePicker.getMediaLibraryPermissionsAsync()'\n );\n return getMediaLibraryPermissionsAsync();\n}\n\nexport async function getMediaLibraryPermissionsAsync(\n writeOnly: boolean = false\n): Promise<MediaLibraryPermissionResponse> {\n // due to a typo in iOS, we need to check on the typo too\n // todo: remove this workaround for SDK 41\n const imagePickerMethod =\n typeof ExponentImagePicker.getMediaLibaryPermissionsAsync === 'function'\n ? ExponentImagePicker.getMediaLibaryPermissionsAsync\n : ExponentImagePicker.getMediaLibraryPermissionsAsync;\n\n return imagePickerMethod(writeOnly);\n}\n\nexport async function requestCameraPermissionsAsync(): Promise<CameraPermissionResponse> {\n return ExponentImagePicker.requestCameraPermissionsAsync();\n}\n\n/**\n * @deprecated in favor of requestMediaLibraryPermissionsAsync()\n */\nexport async function requestCameraRollPermissionsAsync(): Promise<MediaLibraryPermissionResponse> {\n console.warn(\n 'ImagePicker.requestCameraRollPermissionsAsync() is deprecated in favour of ImagePicker.requestMediaLibraryPermissionsAsync()'\n );\n return requestMediaLibraryPermissionsAsync();\n}\n\nexport async function requestMediaLibraryPermissionsAsync(\n writeOnly: boolean = false\n): Promise<MediaLibraryPermissionResponse> {\n // due to a typo in iOS, we need to check on the typo too\n // todo: remove this workaround for SDK 41\n const imagePickerMethod =\n typeof ExponentImagePicker.requestMediaLibaryPermissionsAsync === 'function'\n ? ExponentImagePicker.requestMediaLibaryPermissionsAsync\n : ExponentImagePicker.requestMediaLibraryPermissionsAsync;\n\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\nexport async function getPendingResultAsync(): Promise<\n (ImagePickerResult | ImagePickerErrorResult)[]\n> {\n if (ExponentImagePicker.getPendingResultAsync) {\n return ExponentImagePicker.getPendingResultAsync();\n }\n return [];\n}\n\nexport async function launchCameraAsync(\n options: ImagePickerOptions = {}\n): Promise<ImagePickerResult> {\n if (!ExponentImagePicker.launchCameraAsync) {\n throw new UnavailabilityError('ImagePicker', 'launchCameraAsync');\n }\n return await ExponentImagePicker.launchCameraAsync(validateOptions(options));\n}\n\nexport async function launchImageLibraryAsync<T extends ImagePickerOptions>(\n options?: T\n): Promise<ExpandImagePickerResult<T>> {\n if (!ExponentImagePicker.launchImageLibraryAsync) {\n throw new UnavailabilityError('ImagePicker', 'launchImageLibraryAsync');\n }\n return await ExponentImagePicker.launchImageLibraryAsync(options ?? {});\n}\n\nexport {\n MediaTypeOptions,\n ImagePickerOptions,\n ImagePickerResult,\n ImagePickerErrorResult,\n VideoExportPreset,\n CameraPermissionResponse,\n CameraRollPermissionResponse,\n MediaLibraryPermissionResponse,\n PermissionStatus,\n PermissionExpiration,\n PermissionHookOptions,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"ImagePicker.js","sourceRoot":"","sources":["../src/ImagePicker.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAGhB,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,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IjB,gBAAgB,EAQhB,kCAAkC,EAClC,8BAA8B,GAC/B,CAAC","sourcesContent":["import {\n PermissionStatus,\n PermissionExpiration,\n PermissionHookOptions,\n createPermissionHook,\n UnavailabilityError,\n CodedError,\n} from 'expo-modules-core';\n\nimport ExponentImagePicker from './ExponentImagePicker';\nimport {\n CameraPermissionResponse,\n CameraRollPermissionResponse,\n MediaLibraryPermissionResponse,\n ImagePickerResult,\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\n// @needsAudit\n/**\n * Checks user's permissions for accessing camera.\n * @return A promise that fulfills with an object of type [CameraPermissionResponse](#imagepickercamerapermissionresponse).\n */\nexport async function getCameraPermissionsAsync(): Promise<CameraPermissionResponse> {\n return ExponentImagePicker.getCameraPermissionsAsync();\n}\n\n/**\n * @deprecated Use `getMediaLibraryPermissionsAsync()` instead.\n */\nexport async function getCameraRollPermissionsAsync(): Promise<MediaLibraryPermissionResponse> {\n console.warn(\n 'ImagePicker.getCameraRollPermissionsAsync() is deprecated in favour of ImagePicker.getMediaLibraryPermissionsAsync()'\n );\n return getMediaLibraryPermissionsAsync();\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](#imagepickercamerarollpermissionresponse).\n */\nexport async function getMediaLibraryPermissionsAsync(\n writeOnly: boolean = false\n): Promise<MediaLibraryPermissionResponse> {\n const imagePickerMethod = ExponentImagePicker.getMediaLibraryPermissionsAsync;\n return imagePickerMethod(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](#imagepickercamerapermissionresponse).\n */\nexport async function requestCameraPermissionsAsync(): Promise<CameraPermissionResponse> {\n return ExponentImagePicker.requestCameraPermissionsAsync();\n}\n\n/**\n * @deprecated Use `requestMediaLibraryPermissionsAsync()` instead.\n */\nexport async function requestCameraRollPermissionsAsync(): Promise<MediaLibraryPermissionResponse> {\n console.warn(\n 'ImagePicker.requestCameraRollPermissionsAsync() is deprecated in favour of ImagePicker.requestMediaLibraryPermissionsAsync()'\n );\n return requestMediaLibraryPermissionsAsync();\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](#imagepickercamerarollpermissionresponse).\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 bloc\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 If the user cancelled the action, the method returns `{ cancelled: true }`. Otherwise,\n * this method returns information about the selected media item. When the chosen item is an image,\n * this method returns `{ cancelled: false, type: 'image', uri, width, height, exif, base64 }`;\n * when the item is a video, this method returns `{ cancelled: false, type: 'video', uri, width, height, duration }`.\n */\nexport async function launchCameraAsync(\n options: ImagePickerOptions = {}\n): Promise<ImagePickerResult> {\n if (!ExponentImagePicker.launchCameraAsync) {\n throw new UnavailabilityError('ImagePicker', 'launchCameraAsync');\n }\n return await ExponentImagePicker.launchCameraAsync(validateOptions(options));\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 If the user cancelled the action, the method returns `{ cancelled: true }`. Otherwise,\n * this method returns information about the selected media item. When the chosen item is an image,\n * this method returns `{ cancelled: false, type: 'image', uri, width, height, exif, base64 }`;\n * when the item is a video, this method returns `{ cancelled: false, type: 'video', uri, width, height, duration }`.\n */\nexport async function launchImageLibraryAsync<T extends ImagePickerOptions>(\n options?: T\n): Promise<ExpandImagePickerResult<T>> {\n if (!ExponentImagePicker.launchImageLibraryAsync) {\n throw new UnavailabilityError('ImagePicker', 'launchImageLibraryAsync');\n }\n return await ExponentImagePicker.launchImageLibraryAsync(options ?? {});\n}\n\nexport {\n MediaTypeOptions,\n ImagePickerOptions,\n ImagePickerResult,\n ImagePickerErrorResult,\n VideoExportPreset,\n CameraPermissionResponse,\n CameraRollPermissionResponse,\n MediaLibraryPermissionResponse,\n PermissionStatus,\n PermissionExpiration,\n PermissionHookOptions,\n ImageInfo,\n ImagePickerMultipleResult,\n ImagePickerCancelledResult,\n OpenFileBrowserOptions,\n ExpandImagePickerResult,\n UIImagePickerControllerQualityType,\n UIImagePickerPresentationStyle,\n};\n"]}
|