about summary refs log tree commit diff
path: root/patches/expo-image-picker+14.7.1.patch
blob: 046eb4f4f32bfd9c76c639247436f2f560cc5d5f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
diff --git a/node_modules/expo-image-picker/android/src/main/java/expo/modules/imagepicker/ImagePickerModule.kt b/node_modules/expo-image-picker/android/src/main/java/expo/modules/imagepicker/ImagePickerModule.kt
index 3f50f8c..ee47fa1 100644
--- a/node_modules/expo-image-picker/android/src/main/java/expo/modules/imagepicker/ImagePickerModule.kt
+++ b/node_modules/expo-image-picker/android/src/main/java/expo/modules/imagepicker/ImagePickerModule.kt
@@ -33,7 +33,9 @@ import kotlin.coroutines.resumeWithException
 // TODO(@bbarthec): rename to ExpoImagePicker
 private const val moduleName = "ExponentImagePicker"

+
 class ImagePickerModule : Module() {
+  private var isPickerOpen = false

   override fun definition() = ModuleDefinition {
     Name(moduleName)
@@ -129,6 +131,11 @@ class ImagePickerModule : Module() {
     options: ImagePickerOptions
   ): Any {
     return try {
+      if(isPickerOpen) {
+        return ImagePickerResponse(canceled = true)
+      }
+
+      isPickerOpen = true
       var result = launchPicker(pickerLauncher)
       if (
         !options.allowsMultipleSelection &&
@@ -143,6 +150,8 @@ class ImagePickerModule : Module() {
       mediaHandler.readExtras(result.data, options)
     } catch (cause: OperationCanceledException) {
       return ImagePickerResponse(canceled = true)
+    } finally {
+      isPickerOpen = false
     }
   }

diff --git a/node_modules/expo-image-picker/android/src/main/java/expo/modules/imagepicker/contracts/ImageLibraryContract.kt b/node_modules/expo-image-picker/android/src/main/java/expo/modules/imagepicker/contracts/ImageLibraryContract.kt
index ff15c91..9763012 100644
--- a/node_modules/expo-image-picker/android/src/main/java/expo/modules/imagepicker/contracts/ImageLibraryContract.kt
+++ b/node_modules/expo-image-picker/android/src/main/java/expo/modules/imagepicker/contracts/ImageLibraryContract.kt
@@ -5,12 +5,7 @@ import android.content.ContentResolver
 import android.content.Context
 import android.content.Intent
 import android.net.Uri
-import androidx.activity.result.PickVisualMediaRequest
-import androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia
-import androidx.activity.result.contract.ActivityResultContracts.PickMultipleVisualMedia
 import expo.modules.imagepicker.ImagePickerOptions
-import expo.modules.imagepicker.MediaTypes
-import expo.modules.imagepicker.UNLIMITED_SELECTION
 import expo.modules.imagepicker.getAllDataUris
 import expo.modules.imagepicker.toMediaType
 import expo.modules.kotlin.activityresult.AppContextActivityResultContract
@@ -26,51 +21,26 @@ import java.io.Serializable
  * @see [androidx.activity.result.contract.ActivityResultContracts.GetMultipleContents]
  */
 internal class ImageLibraryContract(
-  private val appContextProvider: AppContextProvider
+  private val appContextProvider: AppContextProvider,
 ) : AppContextActivityResultContract<ImageLibraryContractOptions, ImagePickerContractResult> {
   private val contentResolver: ContentResolver
     get() = appContextProvider.appContext.reactContext?.contentResolver
       ?: throw Exceptions.ReactContextLost()

   override fun createIntent(context: Context, input: ImageLibraryContractOptions): Intent {
-    val request = PickVisualMediaRequest.Builder()
-      .setMediaType(
-        when (input.options.mediaTypes) {
-          MediaTypes.VIDEOS -> {
-            PickVisualMedia.VideoOnly
-          }
-
-          MediaTypes.IMAGES -> {
-            PickVisualMedia.ImageOnly
-          }
-
-          else -> {
-            PickVisualMedia.ImageAndVideo
-          }
-        }
-      )
-      .build()
+    val intent = Intent(Intent.ACTION_GET_CONTENT)
+            .addCategory(Intent.CATEGORY_OPENABLE)
+            .setType("image/*")

     if (input.options.allowsMultipleSelection) {
-      val selectionLimit = input.options.selectionLimit
-
-      if (selectionLimit == 1) {
-        // If multiple selection is allowed but the limit is 1, we should ignore
-        // the multiple selection flag and just treat it as a single selection.
-        return PickVisualMedia().createIntent(context, request)
+      if(input.options.selectionLimit == 1) {
+        return intent
       }

-      if (selectionLimit > 1) {
-        return PickMultipleVisualMedia(selectionLimit).createIntent(context, request)
-      }
-
-      // If the selection limit is 0, it is the same as unlimited selection.
-      if (selectionLimit == UNLIMITED_SELECTION) {
-        return PickMultipleVisualMedia().createIntent(context, request)
-      }
+      intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
     }

-    return PickVisualMedia().createIntent(context, request)
+    return intent
   }

   override fun parseResult(input: ImageLibraryContractOptions, resultCode: Int, intent: Intent?) =