当前位置: 动力学知识库 > 问答 > 编程问答 >

React Native Android WebView video fullscreen (with rotation)

问题描述:

I've currently implemented a native module for RN in order to be able to play html video inside a webview in fullscreen.

To do that, I simply extend ReactWebViewManager to set a custom setWebChromeClient to the React Native Webview.

public class InTeachWebviewModule extends ReactWebViewManager {

@Override

public String getName() {

return "RCTInTeachWebview";

}

@Override

protected WebView createViewInstance(ThemedReactContext reactContext) {

WebView root = super.createViewInstance(reactContext);

root.setWebChromeClient(new VideoWebChromeClient(reactContext.getCurrentActivity(), root));

return root;

}

}

And I've a simple CustomChromeClient:

public VideoWebChromeClient(Activity activity, WebView webView) {

mWebView = webView;

mActivity = activity;

}

@Override

public void onShowCustomView(View view, CustomViewCallback callback) {

if (mVideoView != null) {

callback.onCustomViewHidden();

return;

}

mVideoView = view;

mCustomViewCallback = callback;

view.setBackgroundColor(Color.BLACK);

getRootView().addView(view, FULLSCREEN_LAYOUT_PARAMS);

((View)mWebView.getRootView()).setVisibility(View.GONE);

}

@Override

public void onHideCustomView() {

if (mVideoView == null) {

return;

}

((View)mWebView.getRootView()).setVisibility(View.VISIBLE);

mVideoView.setVisibility(View.GONE);

getRootView().removeView(mVideoView);

mVideoView = null;

mCustomViewCallback.onCustomViewHidden();

}

It works great if there is no screen rotation, but as soon as I call mActivity.setRequestedOrientation() the onHideCustomView is called... It seems that calling setRequestedOrientation() refresh the all webview even if in my AndroidManifest I've

<activity

android:name=".MainActivity"

android:label="@string/app_name"

android:theme="@style/SplashTheme"

android:configChanges="orientation|screenSize">

Is there a way to avoid the refresh? Or an other way to rotate the screen? Notice that my app is portrait only except that case.

分享给朋友:
您可能感兴趣的文章:
随机阅读: