From 8ea6155bb4348346eeb2918ae522deccf0559d19 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Wed, 4 Sep 2024 13:08:39 -0500 Subject: [PATCH] Only do reduced layout if images embed --- src/view/com/util/images/AutoSizedImage.tsx | 4 +- src/view/com/util/images/Gallery.tsx | 76 ++++++++++++-------- src/view/com/util/images/ImageLayoutGrid.tsx | 4 +- src/view/com/util/post-embeds/QuoteEmbed.tsx | 4 +- src/view/com/util/post-embeds/index.tsx | 3 + 5 files changed, 59 insertions(+), 32 deletions(-) diff --git a/src/view/com/util/images/AutoSizedImage.tsx b/src/view/com/util/images/AutoSizedImage.tsx index be4b1490ab..1b4b8593cb 100644 --- a/src/view/com/util/images/AutoSizedImage.tsx +++ b/src/view/com/util/images/AutoSizedImage.tsx @@ -97,12 +97,14 @@ export function ConstrainedImage({ export function AutoSizedImage({ image, crop = 'constrained', + hideBadge, onPress, onLongPress, onPressIn, }: { image: AppBskyEmbedImages.ViewImage crop?: 'none' | 'square' | 'constrained' + hideBadge?: boolean onPress?: () => void onLongPress?: () => void onPressIn?: () => void @@ -133,7 +135,7 @@ export function AutoSizedImage({ accessibilityHint="" /> - {hasAlt || isCropped ? ( + {(hasAlt || isCropped) && !hideBadge ? ( void @@ -18,6 +19,7 @@ interface GalleryItemProps { onLongPress?: EventFunction onPressIn?: EventFunction imageStyle: ComponentProps['style'] + hideBadges?: boolean } export const GalleryItem: FC = ({ @@ -27,11 +29,18 @@ export const GalleryItem: FC = ({ onPress, onPressIn, onLongPress, + hideBadges, }) => { const t = useTheme() const {_} = useLingui() const largeAltBadge = useLargeAltBadgeEnabled() const image = images[index] + const hasAlt = !!image.alt + const isCropped = React.useMemo(() => { + if (!image.aspectRatio) return true + const aspect = image.aspectRatio.width / image.aspectRatio.height + return aspect !== 1 + }, [image.aspectRatio]) return ( = ({ accessibilityIgnoresInvertColors /> - {image.alt === '' ? null : ( - - - ALT - + {(hasAlt || isCropped) && !hideBadges ? ( + + {isCropped && ( + + )} + {hasAlt && ( + + ALT + + )} - )} + ) : null} ) } - -const styles = StyleSheet.create({ - altContainer: { - backgroundColor: 'rgba(0, 0, 0, 0.75)', - borderRadius: 6, - paddingHorizontal: 6, - paddingVertical: 3, - position: 'absolute', - // Related to margin/gap hack. This keeps the alt label in the same position - // on all platforms - right: isWeb ? 8 : 5, - bottom: isWeb ? 8 : 5, - }, - alt: { - color: 'white', - fontSize: 7, - fontWeight: 'bold', - }, -}) diff --git a/src/view/com/util/images/ImageLayoutGrid.tsx b/src/view/com/util/images/ImageLayoutGrid.tsx index ba6c04f505..927136b014 100644 --- a/src/view/com/util/images/ImageLayoutGrid.tsx +++ b/src/view/com/util/images/ImageLayoutGrid.tsx @@ -1,8 +1,9 @@ import React from 'react' import {StyleProp, StyleSheet, View, ViewStyle} from 'react-native' import {AppBskyEmbedImages} from '@atproto/api' -import {GalleryItem} from './Gallery' + import {isWeb} from 'platform/detection' +import {GalleryItem} from './Gallery' interface ImageLayoutGridProps { images: AppBskyEmbedImages.ViewImage[] @@ -10,6 +11,7 @@ interface ImageLayoutGridProps { onLongPress?: (index: number) => void onPressIn?: (index: number) => void style?: StyleProp + hideBadges?: boolean } export function ImageLayoutGrid({style, ...props}: ImageLayoutGridProps) { diff --git a/src/view/com/util/post-embeds/QuoteEmbed.tsx b/src/view/com/util/post-embeds/QuoteEmbed.tsx index d1a2561e09..53cc3b8a15 100644 --- a/src/view/com/util/post-embeds/QuoteEmbed.tsx +++ b/src/view/com/util/post-embeds/QuoteEmbed.tsx @@ -207,6 +207,7 @@ export function QuoteEmbed({ } } }, [quote.embeds, allowNestedQuotes]) + const isImagesEmbed = AppBskyEmbedImages.isView(embed) const onBeforePress = React.useCallback(() => { precacheProfile(queryClient, quote.author) @@ -237,7 +238,8 @@ export function QuoteEmbed({ ) : null} - {viewContext === QuoteEmbedViewContext.FeedEmbedRecordWithMedia ? ( + {viewContext === QuoteEmbedViewContext.FeedEmbedRecordWithMedia && + isImagesEmbed ? ( {embed && ( diff --git a/src/view/com/util/post-embeds/index.tsx b/src/view/com/util/post-embeds/index.tsx index 1bca262390..10ebd400a6 100644 --- a/src/view/com/util/post-embeds/index.tsx +++ b/src/view/com/util/post-embeds/index.tsx @@ -164,6 +164,9 @@ export function PostEmbeds({ images={embed.images} onPress={_openLightbox} onPressIn={onPressIn} + hideBadges={ + viewContext === PostEmbedViewContext.FeedEmbedRecordWithMedia + } />