Skip to content

Commit

Permalink
Use new Bridget fullscreen methods
Browse files Browse the repository at this point in the history
  • Loading branch information
arelra committed Oct 1, 2024
1 parent e805cc5 commit a9667ae
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion dotcom-rendering/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@emotion/server": "11.11.0",
"@guardian/ab-core": "8.0.0",
"@guardian/braze-components": "20.1.0",
"@guardian/bridget": "7.0.0",
"@guardian/bridget": "0.0.0-2024-09-26-snapshot-1",
"@guardian/browserslist-config": "6.1.0",
"@guardian/cdk": "50.13.0",
"@guardian/commercial": "21.0.3",
Expand Down
23 changes: 19 additions & 4 deletions dotcom-rendering/src/components/YoutubeAtom/YoutubeAtomPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
useState,
} from 'react';
import { getVideoClient } from '../../lib/bridgetApi';
import { getZIndex } from '../../lib/getZIndex';
import { getAuthStatus } from '../../lib/identity';
import type { RenderingTarget } from '../../types/renderingTarget';
import type { google } from './ima';
Expand Down Expand Up @@ -84,6 +85,7 @@ const fullscreenStyles = (id: string) => css`
left: 0;
width: 100vw;
height: 100vh;
z-index: ${getZIndex('youTubeFullscreen')};
}
`;

Expand Down Expand Up @@ -412,6 +414,8 @@ export const YoutubeAtomPlayer = ({

const [playerReady, setPlayerReady] = useState<boolean>(false);
const [isFullscreen, setIsFullscreen] = useState<boolean>(false);
const [applyFullscreenStyles, setApplyFullscreenStyles] =
useState<boolean>(false);
const playerReadyCallback = useCallback(() => setPlayerReady(true), []);
const playerListeners = useRef<PlayerListeners>([]);
/**
Expand Down Expand Up @@ -657,11 +661,22 @@ export const YoutubeAtomPlayer = ({
};
}, []);

/**
* For apps rendered articles that return true for `webFullscreen` the web layer
* needs to handle the application of fullscreen styles and inform the native
* layer of the fullscreen state.
*
* This is only for the YouTube player in Android web views which does not support fullscreen
*/
useEffect(() => {
if (renderingTarget === 'Apps') {
console.log('fullscreen', isFullscreen);
// For Android only, iOS will stub the method
// void getVideoClient().fullscreen(isFullscreen);
const videoClient = getVideoClient();
void videoClient.webFullscreen().then((webFullscreen) => {
if (webFullscreen) {
void videoClient.setFullscreen(isFullscreen);
setApplyFullscreenStyles(isFullscreen);
}
});
}
}, [isFullscreen, renderingTarget]);

Expand All @@ -670,7 +685,7 @@ export const YoutubeAtomPlayer = ({
*/
return (
<>
{isFullscreen && <Global styles={fullscreenStyles(id)} />}
{applyFullscreenStyles && <Global styles={fullscreenStyles(id)} />}
<div
id={id}
data-testid={id}
Expand Down
1 change: 1 addition & 0 deletions dotcom-rendering/src/lib/getZIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
const indices = [
// Modals will go here at the top
'lightbox',
'youTubeFullscreen',

// Sticky video and button need to be above everything
'sticky-video-button',
Expand Down
46 changes: 25 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a9667ae

Please sign in to comment.