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