diff options
Diffstat (limited to 'src/state')
-rw-r--r-- | src/state/gallery.ts | 29 | ||||
-rw-r--r-- | src/state/modals/index.tsx | 6 | ||||
-rw-r--r-- | src/state/shell/composer/index.tsx | 8 |
3 files changed, 22 insertions, 21 deletions
diff --git a/src/state/gallery.ts b/src/state/gallery.ts index f4c8b712e..f03ed2afe 100644 --- a/src/state/gallery.ts +++ b/src/state/gallery.ts @@ -5,8 +5,8 @@ import { moveAsync, } from 'expo-file-system' import { - Action, - ActionCrop, + type Action, + type ActionCrop, manipulateAsync, SaveFormat, } from 'expo-image-manipulator' @@ -210,17 +210,21 @@ export async function compressImage(img: ComposerImage): Promise<ImageMeta> { const source = img.transformed || img.source const [w, h] = containImageRes(source.width, source.height, POST_IMG_MAX) - const cacheDir = isNative && getImageCacheDirectory() - for (let i = 10; i > 0; i--) { - // Float precision - const factor = i / 10 + let minQualityPercentage = 0 + let maxQualityPercentage = 101 // exclusive + let newDataUri + + while (maxQualityPercentage - minQualityPercentage > 1) { + const qualityPercentage = Math.round( + (maxQualityPercentage + minQualityPercentage) / 2, + ) const res = await manipulateAsync( source.path, [{resize: {width: w, height: h}}], { - compress: factor, + compress: qualityPercentage / 100, format: SaveFormat.JPEG, base64: true, }, @@ -229,17 +233,20 @@ export async function compressImage(img: ComposerImage): Promise<ImageMeta> { const base64 = res.base64 if (base64 !== undefined && getDataUriSize(base64) <= POST_IMG_MAX.size) { - return { + minQualityPercentage = qualityPercentage + newDataUri = { path: await moveIfNecessary(res.uri), width: res.width, height: res.height, mime: 'image/jpeg', } + } else { + maxQualityPercentage = qualityPercentage } + } - if (cacheDir) { - await deleteAsync(res.uri) - } + if (newDataUri) { + return newDataUri } throw new Error(`Unable to compress image`) diff --git a/src/state/modals/index.tsx b/src/state/modals/index.tsx index 45c4fb467..f79f6213f 100644 --- a/src/state/modals/index.tsx +++ b/src/state/modals/index.tsx @@ -66,11 +66,6 @@ export interface LinkWarningModal { share?: boolean } -export interface InAppBrowserConsentModal { - name: 'in-app-browser-consent' - href: string -} - export type Modal = // Account | DeleteAccountModal @@ -96,7 +91,6 @@ export type Modal = // Generic | LinkWarningModal - | InAppBrowserConsentModal const ModalContext = React.createContext<{ isModalActive: boolean diff --git a/src/state/shell/composer/index.tsx b/src/state/shell/composer/index.tsx index 33634c047..b425873fc 100644 --- a/src/state/shell/composer/index.tsx +++ b/src/state/shell/composer/index.tsx @@ -1,8 +1,8 @@ import React from 'react' import { - AppBskyActorDefs, - AppBskyFeedDefs, - ModerationDecision, + type AppBskyActorDefs, + type AppBskyFeedDefs, + type ModerationDecision, } from '@atproto/api' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' @@ -12,7 +12,7 @@ import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback' import {postUriToRelativePath, toBskyAppUrl} from '#/lib/strings/url-helpers' import {purgeTemporaryImageFiles} from '#/state/gallery' import {precacheResolveLinkQuery} from '#/state/queries/resolve-link' -import type {EmojiPickerPosition} from '#/view/com/composer/text-input/web/EmojiPicker.web' +import {type EmojiPickerPosition} from '#/view/com/composer/text-input/web/EmojiPicker' import * as Toast from '#/view/com/util/Toast' export interface ComposerOptsPostRef { |