/**
 * 通用 webview 封装
 */
import React from 'react';
import { WebView } from 'react-native-webview';

interface Props {
	uri: any;
	onLoadEndHandle?: () => void;
	handleWebViewNavigationStateChange?: (newNavState: { url: any }) => void;
	onMessageHandle?: (e: any) => void;
	refHandle?: (r: any) => any;
}
export const DenetWebview = (props: Props) => {
	return (
		<WebView
			applicationNameForUserAgent={'denet/1.1.0'}
			mediaCapturePermissionGrantType={'grant'}
			setSupportMultipleWindows={false}
			javaScriptEnabled={true}
			startInLoadingState={true}
			originWhitelist={['*']}
			cacheEnabled={false}
			javaScriptCanOpenWindowsAutomatically={true}
			allowUniversalAccessFromFileURLs={true}
			allowFileAccessFromFileURLs={true}
			onLoadEnd={props.onLoadEndHandle}
			ref={props.refHandle}
			onMessage={props.onMessageHandle}
			onNavigationStateChange={props.handleWebViewNavigationStateChange}
			source={{
				uri: props.uri,
			}}
		/>
	);
};
