diff --git a/src/view/com/composer/videos/VideoPreview.tsx b/src/view/com/composer/videos/VideoPreview.tsx index f668c4f209..58bb65a2d9 100644 --- a/src/view/com/composer/videos/VideoPreview.tsx +++ b/src/view/com/composer/videos/VideoPreview.tsx @@ -5,10 +5,10 @@ import {type ImagePickerAsset} from 'expo-image-picker' import {BlueskyVideoView} from '@bsky.app/video' import {type CompressedVideo} from '#/lib/media/video/types' -import {clamp} from '#/lib/numbers' import {useAutoplayDisabled} from '#/state/preferences' import {ExternalEmbedRemoveBtn} from '#/view/com/composer/ExternalEmbedRemoveBtn' -import {atoms as a, useTheme} from '#/alf' +import {atoms as a} from '#/alf' +import {ConstrainedImage} from '#/components/images/AutoSizedImage' import {PlayButtonIcon} from '#/components/video/PlayButtonIcon' import {VideoTranscodeBackdrop} from './VideoTranscodeBackdrop' @@ -23,58 +23,63 @@ export function VideoPreview({ isActivePost: boolean clear: () => void }) { - const t = useTheme() const playerRef = useRef(null) const autoplayDisabled = useAutoplayDisabled() - let aspectRatio = asset.width / asset.height - if (isNaN(aspectRatio)) { - aspectRatio = 16 / 9 + let aspectRatio: number | undefined + if (asset.width && asset.height) { + const raw = asset.width / asset.height + if (!Number.isNaN(raw)) { + aspectRatio = raw + } } - aspectRatio = clamp(aspectRatio, 1 / 1, 3 / 1) + let constrained: number | undefined + if (aspectRatio !== undefined) { + const ratio = 1 / 2 // max of 1:2 ratio in feeds + constrained = Math.max(aspectRatio, ratio) + } return ( - - - - - {isActivePost && ( - <> - {video.mimeType === 'image/gif' ? ( - - ) : ( - + + + + + + + {isActivePost && ( + <> + {video.mimeType === 'image/gif' ? ( + + ) : ( + + )} + + )} + + {autoplayDisabled && ( + + + )} - - )} - - {autoplayDisabled && ( - - - )} + ) } diff --git a/src/view/com/composer/videos/VideoPreview.web.tsx b/src/view/com/composer/videos/VideoPreview.web.tsx index e23733e0c6..77c50dc7d1 100644 --- a/src/view/com/composer/videos/VideoPreview.web.tsx +++ b/src/view/com/composer/videos/VideoPreview.web.tsx @@ -4,22 +4,21 @@ import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' import {type CompressedVideo} from '#/lib/media/video/types' -import {clamp} from '#/lib/numbers' import {useAutoplayDisabled} from '#/state/preferences' import {ExternalEmbedRemoveBtn} from '#/view/com/composer/ExternalEmbedRemoveBtn' import {atoms as a} from '#/alf' +import {ConstrainedImage} from '#/components/images/AutoSizedImage' import * as Toast from '#/components/Toast' import {PlayButtonIcon} from '#/components/video/PlayButtonIcon' export function VideoPreview({ asset, video, - clear, }: { asset: ImagePickerAsset video: CompressedVideo - + isActivePost: boolean clear: () => void }) { const {_} = useLingui() @@ -27,56 +26,65 @@ export function VideoPreview({ // it's not possible using an img tag -sfn const autoplayDisabled = useAutoplayDisabled() - let aspectRatio = asset.width / asset.height - - if (isNaN(aspectRatio)) { - aspectRatio = 16 / 9 + let aspectRatio: number | undefined + if (asset.width && asset.height) { + const raw = asset.width / asset.height + if (!Number.isNaN(raw)) { + aspectRatio = raw + } } - aspectRatio = clamp(aspectRatio, 1 / 1, 3 / 1) + let constrained: number | undefined + if (aspectRatio !== undefined) { + const ratio = 1 / 2 // max of 1:2 ratio in feeds + constrained = Math.max(aspectRatio, ratio) + } return ( - - - {video.mimeType === 'image/gif' ? ( - GIF - ) : ( - <> -