import React from 'react' import {Pressable, StyleSheet, TouchableOpacity, View} from 'react-native' import {AppBskyEmbedExternal} from '@atproto/api' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' 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' import {atoms as a, useTheme} from '#/alf' import {Loader} from '#/components/Loader' import * as Prompt from '#/components/Prompt' import {Text} from '#/components/Typography' import {GifView} from '../../../../../modules/expo-bluesky-gif-view' import {GifViewStateChangeEvent} from '../../../../../modules/expo-bluesky-gif-view/src/GifView.types' function PlaybackControls({ onPress, isPlaying, isLoaded, }: { onPress: () => void isPlaying: boolean isLoaded: boolean }) { const {_} = useLingui() const t = useTheme() return ( {!isLoaded ? ( ) : !isPlaying ? ( ) : undefined} ) } export function GifEmbed({ params, link, hideAlt, }: { params: EmbedPlayerParams link: AppBskyEmbedExternal.ViewExternal hideAlt?: boolean }) { const {_} = useLingui() const autoplayDisabled = useAutoplayDisabled() const playerRef = React.useRef(null) const [playerState, setPlayerState] = React.useState<{ isPlaying: boolean isLoaded: boolean }>({ isPlaying: !autoplayDisabled, isLoaded: false, }) const onPlayerStateChange = React.useCallback( (e: GifViewStateChangeEvent) => { setPlayerState(e.nativeEvent) }, [], ) const onPress = React.useCallback(() => { playerRef.current?.toggleAsync() }, []) const parsedAlt = React.useMemo( () => parseAltFromGIFDescription(link.description), [link], ) return ( {!hideAlt && parsedAlt.isPreferred && } ) } function AltText({text}: {text: string}) { const control = Prompt.usePromptControl() const {_} = useLingui() return ( <> ALT Alt Text {text} ) } const styles = StyleSheet.create({ altContainer: { backgroundColor: 'rgba(0, 0, 0, 0.75)', borderRadius: 6, paddingHorizontal: 6, paddingVertical: 3, position: 'absolute', // Related to margin/gap hack. This keeps the alt label in the same position // on all platforms left: isWeb ? 8 : 5, bottom: isWeb ? 8 : 5, zIndex: 2, }, alt: { color: 'white', fontSize: 10, fontWeight: 'bold', }, })