Browse Source

fix(android): Allow user to rotate fullscreen video (Android X) (#816)

* Allow user to rotate fullscreen video on Android

* Update RNCWebViewManager.java

* Update RNCWebViewManager.java
Akeem McLennon 4 years ago
parent
commit
1ea05d3115

+ 6
- 1
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java View File

@@ -5,6 +5,7 @@ import android.annotation.TargetApi;
5 5
 import android.app.DownloadManager;
6 6
 import android.content.Context;
7 7
 import android.content.Intent;
8
+import android.content.pm.ActivityInfo;
8 9
 import android.content.pm.PackageManager;
9 10
 import android.graphics.Bitmap;
10 11
 import android.graphics.Color;
@@ -589,6 +590,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
589 590
 
590 591
   protected void setupWebChromeClient(ReactContext reactContext, WebView webView) {
591 592
     if (mAllowsFullscreenVideo) {
593
+      int initialRequestedOrientation = reactContext.getCurrentActivity().getRequestedOrientation();
592 594
       mWebChromeClient = new RNCWebChromeClient(reactContext, webView) {
593 595
         @Override
594 596
         public void onShowCustomView(View view, CustomViewCallback callback) {
@@ -600,6 +602,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
600 602
           mVideoView = view;
601 603
           mCustomViewCallback = callback;
602 604
 
605
+          mReactContext.getCurrentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
606
+
603 607
           if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
604 608
             mVideoView.setSystemUiVisibility(FULLSCREEN_SYSTEM_UI_VISIBILITY);
605 609
             mReactContext.getCurrentActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
@@ -630,6 +634,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
630 634
           if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
631 635
             mReactContext.getCurrentActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
632 636
           }
637
+          mReactContext.getCurrentActivity().setRequestedOrientation(initialRequestedOrientation);
633 638
 
634 639
           mReactContext.removeLifecycleEventListener(this);
635 640
         }
@@ -1059,4 +1064,4 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
1059 1064
       }
1060 1065
     }
1061 1066
   }
1062
-}
1067
+}