diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/api/index.ts | 2 | ||||
-rw-r--r-- | src/state/models/media/image.ts | 13 | ||||
-rw-r--r-- | src/view/com/util/images/AutoSizedImage.tsx | 4 | ||||
-rw-r--r-- | src/view/com/util/post-embeds/index.tsx | 9 | ||||
-rw-r--r-- | src/view/screens/Profile.tsx | 5 | ||||
-rw-r--r-- | src/view/shell/desktop/LeftNav.tsx | 23 |
6 files changed, 43 insertions, 13 deletions
diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index 4ecd32046..8a9389a18 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -133,10 +133,12 @@ export async function post(store: RootStoreModel, opts: PostOpts) { opts.onStateChange?.(`Uploading image #${images.length + 1}...`) await image.compress() const path = image.compressed?.path ?? image.path + const {width, height} = image.compressed || image const res = await uploadBlob(store, path, 'image/jpeg') images.push({ image: res.data.blob, alt: image.altText ?? '', + aspectRatio: {width, height}, }) } diff --git a/src/state/models/media/image.ts b/src/state/models/media/image.ts index 844ecb778..10aef0ff4 100644 --- a/src/state/models/media/image.ts +++ b/src/state/models/media/image.ts @@ -8,6 +8,7 @@ import {openCropper} from 'lib/media/picker' import {ActionCrop, FlipType, SaveFormat} from 'expo-image-manipulator' import {Position} from 'react-avatar-editor' import {Dimensions} from 'lib/media/types' +import {isIOS} from 'platform/detection' export interface ImageManipulationAttributes { aspectRatio?: '4:3' | '1:1' | '3:4' | 'None' @@ -164,8 +165,13 @@ export class ImageModel implements Omit<RNImage, 'size'> { // Mobile async crop() { try { - // openCropper requires an output width and height hence - // getting upload dimensions before cropping is necessary. + // NOTE + // on ios, react-native-image-cropper gives really bad quality + // without specifying width and height. on android, however, the + // crop stretches incorrectly if you do specify it. these are + // both separate bugs in the library. we deal with that by + // providing width & height for ios only + // -prf const {width, height} = this.getUploadDimensions({ width: this.width, height: this.height, @@ -175,8 +181,7 @@ export class ImageModel implements Omit<RNImage, 'size'> { mediaType: 'photo', path: this.path, freeStyleCropEnabled: true, - width, - height, + ...(isIOS ? {width, height} : {}), }) runInAction(() => { diff --git a/src/view/com/util/images/AutoSizedImage.tsx b/src/view/com/util/images/AutoSizedImage.tsx index da2f7ab45..035e29c25 100644 --- a/src/view/com/util/images/AutoSizedImage.tsx +++ b/src/view/com/util/images/AutoSizedImage.tsx @@ -11,6 +11,7 @@ const MAX_ASPECT_RATIO = 5 // 5/1 interface Props { alt?: string uri: string + dimensionsHint?: Dimensions onPress?: () => void onLongPress?: () => void onPressIn?: () => void @@ -21,6 +22,7 @@ interface Props { export function AutoSizedImage({ alt, uri, + dimensionsHint, onPress, onLongPress, onPressIn, @@ -29,7 +31,7 @@ export function AutoSizedImage({ }: Props) { const store = useStores() const [dim, setDim] = React.useState<Dimensions | undefined>( - store.imageSizes.get(uri), + dimensionsHint || store.imageSizes.get(uri), ) const [aspectRatio, setAspectRatio] = React.useState<number>( dim ? calc(dim) : 1, diff --git a/src/view/com/util/post-embeds/index.tsx b/src/view/com/util/post-embeds/index.tsx index ce6da4a1b..2d79eed8f 100644 --- a/src/view/com/util/post-embeds/index.tsx +++ b/src/view/com/util/post-embeds/index.tsx @@ -93,7 +93,11 @@ export function PostEmbeds({ const {images} = embed if (images.length > 0) { - const items = embed.images.map(img => ({uri: img.fullsize, alt: img.alt})) + const items = embed.images.map(img => ({ + uri: img.fullsize, + alt: img.alt, + aspectRatio: img.aspectRatio, + })) const openLightbox = (index: number) => { store.shell.openLightbox(new ImagesLightbox(items, index)) } @@ -104,12 +108,13 @@ export function PostEmbeds({ } if (images.length === 1) { - const {alt, thumb} = images[0] + const {alt, thumb, aspectRatio} = images[0] return ( <View style={[styles.imagesContainer, style]}> <AutoSizedImage alt={alt} uri={thumb} + dimensionsHint={aspectRatio} onPress={() => openLightbox(0)} onPressIn={() => onPressIn(0)} style={[ diff --git a/src/view/screens/Profile.tsx b/src/view/screens/Profile.tsx index efcb588f6..596bda57e 100644 --- a/src/view/screens/Profile.tsx +++ b/src/view/screens/Profile.tsx @@ -91,7 +91,10 @@ export const ProfileScreen = withAuthRequired( const onPressCompose = React.useCallback(() => { track('ProfileScreen:PressCompose') const mention = - uiState.profile.handle === store.me.handle ? '' : uiState.profile.handle + uiState.profile.handle === store.me.handle || + uiState.profile.handle === 'handle.invalid' + ? undefined + : uiState.profile.handle store.shell.openComposer({mention}) }, [store, track, uiState]) const onSelectView = React.useCallback( diff --git a/src/view/shell/desktop/LeftNav.tsx b/src/view/shell/desktop/LeftNav.tsx index b19d5e8ab..fb3d66462 100644 --- a/src/view/shell/desktop/LeftNav.tsx +++ b/src/view/shell/desktop/LeftNav.tsx @@ -185,20 +185,33 @@ function ComposeBtn() { const {getState} = useNavigation() const {isTablet} = useWebMediaQueries() - const getProfileHandle = () => { + const getProfileHandle = async () => { const {routes} = getState() const currentRoute = routes[routes.length - 1] + if (currentRoute.name === 'Profile') { - const {name: handle} = + let handle: string | undefined = ( currentRoute.params as CommonNavigatorParams['Profile'] - if (handle === store.me.handle) return undefined + ).name + + if (handle.startsWith('did:')) { + const cached = await store.profiles.cache.get(handle) + const profile = cached ? cached.data : undefined + // if we can't resolve handle, set to undefined + handle = profile?.handle || undefined + } + + if (!handle || handle === store.me.handle || handle === 'handle.invalid') + return undefined + return handle } + return undefined } - const onPressCompose = () => - store.shell.openComposer({mention: getProfileHandle()}) + const onPressCompose = async () => + store.shell.openComposer({mention: await getProfileHandle()}) if (isTablet) { return null |