[APP-2170] Render GIFs through ConstrainedImage (#10453)

Co-authored-by: vineyardbovines <spencer@thepope.dev>
This commit is contained in:
Spence Pope
2026-05-12 11:17:46 -04:00
committed by GitHub
parent 859e172651
commit a03cbd8b1a
2 changed files with 60 additions and 61 deletions
@@ -1,13 +1,13 @@
import {useRef, useState} from 'react' import {useRef, useState} from 'react'
import {type StyleProp, View, type ViewStyle} from 'react-native' import {View} from 'react-native'
import {msg} from '@lingui/core/macro' import {msg} from '@lingui/core/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {clamp} from '#/lib/numbers'
import {type EmbedPlayerParams} from '#/lib/strings/embed-player' import {type EmbedPlayerParams} from '#/lib/strings/embed-player'
import {useAutoplayDisabled} from '#/state/preferences' import {useAutoplayDisabled} from '#/state/preferences'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import {Fill} from '#/components/Fill' import {Fill} from '#/components/Fill'
import {ConstrainedImage} from '#/components/images/AutoSizedImage'
import {MediaInsetBorder} from '#/components/MediaInsetBorder' import {MediaInsetBorder} from '#/components/MediaInsetBorder'
import {GifView} from '../../../../../modules/expo-bluesky-gif-view' import {GifView} from '../../../../../modules/expo-bluesky-gif-view'
import {type GifViewStateChangeEvent} from '../../../../../modules/expo-bluesky-gif-view/src/GifView.types' import {type GifViewStateChangeEvent} from '../../../../../modules/expo-bluesky-gif-view/src/GifView.types'
@@ -19,14 +19,12 @@ export function GifEmbed({
altText, altText,
isPreferredAltText, isPreferredAltText,
hideAlt, hideAlt,
style = {width: '100%'},
}: { }: {
params: EmbedPlayerParams params: EmbedPlayerParams
thumb: string | undefined thumb: string | undefined
altText: string altText: string
isPreferredAltText: boolean isPreferredAltText: boolean
hideAlt?: boolean hideAlt?: boolean
style?: StyleProp<ViewStyle>
}) { }) {
const t = useTheme() const t = useTheme()
const {_} = useLingui() const {_} = useLingui()
@@ -53,17 +51,20 @@ export function GifEmbed({
let aspectRatio = 1 let aspectRatio = 1
if (params.dimensions) { if (params.dimensions) {
const ratio = params.dimensions.width / params.dimensions.height const ratio = params.dimensions.width / params.dimensions.height
aspectRatio = clamp(ratio, 0.75, 4) if (!Number.isNaN(ratio)) {
aspectRatio = ratio
} }
}
const constrained = Math.max(aspectRatio, 1 / 2)
return ( return (
<ConstrainedImage aspectRatio={constrained} minMobileAspectRatio={14 / 9}>
<View <View
style={[ style={[
a.flex_1,
a.rounded_md, a.rounded_md,
a.overflow_hidden, a.overflow_hidden,
{backgroundColor: t.palette.black}, {backgroundColor: t.palette.black},
{aspectRatio},
style,
]}> ]}>
<View <View
style={[ style={[
@@ -108,5 +109,6 @@ export function GifEmbed({
)} )}
</View> </View>
</View> </View>
</ConstrainedImage>
) )
} }
-3
View File
@@ -216,18 +216,15 @@ function AltTextInner({
style={[a.text_2xl, a.font_semi_bold, a.leading_tight, a.pb_sm]}> style={[a.text_2xl, a.font_semi_bold, a.leading_tight, a.pb_sm]}>
<Trans>Add alt text</Trans> <Trans>Add alt text</Trans>
</Text> </Text>
<View style={[a.align_center]}>
<GifEmbed <GifEmbed
thumb={thumb} thumb={thumb}
altText={altText} altText={altText}
isPreferredAltText={true} isPreferredAltText={true}
params={params} params={params}
hideAlt hideAlt
style={[{height: 225}]}
/> />
</View> </View>
</View> </View>
</View>
<Dialog.Close /> <Dialog.Close />
</Dialog.ScrollableInner> </Dialog.ScrollableInner>
) )