From f0706dbe9ffb758d2aa1f75c51cfa0c61cc84482 Mon Sep 17 00:00:00 2001 From: Ollie Hsieh Date: Fri, 21 Apr 2023 14:20:06 -0700 Subject: Add alt text support and rework image layout (#503) * Add alt text support and rework image layout * Add additional BottomSheet implementation to account for nested Composer modal * Use mobile gallery layout on mobile web * Missing key * Fix lint * Move altimage modal into the standard modal system * Fix overflow wrapping of images * Fixes to the alt-image modal * Remove unnecessary switch * Restore old imagelayoutgrid code --------- Co-authored-by: Paul Frazee --- src/view/com/util/images/AutoSizedImage.tsx | 41 ++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'src/view/com/util/images/AutoSizedImage.tsx') diff --git a/src/view/com/util/images/AutoSizedImage.tsx b/src/view/com/util/images/AutoSizedImage.tsx index 17e3e809b..8c31f5614 100644 --- a/src/view/com/util/images/AutoSizedImage.tsx +++ b/src/view/com/util/images/AutoSizedImage.tsx @@ -9,29 +9,33 @@ import { import {Image} from 'expo-image' import {clamp} from 'lib/numbers' import {useStores} from 'state/index' -import {Dim} from 'lib/media/manip' +import {Dimensions} from 'lib/media/types' export const DELAY_PRESS_IN = 500 const MIN_ASPECT_RATIO = 0.33 // 1/3 const MAX_ASPECT_RATIO = 5 // 5/1 +interface Props { + alt?: string + uri: string + onPress?: () => void + onLongPress?: () => void + onPressIn?: () => void + style?: StyleProp + children?: React.ReactNode +} + export function AutoSizedImage({ + alt, uri, onPress, onLongPress, onPressIn, style, children = null, -}: { - uri: string - onPress?: () => void - onLongPress?: () => void - onPressIn?: () => void - style?: StyleProp - children?: React.ReactNode -}) { +}: Props) { const store = useStores() - const [dim, setDim] = React.useState( + const [dim, setDim] = React.useState( store.imageSizes.get(uri), ) const [aspectRatio, setAspectRatio] = React.useState( @@ -59,20 +63,31 @@ export function AutoSizedImage({ onPressIn={onPressIn} delayPressIn={DELAY_PRESS_IN} style={[styles.container, style]}> - + {children} ) } + return ( - + {children} ) } -function calc(dim: Dim) { +function calc(dim: Dimensions) { if (dim.width === 0 || dim.height === 0) { return 1 } -- cgit 1.4.1