-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Hide video pillarboxing on web when the card fits #11118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vineyardbovines
wants to merge
1
commit into
main
Choose a base branch
from
app-2100
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,13 @@ import * as VideoFallback from './VideoEmbedInner/VideoFallback' | |
|
|
||
| const noop = () => {} | ||
|
|
||
| /** | ||
| * Minimum card width for the overlay controls (play, time, CC, volume, | ||
| * fullscreen) to fit without crowding. Narrower cards fall back to the | ||
| * full-width pillarbox. | ||
| */ | ||
| const MIN_CARD_WIDTH = 280 | ||
|
|
||
| export function VideoEmbed({embed}: {embed: AppBskyEmbedVideo.View}) { | ||
| const t = useTheme() | ||
| const ref = useRef<HTMLDivElement>(null) | ||
|
|
@@ -89,20 +96,58 @@ export function VideoEmbed({embed}: {embed: AppBskyEmbedVideo.View}) { | |
| constrained = Math.max(aspectRatio, ratio) | ||
| } | ||
|
|
||
| const [containerWidth, setContainerWidth] = useState(0) | ||
|
|
||
| /* | ||
| * Portrait videos render at their own ratio instead of pillarboxed, but | ||
| * only when the resulting card fits the overlay controls. Videos taller | ||
| * than 1:2 would still show bars inside a ratio-fit card, and an unknown | ||
| * ratio can't be fit, so both keep the full-width pillarbox - a narrow | ||
| * card with black slices down the sides looks broken (see #9371). | ||
| */ | ||
| const cardWidth = containerWidth * Math.min(aspectRatio ?? 1, 1) | ||
| const fullBleed = | ||
| aspectRatio === undefined || | ||
| aspectRatio < 1 / 2 || | ||
| cardWidth < MIN_CARD_WIDTH | ||
|
|
||
| const contents = ( | ||
| <div | ||
| ref={ref} | ||
| style={{ | ||
| display: 'flex', | ||
| flex: 1, | ||
| cursor: 'default', | ||
| position: 'relative', | ||
| backgroundColor: t.palette.black, | ||
| backgroundImage: `url(${embed.thumbnail})`, | ||
| backgroundSize: 'contain', | ||
| backgroundPosition: 'center', | ||
| backgroundRepeat: 'no-repeat', | ||
| }} | ||
| onClick={evt => evt.stopPropagation()}> | ||
| {/* blurred backdrop fills the bars when the video is boxed */} | ||
| {fullBleed && embed.thumbnail && ( | ||
| <div | ||
| aria-hidden | ||
| style={{ | ||
| position: 'absolute', | ||
| inset: 0, | ||
| backgroundImage: `url(${embed.thumbnail})`, | ||
| backgroundSize: 'cover', | ||
| backgroundPosition: 'center', | ||
| filter: 'blur(32px)', | ||
| // hide the transparent fade the blur creates at the edges | ||
| transform: 'scale(1.2)', | ||
| }} | ||
| /> | ||
| )} | ||
|
Comment on lines
+126
to
+140
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love this, looks great imo |
||
| <div | ||
| style={{ | ||
| position: 'absolute', | ||
| inset: 0, | ||
| backgroundImage: `url(${embed.thumbnail})`, | ||
| backgroundSize: 'contain', | ||
| backgroundPosition: 'center', | ||
| backgroundRepeat: 'no-repeat', | ||
| }} | ||
| /> | ||
| <ErrorBoundary renderError={renderError} key={key}> | ||
| <OnlyNearScreen> | ||
| <VideoEmbedInnerWeb | ||
|
|
@@ -118,12 +163,14 @@ export function VideoEmbed({embed}: {embed: AppBskyEmbedVideo.View}) { | |
| ) | ||
|
|
||
| return ( | ||
| <View style={[a.pt_xs]}> | ||
| <View | ||
| style={[a.pt_xs]} | ||
| onLayout={e => setContainerWidth(e.nativeEvent.layout.width)}> | ||
| <ViewportObserver | ||
| sendPosition={isGif ? noop : sendPosition} | ||
| isAnyViewActive={currentActiveView !== null}> | ||
| <ConstrainedImage | ||
| fullBleed | ||
| fullBleed={fullBleed} | ||
| aspectRatio={constrained || 1} | ||
| // slightly smaller max height than images | ||
| // images use 16 / 9, for reference | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nit, but can we use the aspect ratio to calculate width (constrained by a max height, which I think we do on native) so that we don't need to do a FOUC? Could use a heuristic min window width and fall back to letterbox in those cases.