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