prevent duplicate pickers from opening on android (#3240)
* prevent duplicate pickers from opening on android * revert unnecessary changes * test * one more testzio/stable
parent
5e0a6a12ff
commit
2255d21bda
|
@ -1,8 +1,56 @@
|
||||||
|
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
|
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..41aaf12 100644
|
index ff15c91..9763012 100644
|
||||||
--- a/node_modules/expo-image-picker/android/src/main/java/expo/modules/imagepicker/contracts/ImageLibraryContract.kt
|
--- 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
|
+++ b/node_modules/expo-image-picker/android/src/main/java/expo/modules/imagepicker/contracts/ImageLibraryContract.kt
|
||||||
@@ -26,51 +26,26 @@ import java.io.Serializable
|
@@ -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]
|
* @see [androidx.activity.result.contract.ActivityResultContracts.GetMultipleContents]
|
||||||
*/
|
*/
|
||||||
internal class ImageLibraryContract(
|
internal class ImageLibraryContract(
|
||||||
|
@ -12,7 +60,7 @@ index ff15c91..41aaf12 100644
|
||||||
private val contentResolver: ContentResolver
|
private val contentResolver: ContentResolver
|
||||||
get() = appContextProvider.appContext.reactContext?.contentResolver
|
get() = appContextProvider.appContext.reactContext?.contentResolver
|
||||||
?: throw Exceptions.ReactContextLost()
|
?: throw Exceptions.ReactContextLost()
|
||||||
|
|
||||||
override fun createIntent(context: Context, input: ImageLibraryContractOptions): Intent {
|
override fun createIntent(context: Context, input: ImageLibraryContractOptions): Intent {
|
||||||
- val request = PickVisualMediaRequest.Builder()
|
- val request = PickVisualMediaRequest.Builder()
|
||||||
- .setMediaType(
|
- .setMediaType(
|
||||||
|
@ -34,7 +82,7 @@ index ff15c91..41aaf12 100644
|
||||||
+ val intent = Intent(Intent.ACTION_GET_CONTENT)
|
+ val intent = Intent(Intent.ACTION_GET_CONTENT)
|
||||||
+ .addCategory(Intent.CATEGORY_OPENABLE)
|
+ .addCategory(Intent.CATEGORY_OPENABLE)
|
||||||
+ .setType("image/*")
|
+ .setType("image/*")
|
||||||
|
|
||||||
if (input.options.allowsMultipleSelection) {
|
if (input.options.allowsMultipleSelection) {
|
||||||
- val selectionLimit = input.options.selectionLimit
|
- val selectionLimit = input.options.selectionLimit
|
||||||
-
|
-
|
||||||
|
@ -45,7 +93,7 @@ index ff15c91..41aaf12 100644
|
||||||
+ if(input.options.selectionLimit == 1) {
|
+ if(input.options.selectionLimit == 1) {
|
||||||
+ return intent
|
+ return intent
|
||||||
}
|
}
|
||||||
|
|
||||||
- if (selectionLimit > 1) {
|
- if (selectionLimit > 1) {
|
||||||
- return PickMultipleVisualMedia(selectionLimit).createIntent(context, request)
|
- return PickMultipleVisualMedia(selectionLimit).createIntent(context, request)
|
||||||
- }
|
- }
|
||||||
|
@ -56,9 +104,9 @@ index ff15c91..41aaf12 100644
|
||||||
- }
|
- }
|
||||||
+ intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
|
+ intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
- return PickVisualMedia().createIntent(context, request)
|
- return PickVisualMedia().createIntent(context, request)
|
||||||
+ return intent
|
+ return intent
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun parseResult(input: ImageLibraryContractOptions, resultCode: Int, intent: Intent?) =
|
override fun parseResult(input: ImageLibraryContractOptions, resultCode: Int, intent: Intent?) =
|
||||||
|
|
Loading…
Reference in New Issue