diff options
author | Samuel Newman <mozzius@protonmail.com> | 2024-05-07 20:05:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-07 20:05:40 +0100 |
commit | 7d72dfb1cb514a9ab8ee2874390c667d49a78e8b (patch) | |
tree | a1ee8e198fe9654b0ca1899e85cf47e2e6397019 /src/view/com/util/post-embeds/GifEmbed.tsx | |
parent | 77e6c75a2ca3c1389965c142e367d8c3b9faff81 (diff) | |
download | voidsky-7d72dfb1cb514a9ab8ee2874390c667d49a78e8b.tar.zst |
[GIFs] Restore default alt text (#3893)
* restore default alt text * factor out gif alt logic + enable require alt text setting * rm console.log * don't prefill input + esc handling * typo * Nits * shorten user alt prefix * Remove unnecessary condition, rename for clarity * Add comment --------- Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
Diffstat (limited to 'src/view/com/util/post-embeds/GifEmbed.tsx')
-rw-r--r-- | src/view/com/util/post-embeds/GifEmbed.tsx | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/view/com/util/post-embeds/GifEmbed.tsx b/src/view/com/util/post-embeds/GifEmbed.tsx index 286b57992..deb82655b 100644 --- a/src/view/com/util/post-embeds/GifEmbed.tsx +++ b/src/view/com/util/post-embeds/GifEmbed.tsx @@ -6,6 +6,7 @@ import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {HITSLOP_10} from '#/lib/constants' +import {parseAltFromGIFDescription} from '#/lib/gif-alt-text' import {isWeb} from '#/platform/detection' import {EmbedPlayerParams} from 'lib/strings/embed-player' import {useAutoplayDisabled} from 'state/preferences' @@ -116,6 +117,11 @@ export function GifEmbed({ playerRef.current?.toggleAsync() }, []) + const parsedAlt = React.useMemo( + () => parseAltFromGIFDescription(link.description), + [link], + ) + return ( <View style={[a.rounded_sm, a.overflow_hidden, a.mt_sm, {maxWidth: '100%'}]}> @@ -140,12 +146,10 @@ export function GifEmbed({ onPlayerStateChange={onPlayerStateChange} ref={playerRef} accessibilityHint={_(msg`Animated GIF`)} - accessibilityLabel={link.description.replace('Alt text: ', '')} + accessibilityLabel={parsedAlt.alt} /> - {!hideAlt && link.description.startsWith('Alt text: ') && ( - <AltText text={link.description.replace('Alt text: ', '')} /> - )} + {!hideAlt && parsedAlt.isPreferred && <AltText text={parsedAlt.alt} />} </View> </View> ) |