fix for one file
This commit is contained in:
parent
b7a68d61ff
commit
a01559a10d
|
@ -70,7 +70,7 @@ const pickFromCamera = async (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const pickMultipleImageAndVideoFromLibrary = async (): Promise<ImagePickerFile[] | null> => {
|
export const pickMultipleImageAndVideoFromLibrary = async (): Promise<ImagePickerFile | ImagePickerFile[] | null> => {
|
||||||
try {
|
try {
|
||||||
const result = await ImagePicker.launchImageLibraryAsync({
|
const result = await ImagePicker.launchImageLibraryAsync({
|
||||||
mediaTypes: ImagePicker.MediaTypeOptions.All,
|
mediaTypes: ImagePicker.MediaTypeOptions.All,
|
||||||
|
@ -78,9 +78,14 @@ export const pickMultipleImageAndVideoFromLibrary = async (): Promise<ImagePicke
|
||||||
allowsMultipleSelection: true
|
allowsMultipleSelection: true
|
||||||
});
|
});
|
||||||
if (!result.cancelled) {
|
if (!result.cancelled) {
|
||||||
const selectedFiles = result.selected.map(file => addAdditionalPropsToFile(file));
|
if (result.selected) {
|
||||||
const files = await Promise.all(selectedFiles);
|
const selectedFiles = result.selected.map(file => addAdditionalPropsToFile(file));
|
||||||
return files;
|
const files = await Promise.all(selectedFiles);
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
// @ts-ignore - The type for when returning only one file is wrong.
|
||||||
|
const selectedFile = await addAdditionalPropsToFile(result);
|
||||||
|
return [selectedFile];
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -92,7 +97,9 @@ export const pickMultipleImageAndVideoFromLibrary = async (): Promise<ImagePicke
|
||||||
// Function Overload - https://www.typescriptlang.org/docs/handbook/2/functions.html#function-overloads
|
// Function Overload - https://www.typescriptlang.org/docs/handbook/2/functions.html#function-overloads
|
||||||
export async function pickImageFromLibrary(base64: true): Promise<(ImagePickerFile & { data: string }) | 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?: false): Promise<ImagePickerFile | null>;
|
||||||
export async function pickImageFromLibrary(base64?: boolean): Promise<ImagePickerFile | (ImagePickerFile & { data: string }) | 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,
|
||||||
|
|
Loading…
Reference in New Issue