@@ -97,28 +97,57 @@ 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+ * We set the external_fullscreen configuration property to
101+ * control whether the YouTube player enables it's default
102+ * fullscreen behaviour .
103103 *
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.
104+ * On Android webviews, the YouTube player does not implement
105+ * fullscreen so we need to set external_fullscreen to true and
106+ * apply custom styling to mimic fullscreen behaviour.
109107 *
110- * external_fullscreen is allowed listed on our CODE and PROD domains.
108+ * The Bridget method setFullscreen returns a boolean value
109+ * to indicate if the YouTubeAtom should apply fullscreen
110+ * styling itself.
111+ *
112+ * This will return true for Android but not for iOS which
113+ * handles fullscreen natively.
114+ *
115+ * By invoking setFullscreen(false) when intialising the player
116+ * and checking the return value we can determine if the player
117+ * requires the external_fullscreen configuration to be set.
118+ *
119+ * external_fullscreen is allow-listed by YouTube
120+ * on only our CODE and PROD domains.
111121 */
112122const setAppsConfiguration = async (
113123 basePlayerConfiguration : YouTubePlayerArgs ,
114124 renderingTarget : RenderingTarget ,
115- ) => {
125+ videoId : string ,
126+ setIsFullscreen : ( value : React . SetStateAction < boolean > ) => void ,
127+ ) : Promise < YouTubePlayerArgs > => {
116128 if ( renderingTarget === 'Apps' ) {
117129 const requiresWebFullscreen =
118130 await getVideoClient ( ) . setFullscreen ( false ) ;
119131 const updatedConfiguration = {
120132 ...basePlayerConfiguration ,
121- external_fullscreen : requiresWebFullscreen ? 1 : 0 ,
133+ youtubeOptions : {
134+ ...basePlayerConfiguration . youtubeOptions ,
135+ playerVars : {
136+ ...basePlayerConfiguration . youtubeOptions . playerVars ,
137+ external_fullscreen : requiresWebFullscreen ? 1 : 0 ,
138+ fs : 1 ,
139+ } ,
140+ events : {
141+ ...basePlayerConfiguration . youtubeOptions . events ,
142+ onFullscreenToggled : ( ) => {
143+ log ( 'dotcom' , {
144+ from : 'YoutubeAtomPlayer fullscreen toggled' ,
145+ videoId,
146+ } ) ;
147+ setIsFullscreen ( ( prev ) => ! prev ) ;
148+ } ,
149+ } ,
150+ } ,
122151 } ;
123152 return updatedConfiguration ;
124153 }
@@ -514,28 +543,22 @@ export const YoutubeAtomPlayer = ({
514543 } ,
515544 events : {
516545 onStateChange : onStateChangeListener ,
517- onFullscreenToggled : ( ) => {
518- if ( renderingTarget === 'Apps' ) {
519- log ( 'dotcom' , {
520- from : 'YoutubeAtomPlayer fullscreen' ,
521- videoId,
522- } ) ;
523- setIsFullscreen ( ( prev ) => ! prev ) ;
524- }
525- } ,
526546 } ,
527547 } ,
528548 onReadyListener,
529549 enableIma : enableAds ,
530550 } ;
531551
532- const basePlayerConfigurationWithApps = setAppsConfiguration (
533- basePlayerConfiguration ,
534- renderingTarget ,
535- ) ;
552+ const basePlayerConfigurationWithAppsPromise =
553+ setAppsConfiguration (
554+ basePlayerConfiguration ,
555+ renderingTarget ,
556+ videoId ,
557+ setIsFullscreen ,
558+ ) ;
536559
537560 void Promise . allSettled ( [
538- basePlayerConfigurationWithApps ,
561+ basePlayerConfigurationWithAppsPromise ,
539562 isSignedIn ( ) ,
540563 ] ) . then ( ( [ playerConfigurationResult , isSignedInResult ] ) => {
541564 const playerConfiguration =
0 commit comments