Merge branch 'main' into hailey/79fab
This commit is contained in:
@@ -24,7 +24,7 @@ import {type Dimensions} from './types'
|
||||
|
||||
export async function compressIfNeeded(
|
||||
img: PickerImage,
|
||||
maxSize: number = 1000000,
|
||||
maxSize: number = POST_IMG_MAX.size,
|
||||
): Promise<PickerImage> {
|
||||
if (img.size < maxSize) {
|
||||
return img
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/// <reference lib="dom" />
|
||||
|
||||
import {type PickerImage} from './picker.shared'
|
||||
import {type Dimensions} from './types'
|
||||
import {blobToDataUri, getDataUriSize} from './util'
|
||||
|
||||
@@ -1,25 +1,21 @@
|
||||
import {
|
||||
type ImagePickerOptions,
|
||||
launchImageLibraryAsync,
|
||||
MediaTypeOptions,
|
||||
} from 'expo-image-picker'
|
||||
import {t} from '@lingui/macro'
|
||||
|
||||
import {type ImageMeta} from '#/state/gallery'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
import {getDataUriSize} from './util'
|
||||
|
||||
export type PickerImage = {
|
||||
mime: string
|
||||
height: number
|
||||
width: number
|
||||
path: string
|
||||
export type PickerImage = ImageMeta & {
|
||||
size: number
|
||||
}
|
||||
|
||||
export async function openPicker(opts?: ImagePickerOptions) {
|
||||
const response = await launchImageLibraryAsync({
|
||||
exif: false,
|
||||
mediaTypes: MediaTypeOptions.Images,
|
||||
mediaTypes: ['images'],
|
||||
quality: 1,
|
||||
...opts,
|
||||
legacy: true,
|
||||
|
||||
@@ -1,35 +1,18 @@
|
||||
/// <reference lib="dom" />
|
||||
|
||||
import {type OpenCropperOptions} from 'expo-image-crop-tool'
|
||||
|
||||
import {unstable__openModal} from '#/state/modals'
|
||||
import {type PickerImage} from './picker.shared'
|
||||
import {type CameraOpts} from './types'
|
||||
|
||||
export {openPicker, type PickerImage as RNImage} from './picker.shared'
|
||||
export {openPicker} from './picker.shared'
|
||||
|
||||
export async function openCamera(_opts: CameraOpts): Promise<PickerImage> {
|
||||
// const mediaType = opts.mediaType || 'photo' TODO
|
||||
throw new Error('TODO')
|
||||
throw new Error('openCamera is not supported on web')
|
||||
}
|
||||
|
||||
export async function openCropper(
|
||||
opts: OpenCropperOptions,
|
||||
_opts: OpenCropperOptions,
|
||||
): Promise<PickerImage> {
|
||||
// TODO handle more opts
|
||||
return new Promise((resolve, reject) => {
|
||||
unstable__openModal({
|
||||
name: 'crop-image',
|
||||
uri: opts.imageUri,
|
||||
aspect: opts.aspectRatio,
|
||||
circular: opts.shape === 'circle',
|
||||
onSelect: (img?: PickerImage) => {
|
||||
if (img) {
|
||||
resolve(img)
|
||||
} else {
|
||||
reject(new Error('Canceled'))
|
||||
}
|
||||
},
|
||||
})
|
||||
})
|
||||
throw new Error(
|
||||
'openCropper is not supported on web. Use EditImageDialog instead.',
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user