Fix thum dim calculation for tall images

This commit is contained in:
Dan Abramov
2024-11-09 22:21:16 +00:00
parent eab9bb82af
commit 9f8dba381c
2 changed files with 12 additions and 14 deletions
+8 -5
View File
@@ -1,5 +1,6 @@
import React from 'react' import React from 'react'
import {DimensionValue, Pressable, View} from 'react-native' import {DimensionValue, Pressable, View} from 'react-native'
import Animated, {AnimatedRef, useAnimatedRef} from 'react-native-reanimated'
import {Image} from 'expo-image' import {Image} from 'expo-image'
import {AppBskyEmbedImages} from '@atproto/api' import {AppBskyEmbedImages} from '@atproto/api'
import {msg} from '@lingui/macro' import {msg} from '@lingui/macro'
@@ -92,7 +93,7 @@ export function AutoSizedImage({
image: AppBskyEmbedImages.ViewImage image: AppBskyEmbedImages.ViewImage
crop?: 'none' | 'square' | 'constrained' crop?: 'none' | 'square' | 'constrained'
hideBadge?: boolean hideBadge?: boolean
onPress?: () => void onPress?: (containerRef: AnimatedRef<React.Component<{}, {}, any>>) => void
onLongPress?: () => void onLongPress?: () => void
onPressIn?: () => void onPressIn?: () => void
}) { }) {
@@ -107,12 +108,14 @@ export function AutoSizedImage({
src: image.thumb, src: image.thumb,
knownDimensions: image.aspectRatio ?? null, knownDimensions: image.aspectRatio ?? null,
}) })
const containerRef = useAnimatedRef()
const cropDisabled = crop === 'none' const cropDisabled = crop === 'none'
const isCropped = rawIsCropped && !cropDisabled const isCropped = rawIsCropped && !cropDisabled
const hasAlt = !!image.alt const hasAlt = !!image.alt
const contents = ( const contents = (
<> <Animated.View ref={containerRef} collapsable={false}>
<Image <Image
style={[a.w_full, a.h_full]} style={[a.w_full, a.h_full]}
source={image.thumb} source={image.thumb}
@@ -185,13 +188,13 @@ export function AutoSizedImage({
)} )}
</View> </View>
) : null} ) : null}
</> </Animated.View>
) )
if (cropDisabled) { if (cropDisabled) {
return ( return (
<Pressable <Pressable
onPress={onPress} onPress={() => onPress?.(containerRef)}
onLongPress={onLongPress} onLongPress={onLongPress}
onPressIn={onPressIn} onPressIn={onPressIn}
// alt here is what screen readers actually use // alt here is what screen readers actually use
@@ -213,7 +216,7 @@ export function AutoSizedImage({
fullBleed={crop === 'square'} fullBleed={crop === 'square'}
aspectRatio={constrained ?? 1}> aspectRatio={constrained ?? 1}>
<Pressable <Pressable
onPress={onPress} onPress={() => onPress?.(containerRef)}
onLongPress={onLongPress} onLongPress={onLongPress}
onPressIn={onPressIn} onPressIn={onPressIn}
// alt here is what screen readers actually use // alt here is what screen readers actually use
+4 -9
View File
@@ -6,13 +6,12 @@ import {
View, View,
ViewStyle, ViewStyle,
} from 'react-native' } from 'react-native'
import Animated, { import {
AnimatedRef, AnimatedRef,
measure, measure,
MeasuredDimensions, MeasuredDimensions,
runOnJS, runOnJS,
runOnUI, runOnUI,
useAnimatedRef,
} from 'react-native-reanimated' } from 'react-native-reanimated'
import {Image} from 'expo-image' import {Image} from 'expo-image'
import { import {
@@ -69,7 +68,6 @@ export function PostEmbeds({
viewContext?: PostEmbedViewContext viewContext?: PostEmbedViewContext
}) { }) {
const {openLightbox} = useLightboxControls() const {openLightbox} = useLightboxControls()
const containerRef = useAnimatedRef()
// quote post with media // quote post with media
// = // =
@@ -180,10 +178,7 @@ export function PostEmbeds({
const image = images[0] const image = images[0]
return ( return (
<ContentHider modui={moderation?.ui('contentMedia')}> <ContentHider modui={moderation?.ui('contentMedia')}>
<Animated.View <View style={[a.mt_sm, style]}>
ref={containerRef}
collapsable={false}
style={[a.mt_sm, style]}>
<AutoSizedImage <AutoSizedImage
crop={ crop={
viewContext === PostEmbedViewContext.ThreadHighlighted viewContext === PostEmbedViewContext.ThreadHighlighted
@@ -194,13 +189,13 @@ export function PostEmbeds({
: 'constrained' : 'constrained'
} }
image={image} image={image}
onPress={() => onPress(0, [containerRef])} onPress={containerRef => onPress(0, [containerRef])}
onPressIn={() => onPressIn(0)} onPressIn={() => onPressIn(0)}
hideBadge={ hideBadge={
viewContext === PostEmbedViewContext.FeedEmbedRecordWithMedia viewContext === PostEmbedViewContext.FeedEmbedRecordWithMedia
} }
/> />
</Animated.View> </View>
</ContentHider> </ContentHider>
) )
} }