expo-image-picker 13.3.0 → 14.0.0

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 CHANGED
@@ -10,6 +10,31 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 14.0.0 — 2022-10-25
14
+
15
+ ### 🛠 Breaking changes
16
+
17
+ - Remove deprecated `requestCameraRollPermissionsAsync` and `getCameraRollPermissionsAsync` methods, as well as associated to them `CameraRollPermissionResponse` type. ([#18600](https://github.com/expo/expo/pull/18600) by [@Simek](https://github.com/Simek))
18
+ - Bumped iOS deployment target to 13.0 and deprecated support for iOS 12. ([#18873](https://github.com/expo/expo/pull/18873) by [@tsapeta](https://github.com/tsapeta))
19
+ - Reworked the picking result object for simplicity and better compatibility with the multiple selection. ([#19570](https://github.com/expo/expo/pull/19570) by [@tsapeta](https://github.com/tsapeta))
20
+
21
+ ### 🎉 New features
22
+
23
+ - The new `PHPickerViewController` is now default picker interface on iOS 14+. ([#18871](https://github.com/expo/expo/pull/18871) by [@barthap](https://github.com/barthap))
24
+
25
+ ### 🐛 Bug fixes
26
+
27
+ - Fix images taken with `launchCameraAsync` being translated incorrectly on some camera orientations. ([#19185](https://github.com/expo/expo/pull/19185) by [@jacobjaffe](https://github.com/JacobJaffe) and [@reececox](https://github.com/reececox))
28
+ - Fix error where `launchImageLibraryAsync()` saved the photo to a global cache directory that was inaccessible in Expo Go. ([#19205](https://github.com/expo/expo/pull/19205) by [@aleqsio](https://github.com/aleqsio))
29
+
30
+ ### 💡 Others
31
+
32
+ - Drop `@expo/config-plugins` dependency in favor of peer dependency on `expo`. ([#18595](https://github.com/expo/expo/pull/18595) by [@EvanBacon](https://github.com/EvanBacon))
33
+
34
+ ## 13.3.1 — 2022-07-25
35
+
36
+ _This version does not introduce any user-facing changes._
37
+
13
38
  ## 13.3.0 — 2022-07-16
14
39
 
15
40
  ### 🎉 New features
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven-publish'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '13.3.0'
6
+ version = '14.0.0'
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 "13.3.0"
77
+ versionName "14.0.0"
78
78
  }
79
79
  lintOptions {
80
80
  abortOnError false
@@ -4,8 +4,8 @@ import android.Manifest
4
4
  import android.content.Context
5
5
  import android.content.Intent
6
6
  import android.net.Uri
7
- import expo.modules.core.errors.ModuleNotFoundException
8
7
  import android.os.OperationCanceledException
8
+ import expo.modules.core.errors.ModuleNotFoundException
9
9
  import expo.modules.imagepicker.contracts.CameraContract
10
10
  import expo.modules.imagepicker.contracts.CameraContractOptions
11
11
  import expo.modules.imagepicker.contracts.CropImageContract
@@ -21,9 +21,9 @@ import expo.modules.kotlin.functions.Coroutine
21
21
  import expo.modules.kotlin.modules.Module
22
22
  import expo.modules.kotlin.modules.ModuleDefinition
23
23
  import kotlinx.coroutines.Dispatchers
24
- import kotlinx.coroutines.launch
25
24
  import kotlinx.coroutines.suspendCancellableCoroutine
26
25
  import kotlinx.coroutines.withContext
26
+ import java.io.File
27
27
  import kotlin.coroutines.resume
28
28
  import kotlin.coroutines.resumeWithException
29
29
 
@@ -58,7 +58,7 @@ class ImagePickerModule : Module() {
58
58
  ensureTargetActivityIsAvailable(options)
59
59
  ensureCameraPermissionsAreGranted()
60
60
 
61
- val mediaFile = createOutputFile(context.cacheDir, options.mediaTypes.toFileExtension())
61
+ val mediaFile = createOutputFile(cacheDirectory, options.mediaTypes.toFileExtension())
62
62
  val uri = mediaFile.toContentUri(context)
63
63
  val contractOptions = options.toCameraContractOptions(uri)
64
64
 
@@ -80,20 +80,18 @@ class ImagePickerModule : Module() {
80
80
 
81
81
  // endregion
82
82
 
83
- OnCreate {
84
- coroutineScope.launch {
85
- withContext(Dispatchers.Main) {
86
- cameraLauncher = appContext.registerForActivityResult(
87
- CameraContract(this@ImagePickerModule),
88
- ) { input, result -> handleResultUponActivityDestruction(result, input.options) }
89
- imageLibraryLauncher = appContext.registerForActivityResult(
90
- ImageLibraryContract(this@ImagePickerModule),
91
- ) { input, result -> handleResultUponActivityDestruction(result, input.options) }
92
- cropImageLauncher = appContext.registerForActivityResult(
93
- CropImageContract(this@ImagePickerModule),
94
- ) { input, result -> handleResultUponActivityDestruction(result, input.options) }
95
- }
96
- }
83
+ RegisterActivityContracts {
84
+ cameraLauncher = registerForActivityResult(
85
+ CameraContract(this@ImagePickerModule),
86
+ ) { input, result -> handleResultUponActivityDestruction(result, input.options) }
87
+
88
+ imageLibraryLauncher = registerForActivityResult(
89
+ ImageLibraryContract(this@ImagePickerModule),
90
+ ) { input, result -> handleResultUponActivityDestruction(result, input.options) }
91
+
92
+ cropImageLauncher = registerForActivityResult(
93
+ CropImageContract(this@ImagePickerModule),
94
+ ) { input, result -> handleResultUponActivityDestruction(result, input.options) }
97
95
  }
98
96
  }
99
97
 
@@ -110,6 +108,9 @@ class ImagePickerModule : Module() {
110
108
  private lateinit var imageLibraryLauncher: AppContextActivityResultLauncher<ImageLibraryContractOptions, ImagePickerContractResult>
111
109
  private lateinit var cropImageLauncher: AppContextActivityResultLauncher<CropImageContractOptions, ImagePickerContractResult>
112
110
 
111
+ private val cacheDirectory: File
112
+ get() = appContext.cacheDirectory ?: throw ModuleNotFoundException("expo.modules.interfaces.filesystem.AppDirectories")
113
+
113
114
  /**
114
115
  * Stores result for an operation that has been interrupted by the activity destruction.
115
116
  * The results are stored only for successful, non-cancelled-by-user scenario.
@@ -139,7 +140,7 @@ class ImagePickerModule : Module() {
139
140
  }
140
141
  mediaHandler.readExtras(result.data, options)
141
142
  } catch (cause: OperationCanceledException) {
142
- ImagePickerCancelledResponse()
143
+ return ImagePickerResponse(canceled = true)
143
144
  }
144
145
  }
145
146
 
@@ -9,6 +9,7 @@ import expo.modules.imagepicker.contracts.CameraContractOptions
9
9
  import expo.modules.imagepicker.contracts.ImageLibraryContractOptions
10
10
  import expo.modules.kotlin.records.Field
11
11
  import expo.modules.kotlin.records.Record
12
+ import expo.modules.kotlin.types.Enumerable
12
13
 
13
14
  internal class ImagePickerOptions : Record, Serializable {
14
15
  @Field
@@ -41,7 +42,7 @@ internal class ImagePickerOptions : Record, Serializable {
41
42
  fun toImageLibraryContractOptions() = ImageLibraryContractOptions(this)
42
43
  }
43
44
 
44
- internal enum class MediaTypes(val value: String) {
45
+ internal enum class MediaTypes(val value: String) : Enumerable {
45
46
  IMAGES("Images"),
46
47
  VIDEOS("Videos"),
47
48
  ALL("All");
@@ -3,51 +3,26 @@ package expo.modules.imagepicker
3
3
  import android.os.Bundle
4
4
  import expo.modules.kotlin.records.Field
5
5
  import expo.modules.kotlin.records.Record
6
-
7
- internal class ImagePickerCancelledResponse : Record {
8
- @Field
9
- val cancelled: Boolean = true
10
- }
11
-
12
- internal sealed class ImagePickerResponse : Record {
13
- @Field
14
- val cancelled: Boolean = false
15
-
16
- sealed class Single(
17
- @Field val type: MediaType,
18
- @Field val uri: String,
19
- @Field val width: Int,
20
- @Field val height: Int,
21
- @Field val assetId: String?,
22
- ) : ImagePickerResponse() {
23
- class Image(
24
- uri: String,
25
- width: Int,
26
- height: Int,
27
- assetId: String?,
28
-
29
- @Field val base64: String?,
30
- @Field val exif: Bundle?
31
- ) : Single(MediaType.IMAGE, uri, width, height, assetId)
32
-
33
- class Video(
34
- uri: String,
35
- width: Int,
36
- height: Int,
37
- assetId: String?,
38
-
39
- @Field val duration: Int,
40
- @Field val rotation: Int
41
- ) : Single(MediaType.VIDEO, uri, width, height, assetId)
42
- }
43
-
44
- class Multiple(
45
- @Field
46
- val selected: List<Single>
47
- ) : ImagePickerResponse()
48
- }
49
-
50
- enum class MediaType(val value: String) {
6
+ import expo.modules.kotlin.types.Enumerable
7
+
8
+ internal class ImagePickerAsset(
9
+ @Field val assetId: String? = null,
10
+ @Field val type: MediaType = MediaType.IMAGE,
11
+ @Field val uri: String = "",
12
+ @Field val width: Int = 0,
13
+ @Field val height: Int = 0,
14
+ @Field val base64: String? = null,
15
+ @Field val exif: Bundle? = null,
16
+ @Field val duration: Int? = null,
17
+ @Field val rotation: Int? = null
18
+ ) : Record
19
+
20
+ internal class ImagePickerResponse(
21
+ @Field val canceled: Boolean = false,
22
+ @Field val assets: List<ImagePickerAsset>? = null
23
+ ) : Record
24
+
25
+ enum class MediaType(val value: String) : Enumerable {
51
26
  VIDEO("video"),
52
27
  IMAGE("image"),
53
28
  }
@@ -9,6 +9,7 @@ import expo.modules.imagepicker.exporters.CompressionImageExporter
9
9
  import expo.modules.imagepicker.exporters.ImageExporter
10
10
  import expo.modules.imagepicker.exporters.RawImageExporter
11
11
  import expo.modules.kotlin.providers.AppContextProvider
12
+ import java.io.File
12
13
 
13
14
  internal class MediaHandler(
14
15
  private val appContextProvider: AppContextProvider,
@@ -27,24 +28,25 @@ internal class MediaHandler(
27
28
  }
28
29
  }
29
30
 
30
- return if (results.size == 1) {
31
- results[0]
32
- } else {
33
- ImagePickerResponse.Multiple(results)
34
- }
31
+ return ImagePickerResponse(
32
+ canceled = false,
33
+ assets = results
34
+ )
35
35
  }
36
36
 
37
+ private val cacheDirectory: File
38
+ get() = appContextProvider.appContext.cacheDirectory
39
+
37
40
  private suspend fun handleImage(
38
41
  sourceUri: Uri,
39
42
  options: ImagePickerOptions,
40
- ): ImagePickerResponse.Single.Image {
43
+ ): ImagePickerAsset {
41
44
  val exporter: ImageExporter = if (options.quality == ImagePickerConstants.MAXIMUM_QUALITY) {
42
45
  RawImageExporter()
43
46
  } else {
44
47
  CompressionImageExporter(appContextProvider, options.quality)
45
48
  }
46
-
47
- val outputFile = createOutputFile(context.cacheDir, getType(context.contentResolver, sourceUri).toImageFileExtension())
49
+ val outputFile = createOutputFile(cacheDirectory, getType(context.contentResolver, sourceUri).toImageFileExtension())
48
50
 
49
51
  val exportedImage = exporter.exportAsync(sourceUri, outputFile, context.contentResolver)
50
52
  val base64 = options.base64.takeIf { it }
@@ -53,20 +55,21 @@ internal class MediaHandler(
53
55
  val exif = options.exif.takeIf { it }
54
56
  ?.let { exportedImage.exif(context.contentResolver) }
55
57
 
56
- return ImagePickerResponse.Single.Image(
58
+ return ImagePickerAsset(
59
+ type = MediaType.IMAGE,
57
60
  uri = Uri.fromFile(outputFile).toString(),
58
61
  width = exportedImage.width,
59
62
  height = exportedImage.height,
60
63
  base64 = base64,
61
64
  exif = exif,
62
- assetId = sourceUri.getMediaStoreAssetId()
65
+ assetId = sourceUri.getMediaStoreAssetId(),
63
66
  )
64
67
  }
65
68
 
66
69
  private suspend fun handleVideo(
67
70
  sourceUri: Uri,
68
- ): ImagePickerResponse.Single.Video {
69
- val outputFile = createOutputFile(context.cacheDir, ".mp4")
71
+ ): ImagePickerAsset {
72
+ val outputFile = createOutputFile(cacheDirectory, ".mp4")
70
73
  copyFile(sourceUri, outputFile, context.contentResolver)
71
74
  val outputUri = outputFile.toUri()
72
75
 
@@ -75,7 +78,8 @@ internal class MediaHandler(
75
78
  setDataSource(context, outputUri)
76
79
  }
77
80
 
78
- ImagePickerResponse.Single.Video(
81
+ return ImagePickerAsset(
82
+ type = MediaType.VIDEO,
79
83
  uri = outputUri.toString(),
80
84
  width = metadataRetriever.extractInt(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH),
81
85
  height = metadataRetriever.extractInt(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT),
@@ -27,7 +27,8 @@ internal class CropImageContract(
27
27
  override fun createIntent(context: Context, input: CropImageContractOptions) = Intent(context, CropImageActivity::class.java).apply {
28
28
  val mediaType = expo.modules.imagepicker.getType(context.contentResolver, input.sourceUri)
29
29
  val compressFormat = mediaType.toBitmapCompressFormat()
30
- val outputUri = createOutputFile(context.cacheDir, compressFormat.toImageFileExtension()).toUri()
30
+ val cacheDirectory = appContextProvider.appContext.cacheDirectory
31
+ val outputUri = createOutputFile(cacheDirectory, compressFormat.toImageFileExtension()).toUri()
31
32
 
32
33
  putExtra(
33
34
  CropImage.CROP_IMAGE_EXTRA_BUNDLE,
@@ -1,17 +1,17 @@
1
1
  import { PermissionResponse } from 'expo-modules-core';
2
- import { ImagePickerMultipleResult, ImagePickerResult, MediaTypeOptions } from './ImagePicker.types';
2
+ import { ImagePickerResult, MediaTypeOptions } from './ImagePicker.types';
3
3
  declare const _default: {
4
4
  readonly name: string;
5
5
  launchImageLibraryAsync({ mediaTypes, allowsMultipleSelection, base64, }: {
6
6
  mediaTypes?: MediaTypeOptions | undefined;
7
7
  allowsMultipleSelection?: boolean | undefined;
8
8
  base64?: boolean | undefined;
9
- }): Promise<ImagePickerResult | ImagePickerMultipleResult>;
9
+ }): Promise<ImagePickerResult>;
10
10
  launchCameraAsync({ mediaTypes, allowsMultipleSelection, base64, }: {
11
11
  mediaTypes?: MediaTypeOptions | undefined;
12
12
  allowsMultipleSelection?: boolean | undefined;
13
13
  base64?: boolean | undefined;
14
- }): Promise<ImagePickerResult | ImagePickerMultipleResult>;
14
+ }): Promise<ImagePickerResult>;
15
15
  getCameraPermissionsAsync(): Promise<PermissionResponse>;
16
16
  requestCameraPermissionsAsync(): Promise<PermissionResponse>;
17
17
  getMediaLibraryPermissionsAsync(_writeOnly: boolean): Promise<PermissionResponse>;
@@ -1 +1 @@
1
- {"version":3,"file":"ExponentImagePicker.web.d.ts","sourceRoot":"","sources":["../src/ExponentImagePicker.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA8B,MAAM,mBAAmB,CAAC;AAGnF,OAAO,EAGL,yBAAyB,EACzB,iBAAiB,EACjB,gBAAgB,EAEjB,MAAM,qBAAqB,CAAC;;;;;;;QAiBvB,QAAQ,iBAAiB,GAAG,yBAAyB,CAAC;;;;;QAgBtD,QAAQ,iBAAiB,GAAG,yBAAyB,CAAC;;;gDA2BR,OAAO;oDAGH,OAAO,GAAG,QAAQ,kBAAkB,CAAC;;AAvD7F,wBA0DE"}
1
+ {"version":3,"file":"ExponentImagePicker.web.d.ts","sourceRoot":"","sources":["../src/ExponentImagePicker.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA8B,MAAM,mBAAmB,CAAC;AAGnF,OAAO,EAEL,iBAAiB,EACjB,gBAAgB,EAEjB,MAAM,qBAAqB,CAAC;;;;;;;QAiBvB,QAAQ,iBAAiB,CAAC;;;;;QAgB1B,QAAQ,iBAAiB,CAAC;;;gDA2BoB,OAAO;oDAGH,OAAO,GAAG,QAAQ,kBAAkB,CAAC;;AAvD7F,wBA0DE"}
@@ -13,7 +13,7 @@ export default {
13
13
  async launchImageLibraryAsync({ mediaTypes = MediaTypeOptions.Images, allowsMultipleSelection = false, base64 = false, }) {
14
14
  // SSR guard
15
15
  if (!Platform.isDOMAvailable) {
16
- return { cancelled: true };
16
+ return { canceled: true, assets: null };
17
17
  }
18
18
  return await openFileBrowserAsync({
19
19
  mediaTypes,
@@ -24,7 +24,7 @@ export default {
24
24
  async launchCameraAsync({ mediaTypes = MediaTypeOptions.Images, allowsMultipleSelection = false, base64 = false, }) {
25
25
  // SSR guard
26
26
  if (!Platform.isDOMAvailable) {
27
- return { cancelled: true };
27
+ return { canceled: true, assets: null };
28
28
  }
29
29
  return await openFileBrowserAsync({
30
30
  mediaTypes,
@@ -75,22 +75,15 @@ function openFileBrowserAsync({ mediaTypes, capture = false, allowsMultipleSelec
75
75
  input.setAttribute('capture', 'camera');
76
76
  }
77
77
  document.body.appendChild(input);
78
- return new Promise((resolve, reject) => {
78
+ return new Promise((resolve) => {
79
79
  input.addEventListener('change', async () => {
80
80
  if (input.files) {
81
- if (!allowsMultipleSelection) {
82
- const img = await readFile(input.files[0], { base64 });
83
- resolve({
84
- ...img,
85
- });
86
- }
87
- else {
88
- const imgs = await Promise.all(Array.from(input.files).map((file) => readFile(file, { base64 })));
89
- resolve({
90
- cancelled: false,
91
- selected: imgs,
92
- });
93
- }
81
+ const files = allowsMultipleSelection ? input.files : [input.files[0]];
82
+ const assets = await Promise.all(Array.from(files).map((file) => readFile(file, { base64 })));
83
+ resolve({ canceled: false, assets });
84
+ }
85
+ else {
86
+ resolve({ canceled: true, assets: null });
94
87
  }
95
88
  document.body.removeChild(input);
96
89
  });
@@ -106,27 +99,23 @@ function readFile(targetFile, options) {
106
99
  };
107
100
  reader.onload = ({ target }) => {
108
101
  const uri = target.result;
109
- const returnRaw = () => resolve({
110
- uri,
111
- width: 0,
112
- height: 0,
113
- cancelled: false,
114
- });
102
+ const returnRaw = () => resolve({ uri, width: 0, height: 0 });
115
103
  if (typeof uri === 'string') {
116
104
  const image = new Image();
117
105
  image.src = uri;
118
- image.onload = () => resolve({
119
- uri,
120
- width: image.naturalWidth ?? image.width,
121
- height: image.naturalHeight ?? image.height,
122
- cancelled: false,
123
- // The blob's result cannot be directly decoded as Base64 without
124
- // first removing the Data-URL declaration preceding the
125
- // Base64-encoded data. To retrieve only the Base64 encoded string,
126
- // first remove data:*/*;base64, from the result.
127
- // https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL
128
- ...(options.base64 && { base64: uri.substr(uri.indexOf(',') + 1) }),
129
- });
106
+ image.onload = () => {
107
+ resolve({
108
+ uri,
109
+ width: image.naturalWidth ?? image.width,
110
+ height: image.naturalHeight ?? image.height,
111
+ // The blob's result cannot be directly decoded as Base64 without
112
+ // first removing the Data-URL declaration preceding the
113
+ // Base64-encoded data. To retrieve only the Base64 encoded string,
114
+ // first remove data:*/*;base64, from the result.
115
+ // https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL
116
+ ...(options.base64 && { base64: uri.substr(uri.indexOf(',') + 1) }),
117
+ });
118
+ };
130
119
  image.onerror = () => returnRaw();
131
120
  }
132
121
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"ExponentImagePicker.web.js","sourceRoot":"","sources":["../src/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Ac,CAAC,MAAM,CAAC;YACnC,MAAM,SAAS,GAAG,GAAG,EAAE,CACrB,OAAO,CAAC;gBACN,GAAG;gBACH,KAAK,EAAE,CAAC;gBACR,MAAM,EAAE,CAAC;gBACT,SAAS,EAAE,KAAK;aACjB,CAAC,CAAC;YAEL,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;gBAC3B,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;gBAC1B,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC;gBAChB,KAAK,CAAC,MAAM,GAAG,GAAG,EAAE,CAClB,OAAO,CAAC;oBACN,GAAG;oBACH,KAAK,EAAE,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,KAAK;oBACxC,MAAM,EAAE,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,MAAM;oBAC3C,SAAS,EAAE,KAAK;oBAChB,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"]}
1
+ {"version":3,"file":"ExponentImagePicker.web.js","sourceRoot":"","sources":["../src/ExponentImagePicker.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,gBAAgB,EAAE,QAAQ,EAAE,MAAM,mB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CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;YAE9D,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;gBAC3B,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;gBAC1B,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC;gBAChB,KAAK,CAAC,MAAM,GAAG,GAAG,EAAE;oBAClB,OAAO,CAAC;wBACN,GAAG;wBACH,KAAK,EAAE,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,KAAK;wBACxC,MAAM,EAAE,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,MAAM;wBAC3C,iEAAiE;wBACjE,wDAAwD;wBACxD,mEAAmE;wBACnE,iDAAiD;wBACjD,4EAA4E;wBAC5E,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;qBACpE,CAAC,CAAC;gBACL,CAAC,CAAC;gBACF,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 ImagePickerAsset,\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> {\n // SSR guard\n if (!Platform.isDOMAvailable) {\n return { canceled: true, assets: null };\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> {\n // SSR guard\n if (!Platform.isDOMAvailable) {\n return { canceled: true, assets: null };\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({\n mediaTypes,\n capture = false,\n allowsMultipleSelection = false,\n base64,\n}: OpenFileBrowserOptions): Promise<ImagePickerResult> {\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) => {\n input.addEventListener('change', async () => {\n if (input.files) {\n const files = allowsMultipleSelection ? input.files : [input.files[0]];\n const assets: ImagePickerAsset[] = await Promise.all(\n Array.from(files).map((file) => readFile(file, { base64 }))\n );\n\n resolve({ canceled: false, assets });\n } else {\n resolve({ canceled: true, assets: null });\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<ImagePickerAsset> {\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 = () => resolve({ uri, width: 0, height: 0 });\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 // 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 };\n image.onerror = () => returnRaw();\n } else {\n returnRaw();\n }\n };\n\n reader.readAsDataURL(targetFile);\n });\n}\n"]}
@@ -1,14 +1,10 @@
1
1
  import { PermissionStatus, PermissionExpiration, PermissionHookOptions, PermissionResponse } from 'expo-modules-core';
2
- import { CameraPermissionResponse, CameraRollPermissionResponse, MediaLibraryPermissionResponse, ImagePickerResult, ImagePickerErrorResult, MediaTypeOptions, ImagePickerOptions, VideoExportPreset, ExpandImagePickerResult, ImageInfo, ImagePickerMultipleResult, ImagePickerCancelledResult, OpenFileBrowserOptions, UIImagePickerControllerQualityType, UIImagePickerPresentationStyle } from './ImagePicker.types';
2
+ import { CameraPermissionResponse, MediaLibraryPermissionResponse, ImagePickerResult, ImagePickerAsset, ImagePickerErrorResult, MediaTypeOptions, ImagePickerOptions, VideoExportPreset, ExpandImagePickerResult, ImageInfo, ImagePickerMultipleResult, ImagePickerCancelledResult, OpenFileBrowserOptions, UIImagePickerControllerQualityType, UIImagePickerPresentationStyle } from './ImagePicker.types';
3
3
  /**
4
4
  * Checks user's permissions for accessing camera.
5
- * @return A promise that fulfills with an object of type [CameraPermissionResponse](#camerarollpermissionresponse).
5
+ * @return A promise that fulfills with an object of type [CameraPermissionResponse](#camerapermissionresponse).
6
6
  */
7
7
  export declare function getCameraPermissionsAsync(): Promise<CameraPermissionResponse>;
8
- /**
9
- * @deprecated Use `getMediaLibraryPermissionsAsync()` instead.
10
- */
11
- export declare function getCameraRollPermissionsAsync(): Promise<MediaLibraryPermissionResponse>;
12
8
  /**
13
9
  * Checks user's permissions for accessing photos.
14
10
  * @param writeOnly Whether to request write or read and write permissions. Defaults to `false`
@@ -21,10 +17,6 @@ export declare function getMediaLibraryPermissionsAsync(writeOnly?: boolean): Pr
21
17
  * @return A promise that fulfills with an object of type [CameraPermissionResponse](#camerarollpermissionresponse).
22
18
  */
23
19
  export declare function requestCameraPermissionsAsync(): Promise<CameraPermissionResponse>;
24
- /**
25
- * @deprecated Use `requestMediaLibraryPermissionsAsync()` instead.
26
- */
27
- export declare function requestCameraRollPermissionsAsync(): Promise<MediaLibraryPermissionResponse>;
28
20
  /**
29
21
  * Asks the user to grant permissions for accessing user's photo. This method does nothing on web.
30
22
  * @param writeOnly Whether to request write or read and write permissions. Defaults to `false`
@@ -76,15 +68,14 @@ export declare function getPendingResultAsync(): Promise<(ImagePickerResult | Im
76
68
  * intended. The `cancelled` event will not be returned in the browser due to platform restrictions
77
69
  * and inconsistencies across browsers.
78
70
  * @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 }`.
71
+ * @return A promise that resolves to an object with `canceled` and `assets` fields.
72
+ * When the user canceled the action the `assets` is always `null`, otherwise it's an array of
73
+ * the selected media assets which have a form of [`ImagePickerAsset`](#imagepickerasset).
83
74
  */
84
75
  export declare function launchCameraAsync(options?: ImagePickerOptions): Promise<ImagePickerResult>;
85
76
  /**
86
77
  * 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
78
+ * Requires `Permissions.MEDIA_LIBRARY` on iOS 10 only. On mobile web, this must be called
88
79
  * immediately in a user interaction like a button press, otherwise the browser will block the
89
80
  * request without a warning.
90
81
  * **Animated GIFs support** If the selected image is an animated GIF, the result image will be an
@@ -96,11 +87,14 @@ export declare function launchCameraAsync(options?: ImagePickerOptions): Promise
96
87
  * work as intended. The `cancelled` event will not be returned in the browser due to platform
97
88
  * restrictions and inconsistencies across browsers.
98
89
  * @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 }`.
90
+ * @return A promise that resolves to an object with `canceled` and `assets` fields.
91
+ * When the user canceled the action the `assets` is always `null`, otherwise it's an array of
92
+ * the selected media assets which have a form of [`ImagePickerAsset`](#imagepickerasset).
103
93
  */
104
- export declare function launchImageLibraryAsync<T extends ImagePickerOptions>(options?: T): Promise<ExpandImagePickerResult<T>>;
105
- export { MediaTypeOptions, ImagePickerOptions, ImagePickerResult, ImagePickerErrorResult, VideoExportPreset, CameraPermissionResponse, CameraRollPermissionResponse, MediaLibraryPermissionResponse, PermissionStatus, PermissionExpiration, PermissionHookOptions, PermissionResponse, ImageInfo, ImagePickerMultipleResult, ImagePickerCancelledResult, OpenFileBrowserOptions, ExpandImagePickerResult, UIImagePickerControllerQualityType, UIImagePickerPresentationStyle, };
94
+ export declare function launchImageLibraryAsync(options?: ImagePickerOptions): Promise<ImagePickerResult>;
95
+ export { MediaTypeOptions, ImagePickerOptions, ImagePickerResult, ImagePickerErrorResult, ImagePickerAsset, VideoExportPreset, CameraPermissionResponse, MediaLibraryPermissionResponse, PermissionStatus, PermissionExpiration, PermissionHookOptions, PermissionResponse, ImageInfo, // deprecated
96
+ ImagePickerMultipleResult, // deprecated
97
+ ImagePickerCancelledResult, // deprecated
98
+ OpenFileBrowserOptions, ExpandImagePickerResult, // deprecated
99
+ UIImagePickerControllerQualityType, UIImagePickerPresentationStyle, };
106
100
  //# sourceMappingURL=ImagePicker.d.ts.map
@@ -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,4BAA4B,EAC5B,8BAA8B,EAC9B,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,uBAAuB,EACvB,SAAS,EACT,yBAAyB,EACzB,0BAA0B,EAC1B,sBAAsB,EACtB,kCAAkC,EAClC,8BAA8B,EAC/B,MAAM,qBAAqB,CAAC;AAkC7B;;;GAGG;AACH,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,wBAAwB,CAAC,CAEnF;AAED;;GAEG;AACH,wBAAsB,6BAA6B,IAAI,OAAO,CAAC,8BAA8B,CAAC,CAK7F;AAGD;;;;GAIG;AACH,wBAAsB,+BAA+B,CACnD,SAAS,GAAE,OAAe,GACzB,OAAO,CAAC,8BAA8B,CAAC,CAEzC;AAGD;;;;GAIG;AACH,wBAAsB,6BAA6B,IAAI,OAAO,CAAC,wBAAwB,CAAC,CAEvF;AA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