Fix openCamera, openCropped, lightbox model, and image model usages (#1908)

zio/stable
Eric Bailey 2023-11-14 19:46:46 -06:00 committed by GitHub
parent 7d5e01f433
commit ab1ce078ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 11 additions and 34 deletions

View File

@ -1,4 +1,3 @@
import {RootStoreModel} from 'state/index'
import {Image as RNImage} from 'react-native-image-crop-picker' import {Image as RNImage} from 'react-native-image-crop-picker'
import RNFS from 'react-native-fs' import RNFS from 'react-native-fs'
import {CropperOptions} from './types' import {CropperOptions} from './types'
@ -22,18 +21,15 @@ async function getFile() {
}) })
} }
export async function openPicker(_store: RootStoreModel): Promise<RNImage[]> { export async function openPicker(): Promise<RNImage[]> {
return [await getFile()] return [await getFile()]
} }
export async function openCamera(_store: RootStoreModel): Promise<RNImage> { export async function openCamera(): Promise<RNImage> {
return await getFile() return await getFile()
} }
export async function openCropper( export async function openCropper(opts: CropperOptions): Promise<RNImage> {
_store: RootStoreModel,
opts: CropperOptions,
): Promise<RNImage> {
return { return {
path: opts.path, path: opts.path,
mime: 'image/jpeg', mime: 'image/jpeg',

View File

@ -6,15 +6,6 @@ import {
import {CameraOpts, CropperOptions} from './types' import {CameraOpts, CropperOptions} from './types'
export {openPicker} from './picker.shared' export {openPicker} from './picker.shared'
/**
* NOTE
* These methods all include the RootStoreModel as the first param
* because the web versions require it. The signatures have to remain
* equivalent between the different forms, but the store param is not
* used here.
* -prf
*/
export async function openCamera(opts: CameraOpts): Promise<RNImage> { export async function openCamera(opts: CameraOpts): Promise<RNImage> {
const item = await openCameraFn({ const item = await openCameraFn({
width: opts.width, width: opts.width,

View File

@ -6,7 +6,6 @@ import {
} from '@fortawesome/react-native-fontawesome' } from '@fortawesome/react-native-fontawesome'
import {usePalette} from 'lib/hooks/usePalette' import {usePalette} from 'lib/hooks/usePalette'
import {useAnalytics} from 'lib/analytics/analytics' import {useAnalytics} from 'lib/analytics/analytics'
import {useStores} from 'state/index'
import {openCamera} from 'lib/media/picker' import {openCamera} from 'lib/media/picker'
import {useCameraPermission} from 'lib/hooks/usePermissions' import {useCameraPermission} from 'lib/hooks/usePermissions'
import {HITSLOP_10, POST_IMG_MAX} from 'lib/constants' import {HITSLOP_10, POST_IMG_MAX} from 'lib/constants'
@ -23,7 +22,6 @@ type Props = {
export function OpenCameraBtn({gallery}: Props) { export function OpenCameraBtn({gallery}: Props) {
const pal = usePalette('default') const pal = usePalette('default')
const {track} = useAnalytics() const {track} = useAnalytics()
const store = useStores()
const {_} = useLingui() const {_} = useLingui()
const {requestCameraAccessIfNeeded} = useCameraPermission() const {requestCameraAccessIfNeeded} = useCameraPermission()
@ -34,7 +32,7 @@ export function OpenCameraBtn({gallery}: Props) {
return return
} }
const img = await openCamera(store, { const img = await openCamera({
width: POST_IMG_MAX.width, width: POST_IMG_MAX.width,
height: POST_IMG_MAX.height, height: POST_IMG_MAX.height,
freeStyleCropEnabled: true, freeStyleCropEnabled: true,
@ -45,7 +43,7 @@ export function OpenCameraBtn({gallery}: Props) {
// ignore // ignore
logger.warn('Error using camera', {error: err}) logger.warn('Error using camera', {error: err})
} }
}, [gallery, track, store, requestCameraAccessIfNeeded]) }, [gallery, track, requestCameraAccessIfNeeded])
const shouldShowCameraButton = isNative || isMobileWeb const shouldShowCameraButton = isNative || isMobileWeb
if (!shouldShowCameraButton) { if (!shouldShowCameraButton) {

View File

@ -120,9 +120,7 @@ export function useExternalLinkFetch({
setExtLink({ setExtLink({
...extLink, ...extLink,
isLoading: false, // done isLoading: false, // done
localThumb: localThumb localThumb: localThumb ? new ImageModel(localThumb) : undefined,
? new ImageModel(store, localThumb)
: undefined,
}) })
}) })
return cleanup return cleanup

View File

@ -94,7 +94,7 @@ const LightboxFooter = observer(function LightboxFooter({
altText = opts.images[imageIndex].alt || '' altText = opts.images[imageIndex].alt || ''
} else if (lightbox.name === 'profile-image') { } else if (lightbox.name === 'profile-image') {
const opts = lightbox as models.ProfileImageLightbox const opts = lightbox as models.ProfileImageLightbox
uri = opts.profileView.avatar || '' uri = opts.profile.avatar || ''
} }
return ( return (

View File

@ -9,7 +9,6 @@ import {
usePhotoLibraryPermission, usePhotoLibraryPermission,
useCameraPermission, useCameraPermission,
} from 'lib/hooks/usePermissions' } from 'lib/hooks/usePermissions'
import {useStores} from 'state/index'
import {colors} from 'lib/styles' import {colors} from 'lib/styles'
import {usePalette} from 'lib/hooks/usePalette' import {usePalette} from 'lib/hooks/usePalette'
import {isWeb, isAndroid} from 'platform/detection' import {isWeb, isAndroid} from 'platform/detection'
@ -184,7 +183,6 @@ export function EditableUserAvatar({
avatar, avatar,
onSelectNewAvatar, onSelectNewAvatar,
}: EditableUserAvatarProps) { }: EditableUserAvatarProps) {
const store = useStores()
const pal = usePalette('default') const pal = usePalette('default')
const {_} = useLingui() const {_} = useLingui()
const {requestCameraAccessIfNeeded} = useCameraPermission() const {requestCameraAccessIfNeeded} = useCameraPermission()
@ -224,7 +222,7 @@ export function EditableUserAvatar({
} }
onSelectNewAvatar( onSelectNewAvatar(
await openCamera(store, { await openCamera({
width: 1000, width: 1000,
height: 1000, height: 1000,
cropperCircleOverlay: true, cropperCircleOverlay: true,
@ -255,7 +253,7 @@ export function EditableUserAvatar({
return return
} }
const croppedImage = await openCropper(store, { const croppedImage = await openCropper({
mediaType: 'photo', mediaType: 'photo',
cropperCircleOverlay: true, cropperCircleOverlay: true,
height: item.height, height: item.height,
@ -289,7 +287,6 @@ export function EditableUserAvatar({
onSelectNewAvatar, onSelectNewAvatar,
requestCameraAccessIfNeeded, requestCameraAccessIfNeeded,
requestPhotoAccessIfNeeded, requestPhotoAccessIfNeeded,
store,
], ],
) )

View File

@ -5,7 +5,6 @@ import {ModerationUI} from '@atproto/api'
import {Image} from 'expo-image' import {Image} from 'expo-image'
import {colors} from 'lib/styles' import {colors} from 'lib/styles'
import {openCamera, openCropper, openPicker} from '../../../lib/media/picker' import {openCamera, openCropper, openPicker} from '../../../lib/media/picker'
import {useStores} from 'state/index'
import { import {
usePhotoLibraryPermission, usePhotoLibraryPermission,
useCameraPermission, useCameraPermission,
@ -26,7 +25,6 @@ export function UserBanner({
moderation?: ModerationUI moderation?: ModerationUI
onSelectNewBanner?: (img: RNImage | null) => void onSelectNewBanner?: (img: RNImage | null) => void
}) { }) {
const store = useStores()
const pal = usePalette('default') const pal = usePalette('default')
const {_} = useLingui() const {_} = useLingui()
const {requestCameraAccessIfNeeded} = useCameraPermission() const {requestCameraAccessIfNeeded} = useCameraPermission()
@ -50,7 +48,7 @@ export function UserBanner({
return return
} }
onSelectNewBanner?.( onSelectNewBanner?.(
await openCamera(store, { await openCamera({
width: 3000, width: 3000,
height: 1000, height: 1000,
}), }),
@ -77,7 +75,7 @@ export function UserBanner({
} }
onSelectNewBanner?.( onSelectNewBanner?.(
await openCropper(store, { await openCropper({
mediaType: 'photo', mediaType: 'photo',
path: items[0].path, path: items[0].path,
width: 3000, width: 3000,
@ -106,7 +104,6 @@ export function UserBanner({
onSelectNewBanner, onSelectNewBanner,
requestCameraAccessIfNeeded, requestCameraAccessIfNeeded,
requestPhotoAccessIfNeeded, requestPhotoAccessIfNeeded,
store,
], ],
) )