2023-01-27 22:51:24 +01:00
|
|
|
/// <reference lib="dom" />
|
|
|
|
|
2023-04-18 00:41:44 +02:00
|
|
|
import {Image as RNImage} from 'react-native-image-crop-picker'
|
2024-04-27 14:21:13 +02:00
|
|
|
|
|
|
|
import {CameraOpts, CropperOptions} from './types'
|
2023-06-06 16:38:58 +02:00
|
|
|
export {openPicker} from './picker.shared'
|
2023-11-08 19:34:10 +01:00
|
|
|
import {unstable__openModal} from '#/state/modals'
|
2023-02-23 23:02:31 +01:00
|
|
|
|
2023-11-14 19:41:55 +01:00
|
|
|
export async function openCamera(_opts: CameraOpts): Promise<RNImage> {
|
2023-02-23 23:02:31 +01:00
|
|
|
// const mediaType = opts.mediaType || 'photo' TODO
|
|
|
|
throw new Error('TODO')
|
|
|
|
}
|
|
|
|
|
2023-11-14 19:41:55 +01:00
|
|
|
export async function openCropper(opts: CropperOptions): Promise<RNImage> {
|
2023-02-23 23:02:31 +01:00
|
|
|
// TODO handle more opts
|
2024-05-07 00:44:19 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2023-11-08 19:34:10 +01:00
|
|
|
unstable__openModal({
|
2023-02-24 00:22:03 +01:00
|
|
|
name: 'crop-image',
|
|
|
|
uri: opts.path,
|
2024-04-27 14:23:11 +02:00
|
|
|
dimensions:
|
|
|
|
opts.height && opts.width
|
|
|
|
? {width: opts.width, height: opts.height}
|
|
|
|
: undefined,
|
2023-04-18 00:41:44 +02:00
|
|
|
onSelect: (img?: RNImage) => {
|
2023-01-27 22:51:24 +01:00
|
|
|
if (img) {
|
|
|
|
resolve(img)
|
2024-05-07 00:44:19 +02:00
|
|
|
} else {
|
|
|
|
reject(new Error('Canceled'))
|
2023-01-27 22:51:24 +01:00
|
|
|
}
|
2023-02-24 00:22:03 +01:00
|
|
|
},
|
|
|
|
})
|
2023-01-27 22:51:24 +01:00
|
|
|
})
|
|
|
|
}
|