type errors

This commit is contained in:
Hailey
2025-05-05 00:17:04 -07:00
parent 4f57363276
commit 664c079250
5 changed files with 24 additions and 21 deletions
+8 -5
View File
@@ -1,5 +1,4 @@
import {Image as RNImage, Share as RNShare} from 'react-native' import {Image as RNImage, Share as RNShare} from 'react-native'
import {Image} from 'react-native-image-crop-picker'
import uuid from 'react-native-uuid' import uuid from 'react-native-uuid'
import { import {
cacheDirectory, cacheDirectory,
@@ -20,12 +19,13 @@ import RNFetchBlob from 'rn-fetch-blob'
import {POST_IMG_MAX} from '#/lib/constants' import {POST_IMG_MAX} from '#/lib/constants'
import {logger} from '#/logger' import {logger} from '#/logger'
import {isAndroid, isIOS} from '#/platform/detection' import {isAndroid, isIOS} from '#/platform/detection'
import {Dimensions} from './types' import {type PickerImage} from './picker.shared'
import {type Dimensions} from './types'
export async function compressIfNeeded( export async function compressIfNeeded(
img: Image, img: PickerImage,
maxSize: number = 1000000, maxSize: number = 1000000,
): Promise<Image> { ): Promise<PickerImage> {
const origUri = `file://${img.path}` const origUri = `file://${img.path}`
if (img.size < maxSize) { if (img.size < maxSize) {
return img return img
@@ -166,7 +166,10 @@ interface DoResizeOpts {
maxSize: number maxSize: number
} }
async function doResize(localUri: string, opts: DoResizeOpts): Promise<Image> { async function doResize(
localUri: string,
opts: DoResizeOpts,
): Promise<PickerImage> {
// We need to get the dimensions of the image before we resize it. Previously, the library we used allowed us to enter // We need to get the dimensions of the image before we resize it. Previously, the library we used allowed us to enter
// a "max size", and it would do the "best possible size" calculation for us. // a "max size", and it would do the "best possible size" calculation for us.
// Now instead, we have to supply the final dimensions to the manipulation function instead. // Now instead, we have to supply the final dimensions to the manipulation function instead.
+5 -5
View File
@@ -3,11 +3,11 @@ import {
getInfoAsync, getInfoAsync,
readDirectoryAsync, readDirectoryAsync,
} from 'expo-file-system' } from 'expo-file-system'
import ExpoImageCropTool from 'expo-image-crop-tool'
import {compressIfNeeded} from './manip' import {compressIfNeeded} from './manip'
import {CropperOptions} from './types' import {type PickerImage} from './picker.shared'
import {RNImage} from './picker.shared' import {type CropperOptions} from './types'
import ExpoImageCropTool from 'expo-image-crop-tool'
async function getFile() { async function getFile() {
const imagesDir = documentDirectory! const imagesDir = documentDirectory!
@@ -35,11 +35,11 @@ async function getFile() {
}) })
} }
export async function openPicker(): Promise<RNImage[]> { export async function openPicker(): Promise<PickerImage[]> {
return [await getFile()] return [await getFile()]
} }
export async function openCamera(): Promise<RNImage> { export async function openCamera(): Promise<PickerImage> {
return await getFile() return await getFile()
} }
+2 -2
View File
@@ -1,5 +1,5 @@
import { import {
ImagePickerOptions, type ImagePickerOptions,
launchImageLibraryAsync, launchImageLibraryAsync,
MediaTypeOptions, MediaTypeOptions,
} from 'expo-image-picker' } from 'expo-image-picker'
@@ -9,7 +9,7 @@ import {t} from '@lingui/macro'
import * as Toast from '#/view/com/util/Toast' import * as Toast from '#/view/com/util/Toast'
import {getDataUriSize} from './util' import {getDataUriSize} from './util'
export type RNImage = { export type PickerImage = {
mime: string mime: string
height: number height: number
width: number width: number
+3 -3
View File
@@ -1,7 +1,7 @@
import ExpoImageCropTool, {OpenCropperOptions} from 'expo-image-crop-tool' import ExpoImageCropTool, {type OpenCropperOptions} from 'expo-image-crop-tool'
import {ImagePickerOptions, launchCameraAsync} from 'expo-image-picker' import {type ImagePickerOptions, launchCameraAsync} from 'expo-image-picker'
export {openPicker, type RNImage} from './picker.shared' export {openPicker, type PickerImage as RNImage} from './picker.shared'
export async function openCamera(customOpts: ImagePickerOptions) { export async function openCamera(customOpts: ImagePickerOptions) {
const opts: ImagePickerOptions = { const opts: ImagePickerOptions = {
+6 -6
View File
@@ -1,17 +1,17 @@
/// <reference lib="dom" /> /// <reference lib="dom" />
import {CameraOpts, CropperOptions} from './types'
import {unstable__openModal} from '#/state/modals' import {unstable__openModal} from '#/state/modals'
import {RNImage} from './picker.shared' import {type PickerImage} from './picker.shared'
import {type CameraOpts, type CropperOptions} from './types'
export {openPicker, type RNImage} from './picker.shared' export {openPicker, type PickerImage as RNImage} from './picker.shared'
export async function openCamera(_opts: CameraOpts): Promise<RNImage> { export async function openCamera(_opts: CameraOpts): Promise<PickerImage> {
// const mediaType = opts.mediaType || 'photo' TODO // const mediaType = opts.mediaType || 'photo' TODO
throw new Error('TODO') throw new Error('TODO')
} }
export async function openCropper(opts: CropperOptions): Promise<RNImage> { export async function openCropper(opts: CropperOptions): Promise<PickerImage> {
// TODO handle more opts // TODO handle more opts
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
unstable__openModal({ unstable__openModal({
@@ -23,7 +23,7 @@ export async function openCropper(opts: CropperOptions): Promise<RNImage> {
: undefined, : undefined,
aspect: opts.webAspectRatio, aspect: opts.webAspectRatio,
circular: opts.webCircularCrop, circular: opts.webCircularCrop,
onSelect: (img?: RNImage) => { onSelect: (img?: PickerImage) => {
if (img) { if (img) {
resolve(img) resolve(img)
} else { } else {