@exodus/react-native-webview 11.26.1-exodus.1 → 11.26.1-exodus.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1249,7 +1249,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
1249
1249
  public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
1250
1250
 
1251
1251
  // Always deny
1252
- callback.invoke(origin, true, false);
1252
+ callback.invoke(origin, false, false);
1253
1253
 
1254
1254
  }
1255
1255
 
@@ -95,28 +95,6 @@ public class RNCWebViewModule extends ReactContextBaseJavaModule implements Acti
95
95
  }
96
96
  }
97
97
 
98
- private PermissionListener getWebviewFileDownloaderPermissionListener(String downloadingMessage, String lackPermissionToDownloadMessage) {
99
- return new PermissionListener() {
100
- @Override
101
- public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
102
- switch (requestCode) {
103
- case FILE_DOWNLOAD_PERMISSION_REQUEST: {
104
- // If request is cancelled, the result arrays are empty.
105
- if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
106
- if (downloadRequest != null) {
107
- downloadFile(downloadingMessage);
108
- }
109
- } else {
110
- Toast.makeText(getCurrentActivity().getApplicationContext(), lackPermissionToDownloadMessage, Toast.LENGTH_LONG).show();
111
- }
112
- return true;
113
- }
114
- }
115
- return false;
116
- }
117
- };
118
- }
119
-
120
98
  public RNCWebViewModule(ReactApplicationContext reactContext) {
121
99
  super(reactContext);
122
100
  reactContext.addActivityEventListener(this);
@@ -321,21 +299,6 @@ public class RNCWebViewModule extends ReactContextBaseJavaModule implements Acti
321
299
  Toast.makeText(getCurrentActivity().getApplicationContext(), downloadingMessage, Toast.LENGTH_LONG).show();
322
300
  }
323
301
 
