mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at session-2.1 35 lines 891 B view raw
1import { 2 ImagePickerOptions, 3 launchImageLibraryAsync, 4 MediaTypeOptions, 5} from 'expo-image-picker' 6import {getDataUriSize} from './util' 7import * as Toast from 'view/com/util/Toast' 8 9export async function openPicker(opts?: ImagePickerOptions) { 10 const response = await launchImageLibraryAsync({ 11 exif: false, 12 mediaTypes: MediaTypeOptions.Images, 13 quality: 1, 14 ...opts, 15 }) 16 17 if (response.assets && response.assets.length > 4) { 18 Toast.show('You may only select up to 4 images') 19 } 20 21 return (response.assets ?? []) 22 .slice(0, 4) 23 .filter(asset => { 24 if (asset.mimeType?.startsWith('image/')) return true 25 Toast.show('Only image files are supported') 26 return false 27 }) 28 .map(image => ({ 29 mime: 'image/jpeg', 30 height: image.height, 31 width: image.width, 32 path: image.uri, 33 size: getDataUriSize(image.uri), 34 })) 35}