type fixes

This commit is contained in:
Hailey
2025-05-05 08:54:08 -07:00
parent d36837dcf0
commit 29863ca89d
12 changed files with 58 additions and 64 deletions
+8 -6
View File
@@ -1,12 +1,11 @@
import {Image as RNImage} from 'react-native-image-crop-picker'
import {Dimensions} from './types'
import {type PickerImage} from './picker.shared'
import {type Dimensions} from './types'
import {blobToDataUri, getDataUriSize} from './util'
export async function compressIfNeeded(
img: RNImage,
img: PickerImage,
maxSize: number,
): Promise<RNImage> {
): Promise<PickerImage> {
if (img.size < maxSize) {
return img
}
@@ -69,7 +68,10 @@ interface DoResizeOpts {
maxSize: number
}
async function doResize(dataUri: string, opts: DoResizeOpts): Promise<RNImage> {
async function doResize(
dataUri: string,
opts: DoResizeOpts,
): Promise<PickerImage> {
let newDataUri
let minQualityPercentage = 0
+3 -4
View File
@@ -3,11 +3,10 @@ import {
getInfoAsync,
readDirectoryAsync,
} from 'expo-file-system'
import ExpoImageCropTool from 'expo-image-crop-tool'
import ExpoImageCropTool, {type OpenCropperOptions} from 'expo-image-crop-tool'
import {compressIfNeeded} from './manip'
import {type PickerImage} from './picker.shared'
import {type CropperOptions} from './types'
async function getFile() {
const imagesDir = documentDirectory!
@@ -43,10 +42,10 @@ export async function openCamera(): Promise<PickerImage> {
return await getFile()
}
export async function openCropper(opts: CropperOptions) {
export async function openCropper(opts: OpenCropperOptions) {
const item = await ExpoImageCropTool.openCropperAsync({
...opts,
forceJpg: true, // ios only
format: 'jpeg',
})
return {
+9 -9
View File
@@ -1,8 +1,10 @@
/// <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, type CropperOptions} from './types'
import {type CameraOpts} from './types'
export {openPicker, type PickerImage as RNImage} from './picker.shared'
@@ -11,18 +13,16 @@ export async function openCamera(_opts: CameraOpts): Promise<PickerImage> {
throw new Error('TODO')
}
export async function openCropper(opts: CropperOptions): Promise<PickerImage> {
export async function openCropper(
opts: OpenCropperOptions,
): Promise<PickerImage> {
// TODO handle more opts
return new Promise((resolve, reject) => {
unstable__openModal({
name: 'crop-image',
uri: opts.path,
dimensions:
opts.width && opts.height
? {width: opts.width, height: opts.height}
: undefined,
aspect: opts.webAspectRatio,
circular: opts.webCircularCrop,
uri: opts.imageUri,
aspect: opts.aspectRatio,
circular: opts.shape === 'circle',
onSelect: (img?: PickerImage) => {
if (img) {
resolve(img)
-7
View File
@@ -1,5 +1,3 @@
import {openCropper} from 'react-native-image-crop-picker'
export interface Dimensions {
width: number
height: number
@@ -17,8 +15,3 @@ export interface CameraOpts {
freeStyleCropEnabled?: boolean
cropperCircleOverlay?: boolean
}
export type CropperOptions = Parameters<typeof openCropper>[0] & {
webAspectRatio?: number
webCircularCrop?: boolean
}