diff options
author | Samuel Newman <mozzius@protonmail.com> | 2024-08-29 15:58:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-29 15:58:22 +0100 |
commit | d92731b1ebf006ab795cf726452a7f15a49ba618 (patch) | |
tree | 2ce74ac8f085d1d454fd4b8b6495cbac4f081080 /src/view/com/util/post-embeds/VideoEmbed.web.tsx | |
parent | b136c44287f1a4c202f4614da499f1e59a557bea (diff) | |
download | voidsky-d92731b1ebf006ab795cf726452a7f15a49ba618.tar.zst |
[Video] Lexicon implementation (#4881)
* implement AppBskyEmbedVideo lexicon in player * add alt to native player * add prerelease package * update prerelease * add video embed view manually from record * fix type error on example video * black bg + use aspect ratio on web * add video to feeds * fix video overflowing aspect ratio * remove prerelease package --------- Co-authored-by: Samuel Newman <10959775+mozzius@users.noreply.github.com>
Diffstat (limited to 'src/view/com/util/post-embeds/VideoEmbed.web.tsx')
-rw-r--r-- | src/view/com/util/post-embeds/VideoEmbed.web.tsx | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/view/com/util/post-embeds/VideoEmbed.web.tsx b/src/view/com/util/post-embeds/VideoEmbed.web.tsx index c0d774abe..409f2c7ba 100644 --- a/src/view/com/util/post-embeds/VideoEmbed.web.tsx +++ b/src/view/com/util/post-embeds/VideoEmbed.web.tsx @@ -1,19 +1,23 @@ import React, {useCallback, useEffect, useRef, useState} from 'react' import {View} from 'react-native' +import {AppBskyEmbedVideo} from '@atproto/api' import {Trans} from '@lingui/macro' +import {clamp} from '#/lib/numbers' +import {useGate} from '#/lib/statsig/statsig' import { HLSUnsupportedError, VideoEmbedInnerWeb, -} from 'view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb' +} from '#/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerWeb' import {atoms as a, useTheme} from '#/alf' import {ErrorBoundary} from '../ErrorBoundary' import {useActiveVideoWeb} from './ActiveVideoWebContext' import * as VideoFallback from './VideoEmbedInner/VideoFallback' -export function VideoEmbed({source}: {source: string}) { +export function VideoEmbed({embed}: {embed: AppBskyEmbedVideo.View}) { const t = useTheme() const ref = useRef<HTMLDivElement>(null) + const gate = useGate() const {active, setActive, sendPosition, currentActiveView} = useActiveVideoWeb() const [onScreen, setOnScreen] = useState(false) @@ -43,12 +47,25 @@ export function VideoEmbed({source}: {source: string}) { [key], ) + if (!gate('videos')) { + return null + } + + let aspectRatio = 16 / 9 + + if (embed.aspectRatio) { + const {width, height} = embed.aspectRatio + // min: 3/1, max: square + aspectRatio = clamp(width / height, 1 / 1, 3 / 1) + } + return ( <View style={[ a.w_full, - {aspectRatio: 16 / 9}, - t.atoms.bg_contrast_25, + {aspectRatio}, + {backgroundColor: t.palette.black}, + a.relative, a.rounded_sm, a.my_xs, ]}> @@ -61,7 +78,7 @@ export function VideoEmbed({source}: {source: string}) { sendPosition={sendPosition} isAnyViewActive={currentActiveView !== null}> <VideoEmbedInnerWeb - source={source} + embed={embed} active={active} setActive={setActive} onScreen={onScreen} |