reuse gif controls component for tenor gifs

This commit is contained in:
Samuel Newman
2026-02-02 15:06:03 -06:00
parent d60f0a6e97
commit 4cabb85344
2 changed files with 7 additions and 58 deletions
@@ -1,6 +1,5 @@
import {useRef, useState} from 'react' import {useRef, useState} from 'react'
import { import {
Pressable,
type StyleProp, type StyleProp,
StyleSheet, StyleSheet,
TouchableOpacity, TouchableOpacity,
@@ -17,60 +16,13 @@ import {useAutoplayDisabled} from '#/state/preferences'
import {useLargeAltBadgeEnabled} from '#/state/preferences/large-alt-badge' import {useLargeAltBadgeEnabled} from '#/state/preferences/large-alt-badge'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import {Fill} from '#/components/Fill' import {Fill} from '#/components/Fill'
import {Loader} from '#/components/Loader' import {MediaInsetBorder} from '#/components/MediaInsetBorder'
import * as Prompt from '#/components/Prompt' import * as Prompt from '#/components/Prompt'
import {Text} from '#/components/Typography' import {Text} from '#/components/Typography'
import {PlayButtonIcon} from '#/components/video/PlayButtonIcon'
import {IS_WEB} from '#/env' import {IS_WEB} from '#/env'
import {GifView} from '../../../../../modules/expo-bluesky-gif-view' import {GifView} from '../../../../../modules/expo-bluesky-gif-view'
import {type GifViewStateChangeEvent} from '../../../../../modules/expo-bluesky-gif-view/src/GifView.types' import {type GifViewStateChangeEvent} from '../../../../../modules/expo-bluesky-gif-view/src/GifView.types'
import {GifPresentationControls} from '../VideoEmbed/GifPresentationControls'
function PlaybackControls({
onPress,
isPlaying,
isLoaded,
}: {
onPress: () => void
isPlaying: boolean
isLoaded: boolean
}) {
const {_} = useLingui()
const t = useTheme()
return (
<Pressable
accessibilityRole="button"
accessibilityHint={_(msg`Plays or pauses the GIF`)}
accessibilityLabel={isPlaying ? _(msg`Pause`) : _(msg`Play`)}
style={[
a.absolute,
a.align_center,
a.justify_center,
!isLoaded && a.border,
t.atoms.border_contrast_medium,
a.inset_0,
a.w_full,
a.h_full,
{
zIndex: 2,
backgroundColor: !isLoaded
? t.atoms.bg_contrast_25.backgroundColor
: undefined,
},
]}
onPress={onPress}>
{!isLoaded ? (
<View>
<View style={[a.align_center, a.justify_center]}>
<Loader size="xl" />
</View>
</View>
) : !isPlaying ? (
<PlayButtonIcon />
) : undefined}
</Pressable>
)
}
export function GifEmbed({ export function GifEmbed({
params, params,
@@ -120,8 +72,6 @@ export function GifEmbed({
style={[ style={[
a.rounded_md, a.rounded_md,
a.overflow_hidden, a.overflow_hidden,
a.border,
t.atoms.border_contrast_low,
{backgroundColor: t.palette.black}, {backgroundColor: t.palette.black},
{aspectRatio}, {aspectRatio},
style, style,
@@ -139,10 +89,11 @@ export function GifEmbed({
right: -2, right: -2,
}, },
]}> ]}>
<PlaybackControls <MediaInsetBorder />
<GifPresentationControls
onPress={onPress} onPress={onPress}
isPlaying={playerState.isPlaying} isPlaying={playerState.isPlaying}
isLoaded={playerState.isLoaded} isLoading={!playerState.isLoaded}
/> />
<GifView <GifView
source={params.playerUri} source={params.playerUri}
@@ -33,9 +33,7 @@ export function GifPresentationControls({
a.inset_0, a.inset_0,
a.w_full, a.w_full,
a.h_full, a.h_full,
{ {zIndex: 2},
zIndex: 2,
},
]} ]}
onPress={onPress}> onPress={onPress}>
{isLoading ? ( {isLoading ? (
@@ -51,7 +49,7 @@ export function GifPresentationControls({
style={[ style={[
t.name === 'light' ? t.atoms.bg_contrast_975 : t.atoms.bg, t.name === 'light' ? t.atoms.bg_contrast_975 : t.atoms.bg,
{ {
opacity: 0.3, opacity: 0.2,
zIndex: 1, zIndex: 1,
}, },
]} ]}