mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import ExpoImageCropTool, {type OpenCropperOptions} from 'expo-image-crop-tool'
2import {type ImagePickerOptions, launchCameraAsync} from 'expo-image-picker'
3
4export {openPicker, type PickerImage as RNImage} from './picker.shared'
5
6export async function openCamera(customOpts: ImagePickerOptions) {
7 const opts: ImagePickerOptions = {
8 mediaTypes: 'images',
9 ...customOpts,
10 }
11 const res = await launchCameraAsync(opts)
12
13 if (!res || !res.assets) {
14 throw new Error('Camera was closed before taking a photo')
15 }
16
17 const asset = res?.assets[0]
18
19 return {
20 path: asset.uri,
21 mime: asset.mimeType ?? 'image/jpeg',
22 size: asset.fileSize ?? 0,
23 width: asset.width,
24 height: asset.height,
25 }
26}
27
28export async function openCropper(opts: OpenCropperOptions) {
29 const item = await ExpoImageCropTool.openCropperAsync({
30 ...opts,
31 format: 'jpeg',
32 })
33
34 return {
35 path: item.path,
36 mime: item.mime,
37 size: item.size,
38 width: item.width,
39 height: item.height,
40 }
41}