about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--patches/expo-image-picker+14.7.1.patch64
-rw-r--r--patches/expo-image-picker+14.7.1.patch.md3
-rw-r--r--src/lib/media/picker.shared.ts7
3 files changed, 73 insertions, 1 deletions
diff --git a/patches/expo-image-picker+14.7.1.patch b/patches/expo-image-picker+14.7.1.patch
new file mode 100644
index 000000000..2d37a182a
--- /dev/null
+++ b/patches/expo-image-picker+14.7.1.patch
@@ -0,0 +1,64 @@
+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
+--- 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
+@@ -26,51 +26,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?) =
diff --git a/patches/expo-image-picker+14.7.1.patch.md b/patches/expo-image-picker+14.7.1.patch.md
new file mode 100644
index 000000000..47c0daed5
--- /dev/null
+++ b/patches/expo-image-picker+14.7.1.patch.md
@@ -0,0 +1,3 @@
+added by https://github.com/bluesky-social/social-app/pull/2384#pullrequestreview-1800985521
+
+hackfixes the image picker on android so that the user can select from their typical image sources
\ No newline at end of file
diff --git a/src/lib/media/picker.shared.ts b/src/lib/media/picker.shared.ts
index 00b09c6b8..8bade34e2 100644
--- a/src/lib/media/picker.shared.ts
+++ b/src/lib/media/picker.shared.ts
@@ -4,6 +4,7 @@ import {
   MediaTypeOptions,
 } from 'expo-image-picker'
 import {getDataUriSize} from './util'
+import * as Toast from 'view/com/util/Toast'
 
 export async function openPicker(opts?: ImagePickerOptions) {
   const response = await launchImageLibraryAsync({
@@ -13,7 +14,11 @@ export async function openPicker(opts?: ImagePickerOptions) {
     ...opts,
   })
 
-  return (response.assets ?? []).map(image => ({
+  if (response.assets && response.assets.length > 4) {
+    Toast.show('You may only select up to 4 images')
+  }
+
+  return (response.assets ?? []).slice(0, 4).map(image => ({
     mime: 'image/jpeg',
     height: image.height,
     width: image.width,