Browse Source

Allow user to rotate fullscreen video on Android (No Android X) (#815)

Akeem McLennon 4 years ago
parent
commit
d6f90389fc

+ 4
- 0
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.graphics.Bitmap;
9 10
 import android.graphics.Color;
10 11
 import android.net.Uri;
@@ -533,6 +534,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
533 534
 
534 535
   protected void setupWebChromeClient(ReactContext reactContext, WebView webView) {
535 536
     if (mAllowsFullscreenVideo) {
537
+      int initialRequestedOrientation = reactContext.getCurrentActivity().getRequestedOrientation();
536 538
       mWebChromeClient = new RNCWebChromeClient(reactContext, webView) {
537 539
         @Override
538 540
         public void onShowCustomView(View view, CustomViewCallback callback) {
@@ -544,6 +546,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
544 546
           mVideoView = view;
545 547
           mCustomViewCallback = callback;
546 548
 
549
+          mReactContext.getCurrentActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
547 550
           if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
548 551
             mVideoView.setSystemUiVisibility(FULLSCREEN_SYSTEM_UI_VISIBILITY);
549 552
             mReactContext.getCurrentActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
@@ -574,6 +577,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
574 577
           if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
575 578
             mReactContext.getCurrentActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
576 579
           }
580
+          mReactContext.getCurrentActivity().setRequestedOrientation(initialRequestedOrientation);
577 581
 
578 582
           mReactContext.removeLifecycleEventListener(this);
579 583
         }