Skip to content

Commit

Permalink
Merge pull request #27834 from rmm-fl/i-26768-alt
Browse files Browse the repository at this point in the history
Update picker to avoid showing svg images on android
  • Loading branch information
Julesssss authored Sep 21, 2023
2 parents 37614ec + fd7c592 commit 89141ac
Showing 1 changed file with 133 additions and 0 deletions.
133 changes: 133 additions & 0 deletions patches/react-native-image-picker+5.1.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
diff --git a/node_modules/react-native-image-picker/android/src/main/java/com/imagepicker/ImagePickerModuleImpl.java b/node_modules/react-native-image-picker/android/src/main/java/com/imagepicker/ImagePickerModuleImpl.java
index 89b69a8..d86ab1e 100644
--- a/node_modules/react-native-image-picker/android/src/main/java/com/imagepicker/ImagePickerModuleImpl.java
+++ b/node_modules/react-native-image-picker/android/src/main/java/com/imagepicker/ImagePickerModuleImpl.java
@@ -29,6 +29,120 @@ public class ImagePickerModuleImpl implements ActivityEventListener {
public static final int REQUEST_LAUNCH_VIDEO_CAPTURE = 13002;
public static final int REQUEST_LAUNCH_LIBRARY = 13003;

+ // Prevent svg images from being selected as they are not supported (Image component does not support them)
+ // and also because iOS does not allow them to be selected (for consistency).
+ // Since, we can't exclude a mime type, we instead allow all image mime types except 'image/svg+xml'.
+ // Image mime types are generated by merging the Android image mime type support and the IANA media-types lists.
+ // https://android.googlesource.com/platform/external/mime-support/+/main/mime.types#636
+ // https://www.iana.org/assignments/media-types/media-types.xhtml#image
+ private static final String[] ALLOWED_IMAGE_MIME_TYPES = {
+ "image/aces",
+ "image/apng",
+ "image/avci",
+ "image/avcs",
+ "image/avif",
+ "image/bmp",
+ "image/cgm",
+ "image/dicom-rle",
+ "image/dpx",
+ "image/emf",
+ "image/example",
+ "image/fits",
+ "image/g3fax",
+ "image/gif",
+ "image/heic-sequence",
+ "image/heic",
+ "image/heif-sequence",
+ "image/heif",
+ "image/hej2k",
+ "image/hsj2",
+ "image/ief",
+ "image/j2c",
+ "image/jls",
+ "image/jp2",
+ "image/jpeg",
+ "image/jph",
+ "image/jphc",
+ "image/jpm",
+ "image/jpx",
+ "image/jxr",
+ "image/jxrA",
+ "image/jxrS",
+ "image/jxs",
+ "image/jxsc",
+ "image/jxsi",
+ "image/jxss",
+ "image/ktx",
+ "image/ktx2",
+ "image/naplps",
+ "image/pcx",
+ "image/png",
+ "image/prs.btif",
+ "image/prs.pti",
+ "image/pwg-raster",
+ // "image/svg+xml",
+ "image/t38",
+ "image/tiff-fx",
+ "image/tiff",
+ "image/vnd.adobe.photoshop",
+ "image/vnd.airzip.accelerator.azv",
+ "image/vnd.cns.inf2",
+ "image/vnd.dece.graphic",
+ "image/vnd.djvu",
+ "image/vnd.dvb.subtitle",
+ "image/vnd.dwg",
+ "image/vnd.dxf",
+ "image/vnd.fastbidsheet",
+ "image/vnd.fpx",
+ "image/vnd.fst",
+ "image/vnd.fujixerox.edmics-mmr",
+ "image/vnd.fujixerox.edmics-rlc",
+ "image/vnd.globalgraphics.pgb",
+ "image/vnd.microsoft.icon",
+ "image/vnd.mix",
+ "image/vnd.mozilla.apng",
+ "image/vnd.ms-modi",
+ "image/vnd.net-fpx",
+ "image/vnd.pco.b16",
+ "image/vnd.radiance",
+ "image/vnd.sealed.png",
+ "image/vnd.sealedmedia.softseal.gif",
+ "image/vnd.sealedmedia.softseal.jpg",
+ "image/vnd.svf",
+ "image/vnd.tencent.tap",
+ "image/vnd.valve.source.texture",
+ "image/vnd.wap.wbmp",
+ "image/vnd.xiff",
+ "image/vnd.zbrush.pcx",
+ "image/webp",
+ "image/wmf",
+ "image/x-canon-cr2",
+ "image/x-canon-crw",
+ "image/x-cmu-raster",
+ "image/x-coreldraw",
+ "image/x-coreldrawpattern",
+ "image/x-coreldrawtemplate",
+ "image/x-corelphotopaint",
+ "image/x-emf",
+ "image/x-epson-erf",
+ "image/x-icon",
+ "image/x-jg",
+ "image/x-jng",
+ "image/x-ms-bmp",
+ "image/x-nikon-nef",
+ "image/x-olympus-orf",
+ "image/x-photoshop",
+ "image/x-portable-anymap",
+ "image/x-portable-bitmap",
+ "image/x-portable-graymap",
+ "image/x-portable-pixmap",
+ "image/x-rgb",
+ "image/x-wmf",
+ "image/x-xbitmap",
+ "image/x-xpixmap",
+ "image/x-xwindowdump",
+ };
+
private Uri fileUri;

private ReactApplicationContext reactContext;
@@ -148,6 +262,7 @@ public class ImagePickerModuleImpl implements ActivityEventListener {

if (isPhoto) {
libraryIntent.setType("image/*");
+ libraryIntent.putExtra(Intent.EXTRA_MIME_TYPES, this.ALLOWED_IMAGE_MIME_TYPES);
} else if (isVideo) {
libraryIntent.setType("video/*");
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {

0 comments on commit 89141ac

Please sign in to comment.