@@ -243,6 +243,55 @@ public void onProgressChanged(WebView view, int progress) {
243243 args .put ("progress" , progress / 100.0 );
244244 FlutterWebviewPlugin .channel .invokeMethod ("onProgressChanged" , args );
245245 }
246+
247+ // Allow switching to fullscreen e.g when playing a video
248+
249+ private View customView ;
250+ private CustomViewCallback customViewCallback ;
251+
252+ @ Override
253+ public void onShowCustomView (View view , int requestedOrientation , CustomViewCallback callback ) {
254+ onShowCustomView (view , callback );
255+ }
256+
257+ @ Override
258+ public void onShowCustomView (View view , CustomViewCallback callback ) {
259+ // if a view already exists then immediately terminate the new one
260+ if (customView != null ) {
261+ callback .onCustomViewHidden ();
262+ return ;
263+ }
264+
265+ // add custom view to container and save reference
266+ customView = view ;
267+ customViewCallback = callback ;
268+
269+ FrameLayout rootView = (FrameLayout )webView .getRootView ();
270+ rootView .addView (customView );
271+
272+ // hide webview and show custom view
273+ customView .setVisibility (View .VISIBLE );
274+ FrameLayout contentView = (FrameLayout )rootView .findViewById (android .R .id .content );
275+ contentView .setVisibility (View .GONE );
276+ }
277+
278+ @ Override
279+ public void onHideCustomView () {
280+ super .onHideCustomView ();
281+ if (customView == null )
282+ return ;
283+
284+ // Hide the custom view and show Webview
285+ FrameLayout rootView = (FrameLayout )webView .getRootView ();
286+ FrameLayout contentView = (FrameLayout )rootView .findViewById (android .R .id .content );
287+ contentView .setVisibility (View .VISIBLE );
288+ customView .setVisibility (View .GONE );
289+
290+ // Remove the custom view from its container and clear reference
291+ rootView .removeView (customView );
292+ customViewCallback .onCustomViewHidden ();
293+ customView = null ;
294+ }
246295 });
247296 }
248297
0 commit comments