Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split GifEmbed props #5615

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/view/com/composer/GifAltText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ function AltTextInner({
</Text>
<View style={[a.align_center]}>
<GifEmbed
link={link}
thumb={link.thumb}
altText={altText}
isPreferredAltText={true}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note these can just be altText and true now because we're always passing down the "preferred" version. (In any case they don't really matter because it's a preview and has hideAlt. Arguably maybe it shouldn't get any alt at all.)

params={params}
hideAlt
style={[native({maxHeight: 225})]}
Expand Down
12 changes: 11 additions & 1 deletion src/view/com/util/post-embeds/ExternalLinkEmbed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {AppBskyEmbedExternal} from '@atproto/api'
import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'

import {parseAltFromGIFDescription} from '#/lib/gif-alt-text'
import {usePalette} from '#/lib/hooks/usePalette'
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
import {shareUrl} from '#/lib/sharing'
Expand Down Expand Up @@ -55,7 +56,16 @@ export const ExternalLinkEmbed = ({
}, [link.uri, externalEmbedPrefs])

if (embedPlayerParams?.source === 'tenor') {
return <GifEmbed params={embedPlayerParams} link={link} hideAlt={hideAlt} />
const parsedAlt = parseAltFromGIFDescription(link.description)
return (
<GifEmbed
params={embedPlayerParams}
thumb={link.thumb}
altText={parsedAlt.alt}
isPreferredAltText={parsedAlt.isPreferred}
hideAlt={hideAlt}
/>
)
}

return (
Expand Down
21 changes: 9 additions & 12 deletions src/view/com/util/post-embeds/GifEmbed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import {
View,
ViewStyle,
} from 'react-native'
import {AppBskyEmbedExternal} from '@atproto/api'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'

import {HITSLOP_20} from '#/lib/constants'
import {parseAltFromGIFDescription} from '#/lib/gif-alt-text'
import {EmbedPlayerParams} from '#/lib/strings/embed-player'
import {isWeb} from '#/platform/detection'
import {useAutoplayDisabled} from '#/state/preferences'
Expand Down Expand Up @@ -77,12 +75,16 @@ function PlaybackControls({

export function GifEmbed({
params,
link,
thumb,
altText,
isPreferredAltText,
hideAlt,
style = {width: '100%'},
}: {
params: EmbedPlayerParams
link: AppBskyEmbedExternal.ViewExternal
thumb: string | undefined
altText: string
isPreferredAltText: boolean
hideAlt?: boolean
style?: StyleProp<ViewStyle>
}) {
Expand Down Expand Up @@ -111,11 +113,6 @@ export function GifEmbed({
playerRef.current?.toggleAsync()
}, [])

const parsedAlt = React.useMemo(
() => parseAltFromGIFDescription(link.description),
[link],
)

return (
<View style={[a.rounded_md, a.overflow_hidden, a.mt_sm, style]}>
<View
Expand All @@ -131,13 +128,13 @@ export function GifEmbed({
/>
<GifView
source={params.playerUri}
placeholderSource={link.thumb}
placeholderSource={thumb}
style={[a.flex_1, a.rounded_md]}
autoplay={!autoplayDisabled}
onPlayerStateChange={onPlayerStateChange}
ref={playerRef}
accessibilityHint={_(msg`Animated GIF`)}
accessibilityLabel={parsedAlt.alt}
accessibilityLabel={altText}
/>
{!playerState.isPlaying && (
<Fill
Expand All @@ -150,7 +147,7 @@ export function GifEmbed({
/>
)}
<MediaInsetBorder />
{!hideAlt && parsedAlt.isPreferred && <AltText text={parsedAlt.alt} />}
{!hideAlt && isPreferredAltText && <AltText text={altText} />}
</View>
</View>
)
Expand Down
Loading