Same on native
This commit is contained in:
@@ -5,9 +5,9 @@ import {AppBskyEmbedVideo} from '@atproto/api'
|
|||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
import {clamp} from '#/lib/numbers'
|
import {ConstrainedImage} from '#/view/com/util/images/AutoSizedImage'
|
||||||
import {VideoEmbedInnerNative} from '#/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerNative'
|
import {VideoEmbedInnerNative} from '#/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerNative'
|
||||||
import {atoms as a} from '#/alf'
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
import {Button} from '#/components/Button'
|
import {Button} from '#/components/Button'
|
||||||
import {useThrottledValue} from '#/components/hooks/useThrottledValue'
|
import {useThrottledValue} from '#/components/hooks/useThrottledValue'
|
||||||
import {PlayButtonIcon} from '#/components/video/PlayButtonIcon'
|
import {PlayButtonIcon} from '#/components/video/PlayButtonIcon'
|
||||||
@@ -16,9 +16,11 @@ import * as VideoFallback from './VideoEmbedInner/VideoFallback'
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
embed: AppBskyEmbedVideo.View
|
embed: AppBskyEmbedVideo.View
|
||||||
|
crop?: 'none' | 'square' | 'constrained'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function VideoEmbed({embed}: Props) {
|
export function VideoEmbed({embed, crop}: Props) {
|
||||||
|
const t = useTheme()
|
||||||
const [key, setKey] = useState(0)
|
const [key, setKey] = useState(0)
|
||||||
|
|
||||||
const renderError = useCallback(
|
const renderError = useCallback(
|
||||||
@@ -28,26 +30,51 @@ export function VideoEmbed({embed}: Props) {
|
|||||||
[key],
|
[key],
|
||||||
)
|
)
|
||||||
|
|
||||||
let aspectRatio = 16 / 9
|
let aspectRatio: number | undefined
|
||||||
if (embed.aspectRatio) {
|
const dims = embed.aspectRatio
|
||||||
const {width, height} = embed.aspectRatio
|
if (dims) {
|
||||||
aspectRatio = width / height
|
aspectRatio = dims.width / dims.height
|
||||||
aspectRatio = clamp(aspectRatio, 1 / 1, 3 / 1)
|
if (Number.isNaN(aspectRatio)) {
|
||||||
|
aspectRatio = undefined
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let constrained: number | undefined
|
||||||
|
let max: number | undefined
|
||||||
|
if (aspectRatio !== undefined) {
|
||||||
|
const ratio = 1 / 2 // max of 1:2 ratio in feeds
|
||||||
|
constrained = Math.max(aspectRatio, ratio)
|
||||||
|
max = Math.max(aspectRatio, 0.25) // max of 1:4 in thread
|
||||||
|
}
|
||||||
|
const cropDisabled = crop === 'none'
|
||||||
|
|
||||||
|
const contents = (
|
||||||
|
<ErrorBoundary renderError={renderError} key={key}>
|
||||||
|
<InnerWrapper embed={embed} />
|
||||||
|
</ErrorBoundary>
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View
|
<View style={[a.pt_xs]}>
|
||||||
style={[
|
{cropDisabled ? (
|
||||||
a.w_full,
|
<View
|
||||||
a.rounded_md,
|
style={[
|
||||||
a.overflow_hidden,
|
a.w_full,
|
||||||
{aspectRatio},
|
a.overflow_hidden,
|
||||||
{backgroundColor: 'black'},
|
{aspectRatio: max ?? 1},
|
||||||
a.mt_xs,
|
a.rounded_md,
|
||||||
]}>
|
a.overflow_hidden,
|
||||||
<ErrorBoundary renderError={renderError} key={key}>
|
t.atoms.bg_contrast_25,
|
||||||
<InnerWrapper embed={embed} />
|
]}>
|
||||||
</ErrorBoundary>
|
{contents}
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
<ConstrainedImage
|
||||||
|
fullBleed={crop === 'square'}
|
||||||
|
aspectRatio={constrained || 1}>
|
||||||
|
{contents}
|
||||||
|
</ConstrainedImage>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user