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

patch expo-image-picker to support "browse" on android #2384

Merged

Conversation

haileyok
Copy link
Contributor

@haileyok haileyok commented Dec 30, 2023

fixes #1617

Right now, expo-image-picker is using PickVisualMedia. This does not support the "Browse" option to select files elsewhere on the device except the gallery. Instead, we want to use GetContent. See https://android-developers.googleblog.com/2023/04/photo-picker-everywhere.html

This patches expo-image-picker to do so. Tested on SDK 34, 28, and 23 25. Tested accessing images from files as well as Google Drive with good success.

This is meant to be a temporary fix, and I didn't implement the logic for selecting videos. It's only a few extra lines, however we have to be careful that we properly create the intent (the mime can't be anything other than image/* or video/* otherwise it won't use the image picker).

We also have to use Intent.EXTRA_ALLOW_MULTIPLE which only accepts a boolean, not a limit. To that end, I've made a minor change in picker.shared.ts to slice the result and make sure we only return four images. Not the most ideal option, but I think the benefits of fixing this seemingly annoying issue outweigh that. To try and make it clear to the user, we present a toast if they select more than four images.

Of course whenever multiple is disabled we still only allow the selection of one file.

I think Google's intent is to make PickVisualMedia work in the future in the same way, so hopefully this isn't something that will need to be in the codebase for too long. They said by the end of the year though and...here we are 🙃

* @see [androidx.activity.result.contract.ActivityResultContracts.GetMultipleContents]
*/
internal class ImageLibraryContract(
- private val appContextProvider: AppContextProvider
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed code starts here

@haileyok
Copy link
Contributor Author

haileyok commented Dec 30, 2023

and 23

This was a lie. I tested in a sandbox on sdk 23 and it worked. I can't get the app to properly load on SDK 24 or 23. Seems to be an animation issue where the white background doesn't disappear?

see #2394. tested and it does work from 23 up.

@pfrazee
Copy link
Collaborator

pfrazee commented Jan 2, 2024

@haileyok going to review this asap but dropping in real quick to say if you're interested in a job, I definitely want to chat (paul@blueskyweb.xyz)

Copy link
Collaborator

@pfrazee pfrazee left a comment

Choose a reason for hiding this comment

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

I can't tell you how much I appreciate this one. It's been on the todo list for so long.

I'm cleaning up the patchfile with 95%ish confidence that I'm just removing build intermediates. If I get that wrong, we've got this PR to look at again in the future.

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.

Gallery access to all images in local files is dependent on Android version
2 participants