import {useState} from 'react' import {TouchableOpacity, View} from 'react-native' import {msg, Plural, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {HITSLOP_10, MAX_ALT_TEXT} from '#/lib/constants' import {parseAltFromGIFDescription} from '#/lib/gif-alt-text' import { type EmbedPlayerParams, parseEmbedPlayerFromUrl, } from '#/lib/strings/embed-player' import {isAndroid} from '#/platform/detection' import {useResolveGifQuery} from '#/state/queries/resolve-link' import {type Gif} from '#/state/queries/tenor' import {AltTextCounterWrapper} from '#/view/com/composer/AltTextCounterWrapper' import {atoms as a, useTheme} from '#/alf' import {Button, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' import {type DialogControlProps} from '#/components/Dialog' import * as TextField from '#/components/forms/TextField' import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check' import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo' import {PlusSmall_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus' import {GifEmbed} from '#/components/Post/Embed/ExternalEmbed/Gif' import {Text} from '#/components/Typography' import {AltTextReminder} from './photos/Gallery' export function GifAltTextDialog({ gif, altText, onSubmit, }: { gif: Gif altText: string onSubmit: (alt: string) => void }) { const {data} = useResolveGifQuery(gif) const vendorAltText = parseAltFromGIFDescription(data?.description ?? '').alt const params = data ? parseEmbedPlayerFromUrl(data.uri) : undefined if (!data || !params) { return null } return ( ) } export function GifAltTextDialogLoaded({ vendorAltText, altText, onSubmit, params, thumb, }: { vendorAltText: string altText: string onSubmit: (alt: string) => void params: EmbedPlayerParams thumb: string | undefined }) { const control = Dialog.useDialogControl() const {_} = useLingui() const t = useTheme() const [altTextDraft, setAltTextDraft] = useState(altText || vendorAltText) return ( <> {altText ? ( ) : ( )} ALT { onSubmit(altTextDraft) }}> ) } function AltTextInner({ vendorAltText, altText, onChange, control, params, thumb, }: { vendorAltText: string altText: string onChange: (text: string) => void control: DialogControlProps params: EmbedPlayerParams thumb: string | undefined }) { const t = useTheme() const {_, i18n} = useLingui() return ( Descriptive alt text { if (nativeEvent.key === 'Escape') { control.close() } }} /> {altText.length > MAX_ALT_TEXT && ( Alt text will be truncated.{' '} )} {/* below the text input to force tab order */} Add alt text {/* Maybe fix this later -h */} {isAndroid ? : null} ) }