324
- public boolean grantFileDownloaderPermissions(String downloadingMessage, String lackPermissionToDownloadMessage) {
325
- // Permission not required for Android Q and above
326
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
327
- return true;
328
- }
329
-
330
- boolean result = ContextCompat.checkSelfPermission(getCurrentActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
331
- if (!result && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
332
- PermissionAwareActivity activity = getPermissionAwareActivity();
333
- activity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, FILE_DOWNLOAD_PERMISSION_REQUEST, getWebviewFileDownloaderPermissionListener(downloadingMessage, lackPermissionToDownloadMessage));
334
- }
335
-
336
- return result;
337
- }
338
-
339
302
  protected boolean needsCameraPermission() {
340
303
  boolean needed = false;
341
304
 
@@ -1,16 +1,5 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
1
  import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
13
- import { Image, View, NativeModules, } from 'react-native';
2
+ import { View, NativeModules, } from 'react-native';
14
3
  import BatchedBridge from 'react-native/Libraries/BatchedBridge/BatchedBridge';
15
4
  // @ts-expect-error react-native doesn't have this type
16
5
  import codegenNativeCommandsUntyped from 'react-native/Libraries/Utilities/codegenNativeCommands';
@@ -18,33 +7,31 @@ import invariant from 'invariant';
18
7
  import RNCWebView from "./WebViewNativeComponent.android";
19
8
  import { defaultOriginWhitelist, defaultRenderError, defaultRenderLoading, useWebWiewLogic, } from './WebViewShared';
20
9
  import styles from './WebView.styles';
21
- var codegenNativeCommands = codegenNativeCommandsUntyped;
22
- var Commands = codegenNativeCommands({
23
- supportedCommands: ['goBack', 'goForward', 'reload', 'stopLoading', /* 'injectJavaScript', */ 'requestFocus', 'postMessage', 'clearFormData', 'clearCache', 'clearHistory', 'loadUrl']
10
+ const codegenNativeCommands = codegenNativeCommandsUntyped;
11
+ const Commands = codegenNativeCommands({
12
+ supportedCommands: ['goBack', 'goForward', 'reload', 'stopLoading', /* 'injectJavaScript', */ 'requestFocus', 'postMessage', 'clearFormData', 'clearCache', 'clearHistory', 'loadUrl'],
24
13
  });
25
- var resolveAssetSource = Image.resolveAssetSource;
26
14
  /**
27
15
  * A simple counter to uniquely identify WebView instances. Do not use this for anything else.
28
16
  */
29
- var uniqueRef = 0;
17
+ let uniqueRef = 0;
30
18
  /**
31
19
  * Harcoded default for security.
32
20
  */
33
- var allowFileAccessFromFileURLs = false;
34
- var allowUniversalAccessFromFileURLs = false;
35
- var injectedJavaScriptForMainFrameOnly = true;
36
- var injectedJavaScriptBeforeContentLoadedForMainFrameOnly = true;
37
- var mediaPlaybackRequiresUserAction = true;
21
+ const allowFileAccessFromFileURLs = false;
22
+ const allowUniversalAccessFromFileURLs = false;
23
+ const injectedJavaScriptForMainFrameOnly = true;
24
+ const injectedJavaScriptBeforeContentLoadedForMainFrameOnly = true;
25
+ const mediaPlaybackRequiresUserAction = true;
38
26
  // Android only
39
- var allowsFullscreenVideo = false;
40
- var allowFileAccess = false;
41
- var setSupportMultipleWindows = true;
42
- var mixedContentMode = 'never';
43
- var WebViewComponent = forwardRef(function (_a, ref) {
44
- var _b = _a.overScrollMode, overScrollMode = _b === void 0 ? 'always' : _b, _c = _a.javaScriptEnabled, javaScriptEnabled = _c === void 0 ? true : _c, _d = _a.thirdPartyCookiesEnabled, thirdPartyCookiesEnabled = _d === void 0 ? true : _d, _e = _a.scalesPageToFit, scalesPageToFit = _e === void 0 ? true : _e, _f = _a.saveFormDataDisabled, saveFormDataDisabled = _f === void 0 ? false : _f, _g = _a.cacheEnabled, cacheEnabled = _g === void 0 ? true : _g, _h = _a.androidHardwareAccelerationDisabled, androidHardwareAccelerationDisabled = _h === void 0 ? false : _h, _j = _a.androidLayerType, androidLayerType = _j === void 0 ? "none" : _j, _k = _a.originWhitelist, originWhitelist = _k === void 0 ? defaultOriginWhitelist : _k, _l = _a.setBuiltInZoomControls, setBuiltInZoomControls = _l === void 0 ? true : _l, _m = _a.setDisplayZoomControls, setDisplayZoomControls = _m === void 0 ? false : _m, _o = _a.nestedScrollEnabled, nestedScrollEnabled = _o === void 0 ? false : _o, startInLoadingState = _a.startInLoadingState, onNavigationStateChange = _a.onNavigationStateChange, onLoadStart = _a.onLoadStart, onError = _a.onError, onLoad = _a.onLoad, onLoadEnd = _a.onLoadEnd, onLoadProgress = _a.onLoadProgress, onHttpErrorProp = _a.onHttpError, onRenderProcessGoneProp = _a.onRenderProcessGone, onMessageProp = _a.onMessage, renderLoading = _a.renderLoading, renderError = _a.renderError, style = _a.style, containerStyle = _a.containerStyle, source = _a.source, onShouldStartLoadWithRequestProp = _a.onShouldStartLoadWithRequest, otherProps = __rest(_a, ["overScrollMode", "javaScriptEnabled", "thirdPartyCookiesEnabled", "scalesPageToFit", "saveFormDataDisabled", "cacheEnabled", "androidHardwareAccelerationDisabled", "androidLayerType", "originWhitelist", "setBuiltInZoomControls", "setDisplayZoomControls", "nestedScrollEnabled", "startInLoadingState", "onNavigationStateChange", "onLoadStart", "onError", "onLoad", "onLoadEnd", "onLoadProgress", "onHttpError", "onRenderProcessGone", "onMessage", "renderLoading", "renderError", "style", "containerStyle", "source", "onShouldStartLoadWithRequest"]);
45
- var messagingModuleName = useRef("WebViewMessageHandler".concat(uniqueRef += 1)).current;
46
- var webViewRef = useRef(null);
47
- var onShouldStartLoadWithRequestCallback = useCallback(function (shouldStart, url, lockIdentifier) {
27
+ const allowsFullscreenVideo = false;
28
+ const allowFileAccess = false;
29
+ const setSupportMultipleWindows = true;
30
+ const mixedContentMode = 'never';
31
+ const WebViewComponent = forwardRef(({ overScrollMode = 'always', javaScriptEnabled = true, thirdPartyCookiesEnabled = true, scalesPageToFit = true, saveFormDataDisabled = false, cacheEnabled = true, androidHardwareAccelerationDisabled = false, androidLayerType = "none", originWhitelist = defaultOriginWhitelist, setBuiltInZoomControls = true, setDisplayZoomControls = false, nestedScrollEnabled = false, startInLoadingState, onNavigationStateChange, onLoadStart, onError, onLoad, onLoadEnd, onLoadProgress, onHttpError: onHttpErrorProp, onRenderProcessGone: onRenderProcessGoneProp, onMessage: onMessageProp, renderLoading, renderError, style, containerStyle, source, onShouldStartLoadWithRequest: onShouldStartLoadWithRequestProp, ...otherProps }, ref) => {
32
+ const messagingModuleName = useRef(`WebViewMessageHandler${uniqueRef += 1}`).current;
33
+ const webViewRef = useRef(null);
34
+ const onShouldStartLoadWithRequestCallback = useCallback((shouldStart, url, lockIdentifier) => {
48
35
  if (lockIdentifier) {
49
36
  NativeModules.RNCWebView.onShouldStartLoadWithRequestCallback(shouldStart, lockIdentifier);
50
37
  }
@@ -52,44 +39,44 @@ var WebViewComponent = forwardRef(function (_a, ref) {
52
39
  Commands.loadUrl(webViewRef.current, url);
53
40
  }
54
41
  }, []);
55
- var _p = useWebWiewLogic({
56
- onNavigationStateChange: onNavigationStateChange,
57
- onLoad: onLoad,
58
- onError: onError,
59
- onHttpErrorProp: onHttpErrorProp,
60
- onLoadEnd: onLoadEnd,
61
- onLoadProgress: onLoadProgress,
62
- onLoadStart: onLoadStart,
63
- onRenderProcessGoneProp: onRenderProcessGoneProp,
64
- onMessageProp: onMessageProp,
65
- startInLoadingState: startInLoadingState,
66
- originWhitelist: originWhitelist,
67
- onShouldStartLoadWithRequestProp: onShouldStartLoadWithRequestProp,
68
- onShouldStartLoadWithRequestCallback: onShouldStartLoadWithRequestCallback
69
- }), onLoadingStart = _p.onLoadingStart, onShouldStartLoadWithRequest = _p.onShouldStartLoadWithRequest, onMessage = _p.onMessage, viewState = _p.viewState, setViewState = _p.setViewState, lastErrorEvent = _p.lastErrorEvent, onHttpError = _p.onHttpError, onLoadingError = _p.onLoadingError, onLoadingFinish = _p.onLoadingFinish, onLoadingProgress = _p.onLoadingProgress, onRenderProcessGone = _p.onRenderProcessGone;
70
- useImperativeHandle(ref, function () { return ({
71
- goForward: function () { return Commands.goForward(webViewRef.current); },
72
- goBack: function () { return Commands.goBack(webViewRef.current); },
73
- reload: function () {
42
+ const { onLoadingStart, onShouldStartLoadWithRequest, onMessage, viewState, setViewState, lastErrorEvent, onHttpError, onLoadingError, onLoadingFinish, onLoadingProgress, onRenderProcessGone } = useWebWiewLogic({
43
+ onNavigationStateChange,
44
+ onLoad,
45
+ onError,
46
+ onHttpErrorProp,
47
+ onLoadEnd,
48
+ onLoadProgress,
49
+ onLoadStart,
50
+ onRenderProcessGoneProp,
51
+ onMessageProp,
52
+ startInLoadingState,
53
+ originWhitelist,
54
+ onShouldStartLoadWithRequestProp,
55
+ onShouldStartLoadWithRequestCallback,
56
+ });
57
+ useImperativeHandle(ref, () => ({
58
+ goForward: () => Commands.goForward(webViewRef.current),
59
+ goBack: () => Commands.goBack(webViewRef.current),
60
+ reload: () => {
74
61
  setViewState('LOADING');
75
62
  Commands.reload(webViewRef.current);
76
63
  },
77
- stopLoading: function () { return Commands.stopLoading(webViewRef.current); },
78
- postMessage: function (data) { return Commands.postMessage(webViewRef.current, data); },
64
+ stopLoading: () => Commands.stopLoading(webViewRef.current),
65
+ postMessage: (data) => Commands.postMessage(webViewRef.current, data),
79
66
  // injectJavaScript: (data: string) => Commands.injectJavaScript(webViewRef.current, data),
80
- requestFocus: function () { return Commands.requestFocus(webViewRef.current); },
81
- clearFormData: function () { return Commands.clearFormData(webViewRef.current); },
82
- clearCache: function (includeDiskFiles) { return Commands.clearCache(webViewRef.current, includeDiskFiles); },
83
- clearHistory: function () { return Commands.clearHistory(webViewRef.current); }
84
- }); }, [setViewState, webViewRef]);
85
- var directEventCallbacks = useMemo(function () { return ({
86
- onShouldStartLoadWithRequest: onShouldStartLoadWithRequest,
87
- onMessage: onMessage
88
- }); }, [onMessage, onShouldStartLoadWithRequest]);
89
- useEffect(function () {
67
+ requestFocus: () => Commands.requestFocus(webViewRef.current),
68
+ clearFormData: () => Commands.clearFormData(webViewRef.current),
69
+ clearCache: (includeDiskFiles) => Commands.clearCache(webViewRef.current, includeDiskFiles),
70
+ clearHistory: () => Commands.clearHistory(webViewRef.current),
71
+ }), [setViewState, webViewRef]);
72
+ const directEventCallbacks = useMemo(() => ({
73
+ onShouldStartLoadWithRequest,
74
+ onMessage,
75
+ }), [onMessage, onShouldStartLoadWithRequest]);
76
+ useEffect(() => {
90
77
  BatchedBridge.registerCallableModule(messagingModuleName, directEventCallbacks);
91
78
  }, [messagingModuleName, directEventCallbacks]);
92
- var otherView = null;
79
+ let otherView = null;
93
80
  if (viewState === 'LOADING') {
94
81
  otherView = (renderLoading || defaultRenderLoading)();
95
82
  }
@@ -98,10 +85,10 @@ var WebViewComponent = forwardRef(function (_a, ref) {
98
85
  otherView = (renderError || defaultRenderError)(lastErrorEvent.domain, lastErrorEvent.code, lastErrorEvent.description);
99
86
  }
100
87
  else if (viewState !== 'IDLE') {
101
- console.error("RNCWebView invalid state encountered: ".concat(viewState));
88
+ console.error(`RNCWebView invalid state encountered: ${viewState}`);
102
89
  }
103
- var webViewStyles = [styles.container, styles.webView, style];
104
- var webViewContainerStyle = [styles.container, containerStyle];
90
+ const webViewStyles = [styles.container, styles.webView, style];
91
+ const webViewContainerStyle = [styles.container, containerStyle];
105
92
  if (typeof source !== "number" && source && 'method' in source) {
106
93
  if (source.method === 'POST' && source.headers) {
107
94
  console.warn('WebView: `source.headers` is not supported when using POST.');
@@ -110,16 +97,16 @@ var WebViewComponent = forwardRef(function (_a, ref) {
110
97
  console.warn('WebView: `source.body` is not supported when using GET.');
111
98
  }
112
99
  }
113
- var NativeWebView = RNCWebView;
114
- var webView = <NativeWebView key="webViewKey" {...otherProps} messagingEnabled={typeof onMessageProp === 'function'} messagingModuleName={messagingModuleName} onLoadingError={onLoadingError} onLoadingFinish={onLoadingFinish} onLoadingProgress={onLoadingProgress} onLoadingStart={onLoadingStart} onHttpError={onHttpError} onRenderProcessGone={onRenderProcessGone} onMessage={onMessage} onShouldStartLoadWithRequest={onShouldStartLoadWithRequest} injectedJavaScriptForMainFrameOnly={injectedJavaScriptForMainFrameOnly} injectedJavaScriptBeforeContentLoadedForMainFrameOnly={injectedJavaScriptBeforeContentLoadedForMainFrameOnly} ref={webViewRef}
100
+ const NativeWebView = RNCWebView;
101
+ const webView = <NativeWebView key="webViewKey" {...otherProps} messagingEnabled={typeof onMessageProp === 'function'} messagingModuleName={messagingModuleName} onLoadingError={onLoadingError} onLoadingFinish={onLoadingFinish} onLoadingProgress={onLoadingProgress} onLoadingStart={onLoadingStart} onHttpError={onHttpError} onRenderProcessGone={onRenderProcessGone} onMessage={onMessage} onShouldStartLoadWithRequest={onShouldStartLoadWithRequest} injectedJavaScriptForMainFrameOnly={injectedJavaScriptForMainFrameOnly} injectedJavaScriptBeforeContentLoadedForMainFrameOnly={injectedJavaScriptBeforeContentLoadedForMainFrameOnly} ref={webViewRef}
115
102
  // TODO: find a better way to type this.
116
- source={resolveAssetSource(source)} style={webViewStyles} overScrollMode={overScrollMode} javaScriptEnabled={javaScriptEnabled} thirdPartyCookiesEnabled={thirdPartyCookiesEnabled} scalesPageToFit={scalesPageToFit} allowsFullscreenVideo={allowsFullscreenVideo} allowFileAccess={allowFileAccess} allowFileAccessFromFileURLs={allowFileAccessFromFileURLs} allowUniversalAccessFromFileURLs={allowUniversalAccessFromFileURLs} saveFormDataDisabled={saveFormDataDisabled} cacheEnabled={cacheEnabled} androidHardwareAccelerationDisabled={androidHardwareAccelerationDisabled} androidLayerType={androidLayerType} setSupportMultipleWindows={setSupportMultipleWindows} setBuiltInZoomControls={setBuiltInZoomControls} setDisplayZoomControls={setDisplayZoomControls} mixedContentMode={mixedContentMode} nestedScrollEnabled={nestedScrollEnabled} mediaPlaybackRequiresUserAction={mediaPlaybackRequiresUserAction}/>;
103
+ source={source} style={webViewStyles} overScrollMode={overScrollMode} javaScriptEnabled={javaScriptEnabled} thirdPartyCookiesEnabled={thirdPartyCookiesEnabled} scalesPageToFit={scalesPageToFit} allowsFullscreenVideo={allowsFullscreenVideo} allowFileAccess={allowFileAccess} allowFileAccessFromFileURLs={allowFileAccessFromFileURLs} allowUniversalAccessFromFileURLs={allowUniversalAccessFromFileURLs} saveFormDataDisabled={saveFormDataDisabled} cacheEnabled={cacheEnabled} androidHardwareAccelerationDisabled={androidHardwareAccelerationDisabled} androidLayerType={androidLayerType} setSupportMultipleWindows={setSupportMultipleWindows} setBuiltInZoomControls={setBuiltInZoomControls} setDisplayZoomControls={setDisplayZoomControls} mixedContentMode={mixedContentMode} nestedScrollEnabled={nestedScrollEnabled} mediaPlaybackRequiresUserAction={mediaPlaybackRequiresUserAction}/>;
117
104
  return (<View style={webViewContainerStyle}>
118
105
  {webView}
119
106
  {otherView}
120
107
  </View>);
121
108
  });
122
109
  // native implementation should return "true" only for Android 5+
123
- var isFileUploadSupported = NativeModules.RNCWebView.isFileUploadSupported();
124
- var WebView = Object.assign(WebViewComponent, { isFileUploadSupported: isFileUploadSupported });
110
+ const isFileUploadSupported = NativeModules.RNCWebView.isFileUploadSupported();
111
+ const WebView = Object.assign(WebViewComponent, { isFileUploadSupported });
125
112
  export default WebView;
@@ -1,65 +1,17 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- var __rest = (this && this.__rest) || function (s, e) {
38
- var t = {};
39
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
40
- t[p] = s[p];
41
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
42
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
43
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
44
- t[p[i]] = s[p[i]];
45
- }
46
- return t;
47
- };
48
1
  import React, { forwardRef, useCallback, useImperativeHandle, useRef } from 'react';
49
- import { Image, View, NativeModules, } from 'react-native';
2
+ import { View, NativeModules, } from 'react-native';
50
3
  import invariant from 'invariant';
51
4
  // @ts-expect-error react-native doesn't have this type
52
5
  import codegenNativeCommandsUntyped from 'react-native/Libraries/Utilities/codegenNativeCommands';
53
6
  import RNCWebView from "./WebViewNativeComponent.ios";
54
7
  import { defaultOriginWhitelist, defaultRenderError, defaultRenderLoading, useWebWiewLogic, } from './WebViewShared';
55
8
  import styles from './WebView.styles';
56
- var codegenNativeCommands = codegenNativeCommandsUntyped;
57
- var Commands = codegenNativeCommands({
58
- supportedCommands: ['goBack', 'goForward', 'reload', 'stopLoading', /* 'injectJavaScript', */ 'requestFocus', 'postMessage', 'loadUrl']
9
+ const codegenNativeCommands = codegenNativeCommandsUntyped;
10
+ const Commands = codegenNativeCommands({
11
+ supportedCommands: ['goBack', 'goForward', 'reload', 'stopLoading', /* 'injectJavaScript', */ 'requestFocus', 'postMessage', 'loadUrl'],
59
12
  });
60
- var resolveAssetSource = Image.resolveAssetSource;
61
- var processDecelerationRate = function (decelerationRate) {
62
- var newDecelerationRate = decelerationRate;
13
+ const processDecelerationRate = (decelerationRate) => {
14
+ let newDecelerationRate = decelerationRate;
63
15
  if (newDecelerationRate === 'normal') {
64
16
  newDecelerationRate = 0.998;
65
17
  }
@@ -68,71 +20,69 @@ var processDecelerationRate = function (decelerationRate) {
68
20
  }
69
21
  return newDecelerationRate;
70
22
  };
71
- var RNCWebViewManager = NativeModules.RNCWebViewManager;
72
- var useWarnIfChanges = function (value, name) {
73
- var ref = useRef(value);
23
+ const RNCWebViewManager = NativeModules.RNCWebViewManager;
24
+ const useWarnIfChanges = (value, name) => {
25
+ const ref = useRef(value);
74
26
  if (ref.current !== value) {
75
- console.warn("Changes to property ".concat(name, " do nothing after the initial render."));
27
+ console.warn(`Changes to property ${name} do nothing after the initial render.`);
76
28
  ref.current = value;
77
29
  }
78
30
  };
79
31
  /**
80
32
  * Harcoded defaults for security.
81
33
  */
82
- var allowFileAccessFromFileURLs = false;
83
- var allowUniversalAccessFromFileURLs = false;
84
- var injectedJavaScriptForMainFrameOnly = true;
85
- var injectedJavaScriptBeforeContentLoadedForMainFrameOnly = true;
86
- var mediaPlaybackRequiresUserAction = true;
34
+ const allowFileAccessFromFileURLs = false;
35
+ const allowUniversalAccessFromFileURLs = false;
36
+ const injectedJavaScriptForMainFrameOnly = true;
37
+ const injectedJavaScriptBeforeContentLoadedForMainFrameOnly = true;
38
+ const mediaPlaybackRequiresUserAction = true;
87
39
  // iOS only configs
88
- var allowsInlineMediaPlayback = true;
89
- var allowsAirPlayForMediaPlayback = false;
90
- var useSharedProcessPool = false;
91
- var sharedCookiesEnabled = false;
92
- var enableApplePay = false;
93
- var onFileDownload = function () { return console.error('tried to download file'); };
94
- var dataDetectorTypes = 'none';
95
- var WebViewComponent = forwardRef(function (_a, ref) {
96
- var _b = _a.javaScriptEnabled, javaScriptEnabled = _b === void 0 ? true : _b, _c = _a.cacheEnabled, cacheEnabled = _c === void 0 ? true : _c, _d = _a.originWhitelist, originWhitelist = _d === void 0 ? defaultOriginWhitelist : _d, _e = _a.textInteractionEnabled, textInteractionEnabled = _e === void 0 ? true : _e, injectedJavaScript = _a.injectedJavaScript, injectedJavaScriptBeforeContentLoaded = _a.injectedJavaScriptBeforeContentLoaded, startInLoadingState = _a.startInLoadingState, onNavigationStateChange = _a.onNavigationStateChange, onLoadStart = _a.onLoadStart, onError = _a.onError, onLoad = _a.onLoad, onLoadEnd = _a.onLoadEnd, onLoadProgress = _a.onLoadProgress, onContentProcessDidTerminateProp = _a.onContentProcessDidTerminate, onHttpErrorProp = _a.onHttpError, onMessageProp = _a.onMessage, renderLoading = _a.renderLoading, renderError = _a.renderError, style = _a.style, containerStyle = _a.containerStyle, source = _a.source, incognito = _a.incognito, decelerationRateProp = _a.decelerationRate, onShouldStartLoadWithRequestProp = _a.onShouldStartLoadWithRequest, otherProps = __rest(_a, ["javaScriptEnabled", "cacheEnabled", "originWhitelist", "textInteractionEnabled", "injectedJavaScript", "injectedJavaScriptBeforeContentLoaded", "startInLoadingState", "onNavigationStateChange", "onLoadStart", "onError", "onLoad", "onLoadEnd", "onLoadProgress", "onContentProcessDidTerminate", "onHttpError", "onMessage", "renderLoading", "renderError", "style", "containerStyle", "source", "incognito", "decelerationRate", "onShouldStartLoadWithRequest"]);
97
- var webViewRef = useRef(null);
98
- var onShouldStartLoadWithRequestCallback = useCallback(function (shouldStart, _url, lockIdentifier) {
99
- if (lockIdentifier === void 0) { lockIdentifier = 0; }
100
- var viewManager = RNCWebViewManager;
40
+ const allowsInlineMediaPlayback = true;
41
+ const allowsAirPlayForMediaPlayback = false;
42
+ const useSharedProcessPool = false;
43
+ const sharedCookiesEnabled = false;
44
+ const enableApplePay = false;
45
+ const onFileDownload = () => console.error('tried to download file');
46
+ const dataDetectorTypes = 'none';
47
+ const WebViewComponent = forwardRef(({ javaScriptEnabled = true, cacheEnabled = true, originWhitelist = defaultOriginWhitelist, textInteractionEnabled = true, injectedJavaScript, injectedJavaScriptBeforeContentLoaded, startInLoadingState, onNavigationStateChange, onLoadStart, onError, onLoad, onLoadEnd, onLoadProgress, onContentProcessDidTerminate: onContentProcessDidTerminateProp, onHttpError: onHttpErrorProp, onMessage: onMessageProp, renderLoading, renderError, style, containerStyle, source, incognito, decelerationRate: decelerationRateProp, onShouldStartLoadWithRequest: onShouldStartLoadWithRequestProp, ...otherProps }, ref) => {
48
+ const webViewRef = useRef(null);
49
+ const onShouldStartLoadWithRequestCallback = useCallback((shouldStart, _url, lockIdentifier = 0) => {
50
+ const viewManager = RNCWebViewManager;
101
51
  viewManager.startLoadWithResult(!!shouldStart, lockIdentifier);
102
52
  }, []);
103
- var _f = useWebWiewLogic({
104
- onNavigationStateChange: onNavigationStateChange,
105
- onLoad: onLoad,
106
- onError: onError,
107
- onHttpErrorProp: onHttpErrorProp,
108
- onLoadEnd: onLoadEnd,
109
- onLoadProgress: onLoadProgress,
110
- onLoadStart: onLoadStart,
111
- onMessageProp: onMessageProp,
112
- startInLoadingState: startInLoadingState,
113
- originWhitelist: originWhitelist,
114
- onShouldStartLoadWithRequestProp: onShouldStartLoadWithRequestProp,
115
- onShouldStartLoadWithRequestCallback: onShouldStartLoadWithRequestCallback,
116
- onContentProcessDidTerminateProp: onContentProcessDidTerminateProp
117
- }), onLoadingStart = _f.onLoadingStart, onShouldStartLoadWithRequest = _f.onShouldStartLoadWithRequest, onMessage = _f.onMessage, viewState = _f.viewState, setViewState = _f.setViewState, lastErrorEvent = _f.lastErrorEvent, onHttpError = _f.onHttpError, onLoadingError = _f.onLoadingError, onLoadingFinish = _f.onLoadingFinish, onLoadingProgress = _f.onLoadingProgress, onContentProcessDidTerminate = _f.onContentProcessDidTerminate;
118
- useImperativeHandle(ref, function () { return ({
119
- goForward: function () { return Commands.goForward(webViewRef.current); },
120
- goBack: function () { return Commands.goBack(webViewRef.current); },
121
- reload: function () {
53
+ const { onLoadingStart, onShouldStartLoadWithRequest, onMessage, viewState, setViewState, lastErrorEvent, onHttpError, onLoadingError, onLoadingFinish, onLoadingProgress, onContentProcessDidTerminate } = useWebWiewLogic({
54
+ onNavigationStateChange,
55
+ onLoad,
56
+ onError,
57
+ onHttpErrorProp,
58
+ onLoadEnd,
59
+ onLoadProgress,
60
+ onLoadStart,
61
+ onMessageProp,
62
+ startInLoadingState,
63
+ originWhitelist,
64
+ onShouldStartLoadWithRequestProp,
65
+ onShouldStartLoadWithRequestCallback,
66
+ onContentProcessDidTerminateProp,
67
+ });
68
+ useImperativeHandle(ref, () => ({
69
+ goForward: () => Commands.goForward(webViewRef.current),
70
+ goBack: () => Commands.goBack(webViewRef.current),
71
+ reload: () => {
122
72
  setViewState('LOADING');
123
73
  Commands.reload(webViewRef.current);
124
74
  },
125
- stopLoading: function () { return Commands.stopLoading(webViewRef.current); },
126
- postMessage: function (data) { return Commands.postMessage(webViewRef.current, data); },
75
+ stopLoading: () => Commands.stopLoading(webViewRef.current),
76
+ postMessage: (data) => Commands.postMessage(webViewRef.current, data),
127
77
  // injectJavaScript: (data: string) => Commands.injectJavaScript(webViewRef.current, data),
128
- requestFocus: function () { return Commands.requestFocus(webViewRef.current); }
129
- }); }, [setViewState, webViewRef]);
78
+ requestFocus: () => Commands.requestFocus(webViewRef.current),
79
+ }), [setViewState, webViewRef]);
130
80
  useWarnIfChanges(allowsInlineMediaPlayback, 'allowsInlineMediaPlayback');
131
81
  useWarnIfChanges(allowsAirPlayForMediaPlayback, 'allowsAirPlayForMediaPlayback');
132
82
  useWarnIfChanges(incognito, 'incognito');
133
83
  useWarnIfChanges(mediaPlaybackRequiresUserAction, 'mediaPlaybackRequiresUserAction');
134
84
  useWarnIfChanges(dataDetectorTypes, 'dataDetectorTypes');
135
- var otherView = null;
85
+ let otherView = null;
136
86
  if (viewState === 'LOADING') {
137
87
  otherView = (renderLoading || defaultRenderLoading)();
138
88
  }
@@ -141,23 +91,21 @@ var WebViewComponent = forwardRef(function (_a, ref) {
141
91
  otherView = (renderError || defaultRenderError)(lastErrorEvent.domain, lastErrorEvent.code, lastErrorEvent.description);
142
92
  }
143
93
  else if (viewState !== 'IDLE') {
144
- console.error("RNCWebView invalid state encountered: ".concat(viewState));
94
+ console.error(`RNCWebView invalid state encountered: ${viewState}`);
145
95
  }
146
- var webViewStyles = [styles.container, styles.webView, style];
147
- var webViewContainerStyle = [styles.container, containerStyle];
148
- var decelerationRate = processDecelerationRate(decelerationRateProp);
149
- var NativeWebView = RNCWebView;
150
- var webView = (<NativeWebView key="webViewKey" {...otherProps} allowFileAccessFromFileURLs={allowFileAccessFromFileURLs} allowUniversalAccessFromFileURLs={allowUniversalAccessFromFileURLs} enableApplePay={enableApplePay} javaScriptEnabled={javaScriptEnabled} cacheEnabled={cacheEnabled} dataDetectorTypes={dataDetectorTypes} useSharedProcessPool={useSharedProcessPool} textInteractionEnabled={textInteractionEnabled} decelerationRate={decelerationRate} messagingEnabled={typeof onMessageProp === 'function'} onLoadingError={onLoadingError} onLoadingFinish={onLoadingFinish} onLoadingProgress={onLoadingProgress} onFileDownload={onFileDownload} onLoadingStart={onLoadingStart} onHttpError={onHttpError} onMessage={onMessage} onShouldStartLoadWithRequest={onShouldStartLoadWithRequest} onContentProcessDidTerminate={onContentProcessDidTerminate} injectedJavaScript={injectedJavaScript} injectedJavaScriptBeforeContentLoaded={injectedJavaScriptBeforeContentLoaded} injectedJavaScriptForMainFrameOnly={injectedJavaScriptForMainFrameOnly} injectedJavaScriptBeforeContentLoadedForMainFrameOnly={injectedJavaScriptBeforeContentLoadedForMainFrameOnly} allowsAirPlayForMediaPlayback={allowsAirPlayForMediaPlayback} allowsInlineMediaPlayback={allowsInlineMediaPlayback} incognito={incognito} mediaPlaybackRequiresUserAction={mediaPlaybackRequiresUserAction} ref={webViewRef} sharedCookiesEnabled={sharedCookiesEnabled}
96
+ const webViewStyles = [styles.container, styles.webView, style];
97
+ const webViewContainerStyle = [styles.container, containerStyle];
98
+ const decelerationRate = processDecelerationRate(decelerationRateProp);
99
+ const NativeWebView = RNCWebView;
100
+ const webView = (<NativeWebView key="webViewKey" {...otherProps} allowFileAccessFromFileURLs={allowFileAccessFromFileURLs} allowUniversalAccessFromFileURLs={allowUniversalAccessFromFileURLs} enableApplePay={enableApplePay} javaScriptEnabled={javaScriptEnabled} cacheEnabled={cacheEnabled} dataDetectorTypes={dataDetectorTypes} useSharedProcessPool={useSharedProcessPool} textInteractionEnabled={textInteractionEnabled} decelerationRate={decelerationRate} messagingEnabled={typeof onMessageProp === 'function'} onLoadingError={onLoadingError} onLoadingFinish={onLoadingFinish} onLoadingProgress={onLoadingProgress} onFileDownload={onFileDownload} onLoadingStart={onLoadingStart} onHttpError={onHttpError} onMessage={onMessage} onShouldStartLoadWithRequest={onShouldStartLoadWithRequest} onContentProcessDidTerminate={onContentProcessDidTerminate} injectedJavaScript={injectedJavaScript} injectedJavaScriptBeforeContentLoaded={injectedJavaScriptBeforeContentLoaded} injectedJavaScriptForMainFrameOnly={injectedJavaScriptForMainFrameOnly} injectedJavaScriptBeforeContentLoadedForMainFrameOnly={injectedJavaScriptBeforeContentLoadedForMainFrameOnly} allowsAirPlayForMediaPlayback={allowsAirPlayForMediaPlayback} allowsInlineMediaPlayback={allowsInlineMediaPlayback} incognito={incognito} mediaPlaybackRequiresUserAction={mediaPlaybackRequiresUserAction} ref={webViewRef} sharedCookiesEnabled={sharedCookiesEnabled}
151
101
  // TODO: find a better way to type this.
152
- source={resolveAssetSource(source)} style={webViewStyles}/>);
102
+ source={source} style={webViewStyles}/>);
153
103
  return (<View style={webViewContainerStyle}>
154
104
  {webView}
155
105
  {otherView}
156
106
  </View>);
157
107
  });
158
108
  // no native implementation for iOS, depends only on permissions
159
- var isFileUploadSupported = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
160
- return [2 /*return*/, true];
161
- }); }); };
162
- var WebView = Object.assign(WebViewComponent, { isFileUploadSupported: isFileUploadSupported });
109
+ const isFileUploadSupported = async () => true;
110
+ const WebView = Object.assign(WebViewComponent, { isFileUploadSupported });
163
111
  export default WebView;
package/lib/WebView.js CHANGED
@@ -2,10 +2,10 @@ import React from 'react';
2
2
  import { Text, View } from 'react-native';
3
3
  // This "dummy" WebView is to render something for unsupported platforms,
4
4
  // like for example Expo SDK "web" platform.
5
- var WebView = function () { return (<View style={{ alignSelf: 'flex-start' }}>
5
+ const WebView = () => (<View style={{ alignSelf: 'flex-start' }}>
6
6
  <Text style={{ color: 'red' }}>
7
7
  React Native WebView does not support this platform.
8
8
  </Text>
9
- </View>); };
9
+ </View>);
10
10
  export { WebView };
11
11
  export default WebView;
@@ -1,8 +1,8 @@
1
1
  import { StyleSheet } from 'react-native';
2
- var styles = StyleSheet.create({
2
+ const styles = StyleSheet.create({
3
3
  container: {
4
4
  flex: 1,
5
- overflow: 'hidden'
5
+ overflow: 'hidden',
6
6
  },
7
7
  loadingOrErrorView: {
8
8
  position: 'absolute',
@@ -14,20 +14,20 @@ var styles = StyleSheet.create({
14
14
  backgroundColor: 'white'
15
15
  },
16
16
  loadingProgressBar: {
17
- height: 20
17
+ height: 20,
18
18
  },
19
19
  errorText: {
20
20
  fontSize: 14,
21
21
  textAlign: 'center',
22
- marginBottom: 2
22
+ marginBottom: 2,
23
23
  },
24
24
  errorTextTitle: {
25
25
  fontSize: 15,
26
26
  fontWeight: '500',
27
- marginBottom: 10
27
+ marginBottom: 10,
28
28
  },
29
29
  webView: {
30
- backgroundColor: '#ffffff'
31
- }
30
+ backgroundColor: '#ffffff',
31
+ },
32
32
  });
33
33
  export default styles;
@@ -1,3 +1,3 @@
1
1
  import { requireNativeComponent } from "react-native";
2
- var RNCWebView = requireNativeComponent('RNCWebView');
2
+ const RNCWebView = requireNativeComponent('RNCWebView');
3
3
  export default RNCWebView;
@@ -1,3 +1,3 @@
1
1
  import { requireNativeComponent } from "react-native";
2
- var RNCWebView = requireNativeComponent('RNCWebView');
2
+ const RNCWebView = requireNativeComponent('RNCWebView');
3
3
  export default RNCWebView;
@@ -1,46 +1,23 @@
1
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
- if (ar || !(i in from)) {
4
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
- ar[i] = from[i];
6
- }
7
- }
8
- return to.concat(ar || Array.prototype.slice.call(from));
9
- };
10
1
  import escapeStringRegexp from 'escape-string-regexp';
11
2
  import React, { useCallback, useMemo, useRef, useState } from 'react';
12
- import { Linking, View, ActivityIndicator, Text, Platform } from 'react-native';
3
+ import { View, ActivityIndicator, Text, Platform } from 'react-native';
13
4
  import styles from './WebView.styles';
14
- var defaultOriginWhitelist = ['http://*', 'https://*'];
15
- var extractOrigin = function (url) {
16
- var result = /^[A-Za-z][A-Za-z0-9+\-.]+:(\/\/)?[^/]*/.exec(url);
5
+ const defaultOriginWhitelist = ['http://*', 'https://*'];
6
+ const extractOrigin = (url) => {
7
+ const result = /^[A-Za-z][A-Za-z0-9+\-.]+:(\/\/)?[^/]*/.exec(url);
17
8
  return result === null ? '' : result[0];
18
9
  };
19
- var originWhitelistToRegex = function (originWhitelist) {
20
- return "^".concat(escapeStringRegexp(originWhitelist).replace(/\\\*/g, '.*'));
21
- };
22
- var passesWhitelist = function (compiledWhitelist, url) {
23
- var origin = extractOrigin(url);
24
- return compiledWhitelist.some(function (x) { return new RegExp(x).test(origin); });
25
- };
26
- var compileWhitelist = function (originWhitelist) {
27
- return __spreadArray(['about:blank'], (originWhitelist || []), true).map(originWhitelistToRegex);
10
+ const originWhitelistToRegex = (originWhitelist) => `^${escapeStringRegexp(originWhitelist).replace(/\\\*/g, '.*')}`;
11
+ const passesWhitelist = (compiledWhitelist, url) => {
12
+ const origin = extractOrigin(url);
13
+ return compiledWhitelist.some(x => new RegExp(x).test(origin));
28
14
  };
29
- var createOnShouldStartLoadWithRequest = function (loadRequest, originWhitelist, onShouldStartLoadWithRequest) {
30
- return function (_a) {
31
- var nativeEvent = _a.nativeEvent;
32
- var shouldStart = true;
33
- var url = nativeEvent.url, lockIdentifier = nativeEvent.lockIdentifier;
15
+ const compileWhitelist = (originWhitelist) => ['about:blank', ...(originWhitelist || [])].map(originWhitelistToRegex);
16
+ const createOnShouldStartLoadWithRequest = (loadRequest, originWhitelist, onShouldStartLoadWithRequest) => {
17
+ return ({ nativeEvent }) => {
18
+ let shouldStart = true;
19
+ const { url, lockIdentifier } = nativeEvent;
34
20
  if (!passesWhitelist(compileWhitelist(originWhitelist), url)) {
35
- Linking.canOpenURL(url).then(function (supported) {
36
- if (supported) {
37
- return Linking.openURL(url);
38
- }
39
- console.warn("Can't open url: ".concat(url));
40
- return undefined;
41
- })["catch"](function (e) {
42
- console.warn('Error opening URL: ', e);
43
- });
44
21
  shouldStart = false;
45
22
  }
46
23
  else if (onShouldStartLoadWithRequest) {
@@ -49,32 +26,31 @@ var createOnShouldStartLoadWithRequest = function (loadRequest, originWhitelist,
49
26
  loadRequest(shouldStart, url, lockIdentifier);
50
27
  };
51
28
  };
52
- var defaultRenderLoading = function () { return (<View style={styles.loadingOrErrorView}>
29
+ const defaultRenderLoading = () => (<View style={styles.loadingOrErrorView}>
53
30
  <ActivityIndicator />
54
- </View>); };
55
- var defaultRenderError = function (errorDomain, errorCode, errorDesc) { return (<View style={styles.loadingOrErrorView}>
31
+ </View>);
32
+ const defaultRenderError = (errorDomain, errorCode, errorDesc) => (<View style={styles.loadingOrErrorView}>
56
33
  <Text style={styles.errorTextTitle}>Error loading page</Text>
57
- <Text style={styles.errorText}>{"Domain: ".concat(errorDomain)}</Text>
58
- <Text style={styles.errorText}>{"Error Code: ".concat(errorCode)}</Text>
59
- <Text style={styles.errorText}>{"Description: ".concat(errorDesc)}</Text>
60
- </View>); };
34
+ <Text style={styles.errorText}>{`Domain: ${errorDomain}`}</Text>
35
+ <Text style={styles.errorText}>{`Error Code: ${errorCode}`}</Text>
36
+ <Text style={styles.errorText}>{`Description: ${errorDesc}`}</Text>
37
+ </View>);
61
38
  export { defaultOriginWhitelist, createOnShouldStartLoadWithRequest, defaultRenderLoading, defaultRenderError, };
62
- export var useWebWiewLogic = function (_a) {
63
- var startInLoadingState = _a.startInLoadingState, onNavigationStateChange = _a.onNavigationStateChange, onLoadStart = _a.onLoadStart, onLoad = _a.onLoad, onLoadProgress = _a.onLoadProgress, onLoadEnd = _a.onLoadEnd, onError = _a.onError, onHttpErrorProp = _a.onHttpErrorProp, onMessageProp = _a.onMessageProp, onRenderProcessGoneProp = _a.onRenderProcessGoneProp, onContentProcessDidTerminateProp = _a.onContentProcessDidTerminateProp, originWhitelist = _a.originWhitelist, onShouldStartLoadWithRequestProp = _a.onShouldStartLoadWithRequestProp, onShouldStartLoadWithRequestCallback = _a.onShouldStartLoadWithRequestCallback;
64
- var _b = useState(startInLoadingState ? "LOADING" : "IDLE"), viewState = _b[0], setViewState = _b[1];
65
- var _c = useState(null), lastErrorEvent = _c[0], setLastErrorEvent = _c[1];
66
- var startUrl = useRef(null);
67
- var updateNavigationState = useCallback(function (event) {
39
+ export const useWebWiewLogic = ({ startInLoadingState, onNavigationStateChange, onLoadStart, onLoad, onLoadProgress, onLoadEnd, onError, onHttpErrorProp, onMessageProp, onRenderProcessGoneProp, onContentProcessDidTerminateProp, originWhitelist, onShouldStartLoadWithRequestProp, onShouldStartLoadWithRequestCallback, }) => {
40
+ const [viewState, setViewState] = useState(startInLoadingState ? "LOADING" : "IDLE");
41
+ const [lastErrorEvent, setLastErrorEvent] = useState(null);
42
+ const startUrl = useRef(null);
43
+ const updateNavigationState = useCallback((event) => {
68
44
  onNavigationStateChange === null || onNavigationStateChange === void 0 ? void 0 : onNavigationStateChange(event.nativeEvent);
69
45
  }, [onNavigationStateChange]);
70
- var onLoadingStart = useCallback(function (event) {
46
+ const onLoadingStart = useCallback((event) => {
71
47
  // Needed for android
72
48
  startUrl.current = event.nativeEvent.url;
73
49
  // !Needed for android
74
50
  onLoadStart === null || onLoadStart === void 0 ? void 0 : onLoadStart(event);
75
51
  updateNavigationState(event);
76
52
  }, [onLoadStart, updateNavigationState]);
77
- var onLoadingError = useCallback(function (event) {
53
+ const onLoadingError = useCallback((event) => {
78
54
  event.persist();
79
55
  if (onError) {
80
56
  onError(event);
@@ -90,23 +66,23 @@ export var useWebWiewLogic = function (_a) {
90
66
  setViewState('ERROR');
91
67
  setLastErrorEvent(event.nativeEvent);
92
68
  }, [onError, onLoadEnd]);
93
- var onHttpError = useCallback(function (event) {
69
+ const onHttpError = useCallback((event) => {
94
70
  onHttpErrorProp === null || onHttpErrorProp === void 0 ? void 0 : onHttpErrorProp(event);
95
71
  }, [onHttpErrorProp]);
96
72
  // Android Only
97
- var onRenderProcessGone = useCallback(function (event) {
73
+ const onRenderProcessGone = useCallback((event) => {
98
74
  onRenderProcessGoneProp === null || onRenderProcessGoneProp === void 0 ? void 0 : onRenderProcessGoneProp(event);
99
75
  }, [onRenderProcessGoneProp]);
100
76
  // !Android Only
101
77
  // iOS Only
102
- var onContentProcessDidTerminate = useCallback(function (event) {
78
+ const onContentProcessDidTerminate = useCallback((event) => {
103
79
  onContentProcessDidTerminateProp === null || onContentProcessDidTerminateProp === void 0 ? void 0 : onContentProcessDidTerminateProp(event);
104
80
  }, [onContentProcessDidTerminateProp]);
105
81
  // !iOS Only
106
- var onLoadingFinish = useCallback(function (event) {
82
+ const onLoadingFinish = useCallback((event) => {
107
83
  onLoad === null || onLoad === void 0 ? void 0 : onLoad(event);
108
84
  onLoadEnd === null || onLoadEnd === void 0 ? void 0 : onLoadEnd(event);
109
- var url = event.nativeEvent.url;
85
+ const { nativeEvent: { url } } = event;
110
86
  // on Android, only if url === startUrl
111
87
  if (Platform.OS !== "android" || url === startUrl.current) {
112
88
  setViewState('IDLE');
@@ -114,31 +90,31 @@ export var useWebWiewLogic = function (_a) {
114
90
  // !on Android, only if url === startUrl
115
91
  updateNavigationState(event);
116
92
  }, [onLoad, onLoadEnd, updateNavigationState]);
117
- var onMessage = useCallback(function (event) {
93
+ const onMessage = useCallback((event) => {
118
94
  onMessageProp === null || onMessageProp === void 0 ? void 0 : onMessageProp(event);
119
95
  }, [onMessageProp]);
120
- var onLoadingProgress = useCallback(function (event) {
121
- var progress = event.nativeEvent.progress;
96
+ const onLoadingProgress = useCallback((event) => {
97
+ const { nativeEvent: { progress } } = event;
122
98
  // patch for Android only
123
99
  if (Platform.OS === "android" && progress === 1) {
124
- setViewState(function (prevViewState) { return prevViewState === 'LOADING' ? 'IDLE' : prevViewState; });
100
+ setViewState(prevViewState => prevViewState === 'LOADING' ? 'IDLE' : prevViewState);
125
101
  }
126
102
  // !patch for Android only
127
103
  onLoadProgress === null || onLoadProgress === void 0 ? void 0 : onLoadProgress(event);
128
104
  }, [onLoadProgress]);
129
- var onShouldStartLoadWithRequest = useMemo(function () { return createOnShouldStartLoadWithRequest(onShouldStartLoadWithRequestCallback, originWhitelist, onShouldStartLoadWithRequestProp); }, [originWhitelist, onShouldStartLoadWithRequestProp, onShouldStartLoadWithRequestCallback]);
105
+ const onShouldStartLoadWithRequest = useMemo(() => createOnShouldStartLoadWithRequest(onShouldStartLoadWithRequestCallback, originWhitelist, onShouldStartLoadWithRequestProp), [originWhitelist, onShouldStartLoadWithRequestProp, onShouldStartLoadWithRequestCallback]);
130
106
  return {
131
- onShouldStartLoadWithRequest: onShouldStartLoadWithRequest,
132
- onLoadingStart: onLoadingStart,
133
- onLoadingProgress: onLoadingProgress,
134
- onLoadingError: onLoadingError,
135
- onLoadingFinish: onLoadingFinish,
136
- onHttpError: onHttpError,
137
- onRenderProcessGone: onRenderProcessGone,
138
- onContentProcessDidTerminate: onContentProcessDidTerminate,
139
- onMessage: onMessage,
140
- viewState: viewState,
141
- setViewState: setViewState,
142
- lastErrorEvent: lastErrorEvent
107
+ onShouldStartLoadWithRequest,
108
+ onLoadingStart,
109
+ onLoadingProgress,
110
+ onLoadingError,
111
+ onLoadingFinish,
112
+ onHttpError,
113
+ onRenderProcessGone,
114
+ onContentProcessDidTerminate,
115
+ onMessage,
116
+ viewState,
117
+ setViewState,
118
+ lastErrorEvent,
143
119
  };
144
120
  };
@@ -1,33 +1,6 @@
1
1
  /* eslint-disable react/no-multi-comp, max-classes-per-file */
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  import { Component } from 'react';
18
- var NativeWebViewIOS = /** @class */ (function (_super) {
19
- __extends(NativeWebViewIOS, _super);
20
- function NativeWebViewIOS() {
21
- return _super !== null && _super.apply(this, arguments) || this;
22
- }
23
- return NativeWebViewIOS;
24
- }(NativeWebViewIOSBase));
25
- export { NativeWebViewIOS };
26
- var NativeWebViewAndroid = /** @class */ (function (_super) {
27
- __extends(NativeWebViewAndroid, _super);
28
- function NativeWebViewAndroid() {
29
- return _super !== null && _super.apply(this, arguments) || this;
30
- }
31
- return NativeWebViewAndroid;
32
- }(NativeWebViewAndroidBase));
33
- export { NativeWebViewAndroid };
3
+ export class NativeWebViewIOS extends NativeWebViewIOSBase {
4
+ }
5
+ export class NativeWebViewAndroid extends NativeWebViewAndroidBase {
6
+ }
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "Thibault Malbranche <malbranche.thibault@gmail.com>"
10
10
  ],
11
11
  "license": "MIT",
12
- "version": "11.26.1-exodus.1",
12
+ "version": "11.26.1-exodus.3",
13
13
  "homepage": "https://github.com/ExodusMovement/react-native-webview#readme",
14
14
  "scripts": {
15
15
  "android": "react-native run-android",