webview.tsx 969 B

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * 通用 webview 封装
  3. */
  4. import React from 'react';
  5. import { WebView } from 'react-native-webview';
  6. interface Props {
  7. uri: any;
  8. onLoadEndHandle?: () => void;
  9. handleWebViewNavigationStateChange?: (newNavState: { url: any }) => void;
  10. onMessageHandle?: (e: any) => void;
  11. refHandle?: (r: any) => any;
  12. }
  13. export const DenetWebview = (props: Props) => {
  14. return (
  15. <WebView
  16. applicationNameForUserAgent={'denet/1.1.0'}
  17. mediaCapturePermissionGrantType={'grant'}
  18. setSupportMultipleWindows={false}
  19. javaScriptEnabled={true}
  20. startInLoadingState={true}
  21. originWhitelist={['*']}
  22. cacheEnabled={false}
  23. javaScriptCanOpenWindowsAutomatically={true}
  24. allowUniversalAccessFromFileURLs={true}
  25. allowFileAccessFromFileURLs={true}
  26. onLoadEnd={props.onLoadEndHandle}
  27. ref={props.refHandle}
  28. onMessage={props.onMessageHandle}
  29. onNavigationStateChange={props.handleWebViewNavigationStateChange}
  30. source={{
  31. uri: props.uri,
  32. }}
  33. />
  34. );
  35. };