mostly implement
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
import {
|
||||
Image as RNImage,
|
||||
openCropper as openCropperFn,
|
||||
} from 'react-native-image-crop-picker'
|
||||
import {
|
||||
documentDirectory,
|
||||
getInfoAsync,
|
||||
@@ -10,6 +6,8 @@ import {
|
||||
|
||||
import {compressIfNeeded} from './manip'
|
||||
import {CropperOptions} from './types'
|
||||
import {RNImage} from './picker.shared'
|
||||
import ExpoImageCropTool from 'expo-image-crop-tool'
|
||||
|
||||
async function getFile() {
|
||||
const imagesDir = documentDirectory!
|
||||
@@ -46,7 +44,7 @@ export async function openCamera(): Promise<RNImage> {
|
||||
}
|
||||
|
||||
export async function openCropper(opts: CropperOptions) {
|
||||
const item = await openCropperFn({
|
||||
const item = await ExpoImageCropTool.openCropperAsync({
|
||||
...opts,
|
||||
forceJpg: true, // ios only
|
||||
})
|
||||
|
||||
@@ -9,6 +9,14 @@ import {t} from '@lingui/macro'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
import {getDataUriSize} from './util'
|
||||
|
||||
export type RNImage = {
|
||||
mime: string
|
||||
height: number
|
||||
width: number
|
||||
path: string
|
||||
size: number
|
||||
}
|
||||
|
||||
export async function openPicker(opts?: ImagePickerOptions) {
|
||||
const response = await launchImageLibraryAsync({
|
||||
exif: false,
|
||||
|
||||
+23
-25
@@ -1,36 +1,34 @@
|
||||
import {
|
||||
Image as RNImage,
|
||||
openCamera as openCameraFn,
|
||||
openCropper as openCropperFn,
|
||||
} from 'react-native-image-crop-picker'
|
||||
import ExpoImageCropTool, {OpenCropperOptions} from 'expo-image-crop-tool'
|
||||
import {ImagePickerOptions, launchCameraAsync} from 'expo-image-picker'
|
||||
|
||||
import {CameraOpts, CropperOptions} from './types'
|
||||
export {openPicker} from './picker.shared'
|
||||
export {openPicker, type RNImage} from './picker.shared'
|
||||
|
||||
export async function openCamera(opts: CameraOpts): Promise<RNImage> {
|
||||
const item = await openCameraFn({
|
||||
width: opts.width,
|
||||
height: opts.height,
|
||||
freeStyleCropEnabled: opts.freeStyleCropEnabled,
|
||||
cropperCircleOverlay: opts.cropperCircleOverlay,
|
||||
cropping: false,
|
||||
forceJpg: true, // ios only
|
||||
compressImageQuality: 0.8,
|
||||
})
|
||||
export async function openCamera(customOpts: ImagePickerOptions) {
|
||||
const opts: ImagePickerOptions = {
|
||||
mediaTypes: 'images',
|
||||
...customOpts,
|
||||
}
|
||||
const res = await launchCameraAsync(opts)
|
||||
|
||||
if (!res || !res.assets) {
|
||||
throw new Error('Camera was closed before taking a photo')
|
||||
}
|
||||
|
||||
const asset = res?.assets[0]
|
||||
|
||||
return {
|
||||
path: item.path,
|
||||
mime: item.mime,
|
||||
size: item.size,
|
||||
width: item.width,
|
||||
height: item.height,
|
||||
path: asset.uri,
|
||||
mime: asset.mimeType ?? 'image/jpeg',
|
||||
size: asset.fileSize ?? 0,
|
||||
width: asset.width,
|
||||
height: asset.height,
|
||||
}
|
||||
}
|
||||
|
||||
export async function openCropper(opts: CropperOptions) {
|
||||
const item = await openCropperFn({
|
||||
export async function openCropper(opts: OpenCropperOptions) {
|
||||
const item = await ExpoImageCropTool.openCropperAsync({
|
||||
...opts,
|
||||
forceJpg: true, // ios only
|
||||
format: 'jpeg',
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/// <reference lib="dom" />
|
||||
|
||||
import {Image as RNImage} from 'react-native-image-crop-picker'
|
||||
|
||||
import {CameraOpts, CropperOptions} from './types'
|
||||
export {openPicker} from './picker.shared'
|
||||
import {unstable__openModal} from '#/state/modals'
|
||||
import {RNImage} from './picker.shared'
|
||||
|
||||
export {openPicker, type RNImage} from './picker.shared'
|
||||
|
||||
export async function openCamera(_opts: CameraOpts): Promise<RNImage> {
|
||||
// const mediaType = opts.mediaType || 'photo' TODO
|
||||
|
||||
Reference in New Issue
Block a user