Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): permit to specify a list of allowed mime-types #2145

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

renchap
Copy link
Contributor

@renchap renchap commented Jun 16, 2023

Motivation (required)

The Android camera app has an option to store both JPEG and RAW (DNG format) files for each picture. When this option is enabled, both versions of the image are shown to the user (but without any indication of the file format, so the users sees every image twice).

This new options allows you to restrict the allowed MIME types, for example restrictMimeTypes: ['image/jpeg', 'image/heic', 'image/png'].

On Android 13 (new Photo Picker), only the matching files are displayed, no more duplicates.

On older Android versions, every file is still displayed in the file explorer, but non-matching files are grayed and can not be selected.

This option can not be implemented on iOS, as the API only allows you to filter on predefined types (images, videos, slow-mos…).

Test Plan (required)

I used restrictMimeTypes: ['image/jpeg', 'image/heic', 'image/png'] with the example app and tested the behaviour with and without the option on an Android 10 and Android 13 devices.

@@ -125,35 +125,42 @@ public void launchImageLibrary(final ReadableMap options, final Callback callbac
boolean isPhoto = this.options.mediaType.equals(mediaTypePhoto);
boolean isVideo = this.options.mediaType.equals(mediaTypeVideo);

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
boolean usePhotoPicker = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this check into a variable as it was used multiple times

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
boolean usePhotoPicker = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU;

if (usePhotoPicker) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Order of the statements has been inversed to avoid a negation in the if statement

src/platforms/native.ts Outdated Show resolved Hide resolved
@renchap
Copy link
Contributor Author

renchap commented Sep 8, 2023

@Johan-dutoit Could you have a look at this PR?

It has been running in our production app for 2 months without issues.

@Julesssss
Copy link

@Johan-dutoit Could you have a look at this PR?
It has been running in our production app for 2 months without issues.

Bumping this comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants