import {useState} from 'react' import {TouchableOpacity, View} from 'react-native' import {msg, 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 { EmbedPlayerParams, parseEmbedPlayerFromUrl, } from '#/lib/strings/embed-player' import {isAndroid} from '#/platform/detection' import {useResolveGifQuery} from '#/state/queries/resolve-link' import {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 {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 {Text} from '#/components/Typography' import {GifEmbed} from '../util/post-embeds/GifEmbed' 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. Limit:{' '} {i18n.number(MAX_ALT_TEXT)} characters. )} {/* below the text input to force tab order */} Add alt text {/* Maybe fix this later -h */} {isAndroid ? : null} ) }