fix for gifs
This commit is contained in:
parent
a01559a10d
commit
553237caaf
|
@ -1,4 +1,3 @@
|
||||||
/* eslint-disable no-redeclare */
|
|
||||||
import * as FileSystem from 'expo-file-system';
|
import * as FileSystem from 'expo-file-system';
|
||||||
import * as ImagePicker from 'expo-image-picker';
|
import * as ImagePicker from 'expo-image-picker';
|
||||||
import { PermissionsAndroid } from 'react-native';
|
import { PermissionsAndroid } from 'react-native';
|
||||||
|
@ -74,7 +73,7 @@ export const pickMultipleImageAndVideoFromLibrary = async (): Promise<ImagePicke
|
||||||
try {
|
try {
|
||||||
const result = await ImagePicker.launchImageLibraryAsync({
|
const result = await ImagePicker.launchImageLibraryAsync({
|
||||||
mediaTypes: ImagePicker.MediaTypeOptions.All,
|
mediaTypes: ImagePicker.MediaTypeOptions.All,
|
||||||
quality: undefined, // to force animated gifs
|
quality: 1,
|
||||||
allowsMultipleSelection: true
|
allowsMultipleSelection: true
|
||||||
});
|
});
|
||||||
if (!result.cancelled) {
|
if (!result.cancelled) {
|
||||||
|
@ -94,19 +93,17 @@ export const pickMultipleImageAndVideoFromLibrary = async (): Promise<ImagePicke
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function Overload - https://www.typescriptlang.org/docs/handbook/2/functions.html#function-overloads
|
export async function pickImageFromLibrary({ animatedGif = true }: { animatedGif: boolean }): Promise<ImagePickerFile | null> {
|
||||||
export async function pickImageFromLibrary(base64: true): Promise<(ImagePickerFile & { data: string }) | null>;
|
|
||||||
export async function pickImageFromLibrary(base64?: false): Promise<ImagePickerFile | null>;
|
|
||||||
export async function pickImageFromLibrary(
|
|
||||||
base64?: boolean
|
|
||||||
): Promise<ImagePickerFile | (ImagePickerFile & { data: string }) | null> {
|
|
||||||
try {
|
try {
|
||||||
const image = await ImagePicker.launchImageLibraryAsync({
|
const image = await ImagePicker.launchImageLibraryAsync({
|
||||||
mediaTypes: ImagePicker.MediaTypeOptions.Images,
|
mediaTypes: ImagePicker.MediaTypeOptions.Images,
|
||||||
quality: undefined, // to force animated gifs
|
quality: animatedGif ? 1 : 0.9,
|
||||||
base64
|
base64: true
|
||||||
});
|
});
|
||||||
if (!image.cancelled) return addAdditionalPropsToFile(image);
|
if (!image.cancelled) {
|
||||||
|
const selectedImage = await addAdditionalPropsToFile(image);
|
||||||
|
return selectedImage;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log(error);
|
log(error);
|
||||||
|
|
|
@ -345,9 +345,9 @@ class ProfileView extends React.Component<IProfileViewProps, IProfileViewState>
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logEvent(events.PROFILE_PICK_AVATAR);
|
logEvent(events.PROFILE_PICK_AVATAR);
|
||||||
const response = await pickImageFromLibrary(true);
|
const response = await pickImageFromLibrary({ animatedGif: false });
|
||||||
if (response) {
|
if (response) {
|
||||||
this.setAvatar({ url: response.path, data: `data:image/jpeg;base64,${response.data}`, service: 'upload' });
|
this.setAvatar({ url: response.path, data: `data:image/jpeg;base64,${response.base64}`, service: 'upload' });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logEvent(events.PROFILE_PICK_AVATAR_F);
|
logEvent(events.PROFILE_PICK_AVATAR_F);
|
||||||
|
|
|
@ -489,9 +489,9 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
|
||||||
|
|
||||||
changeAvatar = async () => {
|
changeAvatar = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await pickImageFromLibrary(true);
|
const response = await pickImageFromLibrary({ animatedGif: false });
|
||||||
if (response) {
|
if (response) {
|
||||||
this.setState({ avatar: { url: response.path, data: `data:image/jpeg;base64,${response.data}`, service: 'upload' } });
|
this.setState({ avatar: { url: response.path, data: `data:image/jpeg;base64,${response.base64}`, service: 'upload' } });
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
|
Loading…
Reference in New Issue