@@ -97,28 +97,61 @@ const fullscreenStyles = (id: string) => css`
9797` ;
9898
9999/**
100- * We set the external_fullscreen configuration property depending on
101- * whether the native layer needs to delegate fullscreen styling to
102- * the webview.
100+ * The external_fullscreen configuration property determines
101+ * if the YouTube player controls fullscreen behaviour.
103102 *
104- * This is true for Android but not for iOS which handles fullscreen
105- * natively. The Bridget method setFullscreen returns a value to
106- * indicate this requirement. We use it here by passing a value of
107- * false for fullscreen when intialising the player to determine
108- * the value we need to pass for external_fullscreen.
103+ * On Android webviews, the YouTube player does not implement
104+ * fullscreen so we need to set external_fullscreen to true and
105+ * apply custom styling to mimic fullscreen behaviour.
109106 *
110- * external_fullscreen is allowed listed on our CODE and PROD domains.
107+ * The Bridget method setFullscreen returns a boolean value
108+ * to indicate if the YouTubeAtom should apply fullscreen
109+ * styling itself.
110+ *
111+ * By invoking setFullscreen(false) when intialising the player
112+ * and checking the return value we can determine if the player
113+ * requires external_fullscreen to be set.
114+ *
115+ * This will return true for Android but false for iOS which
116+ * handles fullscreen natively.
117+ *
118+ * We then add a listener for fullscreen toggles so we can
119+ * a) apply or remove fullscreen styles
120+ * b) invoke the Bridget method setFullscreen(true|false) so
121+ * the native layer can also toggle fullscreen
122+ *
123+ * external_fullscreen is allow-listed by YouTube
124+ * on only our CODE and PROD domains.
111125 */
112126const setAppsConfiguration = async (
113127 basePlayerConfiguration : YouTubePlayerArgs ,
114128 renderingTarget : RenderingTarget ,
115- ) => {
129+ videoId : string ,
130+ setIsFullscreen : ( value : React . SetStateAction < boolean > ) => void ,
131+ ) : Promise < YouTubePlayerArgs > => {
116132 if ( renderingTarget === 'Apps' ) {
117133 const requiresWebFullscreen =
118134 await getVideoClient ( ) . setFullscreen ( false ) ;
119135 const updatedConfiguration = {
120136 ...basePlayerConfiguration ,
121- external_fullscreen : requiresWebFullscreen ? 1 : 0 ,
137+ youtubeOptions : {
138+ ...basePlayerConfiguration . youtubeOptions ,
139+ playerVars : {
140+ ...basePlayerConfiguration . youtubeOptions . playerVars ,
141+ external_fullscreen : requiresWebFullscreen ? 1 : 0 ,
142+ fs : 1 ,
143+ } ,
144+ events : {
145+ ...basePlayerConfiguration . youtubeOptions . events ,
146+ onFullscreenToggled : ( ) => {
147+ log ( 'dotcom' , {
148+ from : 'YoutubeAtomPlayer fullscreen toggled' ,
149+ videoId,
150+ } ) ;
151+ setIsFullscreen ( ( prev ) => ! prev ) ;
152+ } ,
153+ } ,
154+ } ,
122155 } ;
123156 return updatedConfiguration ;
124157 }
@@ -514,28 +547,22 @@ export const YoutubeAtomPlayer = ({
514547 } ,
515548 events : {
516549 onStateChange : onStateChangeListener ,
517- onFullscreenToggled : ( ) => {
518- if ( renderingTarget === 'Apps' ) {
519- log ( 'dotcom' , {
520- from : 'YoutubeAtomPlayer fullscreen' ,
521- videoId,
522- } ) ;
523- setIsFullscreen ( ( prev ) => ! prev ) ;
524- }
525- } ,
526550 } ,
527551 } ,
528552 onReadyListener,
529553 enableIma : enableAds ,
530554 } ;
531555
532- const basePlayerConfigurationWithApps = setAppsConfiguration (
533- basePlayerConfiguration ,
534- renderingTarget ,
535- ) ;
556+ const basePlayerConfigurationWithAppsPromise =
557+ setAppsConfiguration (
558+ basePlayerConfiguration ,
559+ renderingTarget ,
560+ videoId ,
561+ setIsFullscreen ,
562+ ) ;
536563
537564 void Promise . allSettled ( [
538- basePlayerConfigurationWithApps ,
565+ basePlayerConfigurationWithAppsPromise ,
539566 isSignedIn ( ) ,
540567 ] ) . then ( ( [ playerConfigurationResult , isSignedInResult ] ) => {
541568 const playerConfiguration =
0 commit comments