Skip to content

Commit 014ef95

Browse files
authored
fix: Vimeo and youtube inline option fix (#5017)
Closes #5016 ## Description Since we are lazily initializing the player and using autoplay, players won't request full screen, so we need to request the fullscreen ourselves. 1. inline is now false by default 2. only for mobile/touch, custom logic checks if the device has touch or has resolution lower than 1024px ## Steps for reproduction 1. add vimeo component 2. put a video url, e.g. https://vimeo.com/1062544169 3. publish 4. play on a touch device or just a resolution smaller than 1024 5. see it goes full screen 6. repeaat the same with youtube ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 35d0d7c commit 014ef95

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

packages/sdk-components-react/src/vimeo.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
useContext,
1515
createContext,
1616
type ContextType,
17+
useRef,
1718
} from "react";
1819
import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime";
1920

@@ -246,11 +247,20 @@ const EmptyState = () => {
246247
);
247248
};
248249

250+
export const requestFullscreen = (element: HTMLIFrameElement) => {
251+
const isTouchDevice = "ontouchstart" in window;
252+
// Allows it to work on small screens on desktop too and makes it easy to test.
253+
const isMobileResolution = window.matchMedia("(max-width: 1024px)").matches;
254+
if (isMobileResolution || isTouchDevice) {
255+
element.requestFullscreen();
256+
}
257+
};
258+
249259
type PlayerStatus = "initial" | "loading" | "ready";
250260

251261
type PlayerProps = Pick<
252262
VimeoOptions,
253-
"loading" | "autoplay" | "showPreview"
263+
"loading" | "autoplay" | "showPreview" | "playsinline"
254264
> & {
255265
videoUrl: string;
256266
title: string | undefined;
@@ -270,10 +280,12 @@ const Player = ({
270280
autoplay,
271281
renderer,
272282
showPreview,
283+
playsinline,
273284
onStatusChange,
274285
onPreviewImageUrlChange,
275286
}: PlayerProps) => {
276287
const [opacity, setOpacity] = useState(0);
288+
const ref = useRef<HTMLIFrameElement>(null);
277289

278290
useEffect(() => {
279291
if (autoplay && renderer !== "canvas" && status === "initial") {
@@ -312,6 +324,7 @@ const Player = ({
312324

313325
return (
314326
<iframe
327+
ref={ref}
315328
title={title}
316329
src={videoUrl}
317330
loading={loading}
@@ -328,6 +341,9 @@ const Player = ({
328341
onLoad={() => {
329342
onStatusChange("ready");
330343
setOpacity(1);
344+
if (ref.current && !playsinline && !autoplay) {
345+
requestFullscreen(ref.current);
346+
}
331347
}}
332348
/>
333349
);
@@ -369,7 +385,7 @@ export const Vimeo = forwardRef<Ref, Props>(
369385
loop = false,
370386
muted = false,
371387
pip = false,
372-
playsinline = true,
388+
playsinline = false,
373389
showPortrait = true,
374390
quality = "auto",
375391
responsive = true,
@@ -440,6 +456,7 @@ export const Vimeo = forwardRef<Ref, Props>(
440456
<Player
441457
title={rest.title}
442458
autoplay={autoplay}
459+
playsinline={playsinline}
443460
videoUrl={videoUrl}
444461
previewImageUrl={previewImageUrl}
445462
loading={loading}

packages/sdk-components-react/src/vimeo.ws.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const initialProps: Array<keyof ComponentProps<typeof Vimeo>> = [
4242
"showTitle",
4343
"showControls",
4444
"controlsColor",
45+
"playsinline",
4546
];
4647

4748
export const propsMeta: WsComponentPropsMeta = {

packages/sdk-components-react/src/youtube.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import {
66
type ComponentProps,
77
useContext,
88
type ContextType,
9+
useRef,
910
} from "react";
1011
import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime";
11-
import { VimeoContext } from "./vimeo";
12+
import { VimeoContext, requestFullscreen } from "./vimeo";
1213

1314
/**
1415
* Options for configuring the YouTube player parameters.
@@ -362,7 +363,7 @@ const EmptyState = () => {
362363

363364
type PlayerProps = Pick<
364365
YouTubePlayerOptions,
365-
"loading" | "autoplay" | "showPreview"
366+
"loading" | "autoplay" | "showPreview" | "inline"
366367
> & {
367368
videoUrl: string;
368369
title: string | undefined;
@@ -380,12 +381,14 @@ const Player = ({
380381
videoUrl,
381382
previewImageUrl,
382383
autoplay,
384+
inline,
383385
renderer,
384386
showPreview,
385387
onStatusChange,
386388
onPreviewImageUrlChange,
387389
}: PlayerProps) => {
388390
const [opacity, setOpacity] = useState(0);
391+
const ref = useRef<HTMLIFrameElement>(null);
389392

390393
useEffect(() => {
391394
if (autoplay && renderer !== "canvas" && status === "initial") {
@@ -417,6 +420,7 @@ const Player = ({
417420

418421
return (
419422
<iframe
423+
ref={ref}
420424
title={title}
421425
src={videoUrl}
422426
loading={loading}
@@ -433,6 +437,9 @@ const Player = ({
433437
onLoad={() => {
434438
onStatusChange("ready");
435439
setOpacity(1);
440+
if (!inline && !autoplay && ref.current) {
441+
requestFullscreen(ref.current);
442+
}
436443
}}
437444
/>
438445
);
@@ -463,6 +470,7 @@ export const YouTube = forwardRef<Ref, Props>(
463470
showPreview,
464471
children,
465472
privacyEnhancedMode,
473+
inline = false,
466474
...rest
467475
},
468476
ref
@@ -478,6 +486,7 @@ export const YouTube = forwardRef<Ref, Props>(
478486
const videoUrl = getVideoUrl(
479487
{
480488
...rest,
489+
inline,
481490
url,
482491
autoplay: true,
483492
},
@@ -508,6 +517,7 @@ export const YouTube = forwardRef<Ref, Props>(
508517
videoUrl={videoUrl}
509518
previewImageUrl={previewImageUrl}
510519
loading={loading}
520+
inline={inline}
511521
showPreview={showPreview}
512522
renderer={renderer}
513523
status={status}

0 commit comments

Comments
 (0)