From 521ec8e044e58633530e1864e7abc6e22554d7d3 Mon Sep 17 00:00:00 2001
From: hailey <me@haileyok.com>
Date: Tue, 6 May 2025 10:54:08 -0700
Subject: swap out cropper library (#8327)

* mostly implement

* type errors

* unused import

* rm comment

* stop accidentally deleting the image while compressing

* upgrade

* type fixes

* upgrade, remove timeout

* bump

* rm mock

* bump

---------

Co-authored-by: Samuel Newman <mozzius@protonmail.com>
---
 src/lib/media/picker.tsx | 48 +++++++++++++++++++++++-------------------------
 1 file changed, 23 insertions(+), 25 deletions(-)

(limited to 'src/lib/media/picker.tsx')

diff --git a/src/lib/media/picker.tsx b/src/lib/media/picker.tsx
index 37e01e67f..6095730d5 100644
--- a/src/lib/media/picker.tsx
+++ b/src/lib/media/picker.tsx
@@ -1,36 +1,34 @@
-import {
-  Image as RNImage,
-  openCamera as openCameraFn,
-  openCropper as openCropperFn,
-} from 'react-native-image-crop-picker'
+import ExpoImageCropTool, {type OpenCropperOptions} from 'expo-image-crop-tool'
+import {type ImagePickerOptions, launchCameraAsync} from 'expo-image-picker'
 
-import {CameraOpts, CropperOptions} from './types'
-export {openPicker} from './picker.shared'
+export {openPicker, type PickerImage as 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 {
-- 
cgit 1.4.1

