Browse Source

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

Akeem McLennon 5 years ago
parent
commit
d6f90389fc

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