ensure no more than four assets, show toast if more

zio/stable
Hailey 2023-12-29 22:00:52 -08:00
parent a4aefcc8f8
commit 54e6ed8ebc
1 changed files with 6 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import {
MediaTypeOptions,
} from 'expo-image-picker'
import {getDataUriSize} from './util'
import * as Toast from 'view/com/util/Toast'
export async function openPicker(opts?: ImagePickerOptions) {
const response = await launchImageLibraryAsync({
@ -13,7 +14,11 @@ export async function openPicker(opts?: ImagePickerOptions) {
...opts,
})
return (response.assets ?? []).map(image => ({
if (response.assets && response.assets.length > 4) {
Toast.show('You may only select up to 4 images')
}
return (response.assets ?? []).slice(0, 4).map(image => ({
mime: 'image/jpeg',
height: image.height,
width: image.width,