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: migrate to expo-image-picker #6143

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/containers/MessageComposer/hooks/useChooseMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useAppSelector } from '../../../lib/hooks';
import { useRoomContext } from '../../../views/RoomView/context';
import ImagePicker from '../../../lib/methods/helpers/ImagePicker/ImagePicker';
import { mapMediaResult } from '../../../lib/methods/helpers/ImagePicker/mapMediaResult';
import { getPermissions } from '../../../lib/methods/helpers/ImagePicker/getPermissions';
import { IShareAttachment } from '../../../definitions';

export const useChooseMedia = ({
Expand All @@ -30,6 +31,7 @@ export const useChooseMedia = ({

const takePhoto = async () => {
try {
await getPermissions('camera');
const result = await ImagePicker.launchCameraAsync(IMAGE_PICKER_CONFIG);
if (result.canceled) {
return;
Expand All @@ -53,6 +55,7 @@ export const useChooseMedia = ({

const takeVideo = async () => {
try {
await getPermissions('camera');
const result = await ImagePicker.launchCameraAsync(VIDEO_PICKER_CONFIG);
if (result.canceled) {
return;
Expand All @@ -76,6 +79,7 @@ export const useChooseMedia = ({

const chooseFromLibrary = async () => {
try {
await getPermissions('library');
const result = await ImagePicker.launchImageLibraryAsync(LIBRARY_PICKER_CONFIG);
if (result.canceled) {
return;
Expand Down
16 changes: 16 additions & 0 deletions app/lib/methods/helpers/ImagePicker/getPermissions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Linking } from 'react-native';

import ImagePicker from './ImagePicker';

export const getPermissions = async (type: 'camera' | 'library') => {
const method = type === 'camera' ? 'requestCameraPermissionsAsync' : 'requestMediaLibraryPermissionsAsync';
const requestResult = await ImagePicker[method]();
if (!requestResult.canAskAgain) {
Linking.openURL('app-settings:');
return Promise.reject();
}
if (!requestResult.granted) {
return Promise.reject();
}
return Promise.resolve();
};
5 changes: 3 additions & 2 deletions app/views/ChangeAvatarView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import AvatarSuggestion from './AvatarSuggestion';
import log from '../../lib/methods/helpers/log';
import { changeRoomsAvatar, changeUserAvatar, resetUserAvatar } from './submitServices';
import ImagePicker from '../../lib/methods/helpers/ImagePicker/ImagePicker';
import { getPermissions } from '../../lib/methods/helpers/ImagePicker/getPermissions';
import { mapMediaResult } from '../../lib/methods/helpers/ImagePicker/mapMediaResult';
import { isImageURL, useDebounce } from '../../lib/methods/helpers';
import { FormTextInput } from '../../containers/TextInput';
Expand Down Expand Up @@ -172,8 +173,8 @@ const ChangeAvatarView = () => {
exif: true,
base64: true
};
const response =
isCam === true ? await ImagePicker.launchCameraAsync(options) : await ImagePicker.launchImageLibraryAsync(options);
await getPermissions(isCam ? 'camera' : 'library');
Copy link
Contributor

Choose a reason for hiding this comment

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

Upload Image button is always opening the camera instead of library.
It is happening on both platforms.

WhatsApp.Video.2025-02-21.at.12.15.16.mp4

Tested on iPhone 13 and Xiaomi Mi A3

const response = isCam ? await ImagePicker.launchCameraAsync(options) : await ImagePicker.launchImageLibraryAsync(options);
if (response.canceled) {
return;
}
Expand Down