[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>
This commit is contained in:
parent
77e6c75a2c
commit
7d72dfb1cb
4 changed files with 84 additions and 20 deletions
|
@ -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>
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue