From 4f469ee9aab9f6db5f9905c6276dc604d231cd5d Mon Sep 17 00:00:00 2001 From: Cristiano Coelho <48869228+cristianoccazinsp@users.noreply.github.com> Date: Thu, 11 Feb 2021 02:09:09 -0300 Subject: [PATCH] fix(android): Fix full=screen video when in modals (#1748 by @cristianoccazinsp) Co-authored-by: Cristiano Coelho Co-authored-by: Thibault Malbranche --- .../webview/RNCWebViewManager.java | 45 +++++++++++++++---- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java index 2190ae7..952e46e 100644 --- a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +++ b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java @@ -734,8 +734,25 @@ public class RNCWebViewManager extends SimpleViewManager { } mVideoView.setBackgroundColor(Color.BLACK); - getRootView().addView(mVideoView, FULLSCREEN_LAYOUT_PARAMS); - mWebView.setVisibility(View.GONE); + + // since RN's Modals interfere with the View hierarchy + // we will decide which View to Hide if the hierarchy + // does not match (i.e., the webview is within a Modal) + // NOTE: We could use mWebView.getRootView() instead of getRootView() + // but that breaks the Modal's styles and layout, so we need this to render + // in the main View hierarchy regardless. + ViewGroup rootView = getRootView(); + rootView.addView(mVideoView, FULLSCREEN_LAYOUT_PARAMS); + + // Different root views, we are in a Modal + if(rootView.getRootView() != mWebView.getRootView()){ + mWebView.getRootView().setVisibility(View.GONE); + } + + // Same view hierarchy (no Modal), just hide the webview then + else{ + mWebView.setVisibility(View.GONE); + } mReactContext.addLifecycleEventListener(this); } @@ -746,18 +763,28 @@ public class RNCWebViewManager extends SimpleViewManager { return; } - mVideoView.setVisibility(View.GONE); - getRootView().removeView(mVideoView); + // same logic as above + ViewGroup rootView = getRootView(); + + if(rootView.getRootView() != mWebView.getRootView()){ + mWebView.getRootView().setVisibility(View.VISIBLE); + } + + // Same view hierarchy (no Modal) + else{ + mWebView.setVisibility(View.VISIBLE); + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + mReactContext.getCurrentActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + } + + rootView.removeView(mVideoView); mCustomViewCallback.onCustomViewHidden(); mVideoView = null; mCustomViewCallback = null; - mWebView.setVisibility(View.VISIBLE); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - mReactContext.getCurrentActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); - } mReactContext.getCurrentActivity().setRequestedOrientation(initialRequestedOrientation); mReactContext.removeLifecycleEventListener(this);