@momo-kits/webview 0.0.74-beta → 0.72.1

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.
Files changed (39) hide show
  1. package/index.d.ts +1 -46
  2. package/index.js +0 -2
  3. package/lib/WebView.android.d.ts +4 -72
  4. package/lib/WebView.android.d.ts.map +1 -1
  5. package/lib/WebView.android.js +101 -307
  6. package/lib/WebView.d.ts +2 -2
  7. package/lib/WebView.d.ts.map +1 -1
  8. package/lib/WebView.ios.d.ts +4 -80
  9. package/lib/WebView.ios.d.ts.map +1 -1
  10. package/lib/WebView.ios.js +86 -221
  11. package/lib/WebView.js +7 -12
  12. package/lib/WebView.macos.d.ts +4 -80
  13. package/lib/WebView.macos.d.ts.map +1 -1
  14. package/lib/WebView.macos.js +83 -219
  15. package/lib/WebView.styles.js +0 -2
  16. package/lib/WebView.windows.d.ts +5 -26
  17. package/lib/WebView.windows.d.ts.map +1 -1
  18. package/lib/WebView.windows.js +114 -161
  19. package/lib/WebViewNativeComponent.android.d.ts +4 -0
  20. package/lib/WebViewNativeComponent.android.d.ts.map +1 -0
  21. package/lib/WebViewNativeComponent.android.js +3 -0
  22. package/lib/WebViewNativeComponent.ios.d.ts +4 -0
  23. package/lib/WebViewNativeComponent.ios.d.ts.map +1 -0
  24. package/lib/WebViewNativeComponent.ios.js +3 -0
  25. package/lib/WebViewNativeComponent.macos.d.ts +4 -0
  26. package/lib/WebViewNativeComponent.macos.d.ts.map +1 -0
  27. package/lib/WebViewNativeComponent.macos.js +3 -0
  28. package/lib/WebViewNativeComponent.windows.d.ts +4 -0
  29. package/lib/WebViewNativeComponent.windows.d.ts.map +1 -0
  30. package/lib/WebViewNativeComponent.windows.js +3 -0
  31. package/lib/WebViewShared.d.ts +32 -2
  32. package/lib/WebViewShared.d.ts.map +1 -1
  33. package/lib/WebViewShared.js +99 -16
  34. package/lib/WebViewTypes.d.ts +242 -14
  35. package/lib/WebViewTypes.d.ts.map +1 -1
  36. package/lib/WebViewTypes.js +4 -3
  37. package/lib/index.d.ts.map +1 -0
  38. package/package.json +15 -15
  39. package/publish.sh +2 -2
package/index.d.ts CHANGED
@@ -1,47 +1,2 @@
1
- import { Component } from 'react';
2
- // eslint-disable-next-line
3
- import { IOSWebViewProps, AndroidWebViewProps } from './lib/WebViewTypes';
4
-
5
- export { FileDownload, WebViewMessageEvent, WebViewNavigation } from './lib/WebViewTypes';
6
-
7
- export type WebViewProps = IOSWebViewProps & AndroidWebViewProps;
8
-
9
- declare class WebView extends Component<WebViewProps> {
10
- /**
11
- * Go back one page in the webview's history.
12
- */
13
- goBack: () => void;
14
-
15
- /**
16
- * Go forward one page in the webview's history.
17
- */
18
- goForward: () => void;
19
-
20
- /**
21
- * Reloads the current page.
22
- */
23
- reload: () => void;
24
-
25
- /**
26
- * Stop loading the current page.
27
- */
28
- stopLoading(): void;
29
-
30
- /**
31
- * Extra Native Component Config.
32
- */
33
- extraNativeComponentConfig: () => any;
34
-
35
- /**
36
- * Executes the JavaScript string.
37
- */
38
- injectJavaScript: (script: string) => void;
39
-
40
- /**
41
- * Focuses on WebView redered page.
42
- */
43
- requestFocus: () => void;
44
- }
45
-
46
- export { WebView };
1
+ import WebView from './lib/WebView';
47
2
  export default WebView;
package/index.js CHANGED
@@ -1,4 +1,2 @@
1
- /* eslint-disable */
2
1
  import WebView from './lib/WebView';
3
-
4
2
  export default WebView;
@@ -1,75 +1,7 @@
1
1
  import React from 'react';
2
- import { WebViewRenderProcessGoneEvent, WebViewErrorEvent, WebViewHttpErrorEvent, WebViewMessageEvent, WebViewNavigationEvent, WebViewProgressEvent, AndroidWebViewProps, NativeWebViewAndroid, State } from './WebViewTypes';
3
- /**
4
- * Renders a native WebView.
5
- */
6
- declare class WebView extends React.Component<AndroidWebViewProps, State> {
7
- static defaultProps: {
8
- overScrollMode: string;
9
- javaScriptEnabled: boolean;
10
- thirdPartyCookiesEnabled: boolean;
11
- scalesPageToFit: boolean;
12
- allowsFullscreenVideo: boolean;
13
- allowFileAccess: boolean;
14
- saveFormDataDisabled: boolean;
15
- cacheEnabled: boolean;
16
- androidHardwareAccelerationDisabled: boolean;
17
- androidLayerType: string;
18
- originWhitelist: string[];
19
- };
20
- static isFileUploadSupported: () => Promise<any>;
21
- startUrl: string | null;
22
- state: State;
23
- webViewRef: React.RefObject<NativeWebViewAndroid>;
24
- messagingModuleName: string;
25
- componentDidMount: () => void;
26
- getCommands: () => {
27
- goForward: number;
28
- goBack: number;
29
- reload: number;
30
- stopLoading: number;
31
- postMessage: number;
32
- injectJavaScript: number;
33
- loadUrl: number;
34
- requestFocus: number;
35
- clearHistory: number;
36
- clearCache: number;
37
- clearFormData: number;
38
- };
39
- goForward: () => void;
40
- goBack: () => void;
41
- reload: () => void;
42
- stopLoading: () => void;
43
- requestFocus: () => void;
44
- postMessage: (data: string) => void;
45
- clearFormData: () => void;
46
- clearCache: (includeDiskFiles: boolean) => void;
47
- clearHistory: () => void;
48
- /**
49
- * Injects a javascript string into the referenced WebView. Deliberately does not
50
- * return a response because using eval() to return a response breaks this method
51
- * on pages with a Content Security Policy that disallows eval(). If you need that
52
- * functionality, look into postMessage/onMessage.
53
- */
54
- injectJavaScript: (data: string) => void;
55
- /**
56
- * We return an event with a bunch of fields including:
57
- * url, title, loading, canGoBack, canGoForward
58
- */
59
- updateNavigationState: (event: WebViewNavigationEvent) => void;
60
- /**
61
- * Returns the native `WebView` node.
62
- */
63
- getWebViewHandle: () => number;
64
- onLoadingStart: (event: WebViewNavigationEvent) => void;
65
- onLoadingError: (event: WebViewErrorEvent) => void;
66
- onHttpError: (event: WebViewHttpErrorEvent) => void;
67
- onRenderProcessGone: (event: WebViewRenderProcessGoneEvent) => void;
68
- onLoadingFinish: (event: WebViewNavigationEvent) => void;
69
- onMessage: (event: WebViewMessageEvent) => void;
70
- onLoadingProgress: (event: WebViewProgressEvent) => void;
71
- onShouldStartLoadWithRequestCallback: (shouldStart: boolean, url: string) => void;
72
- render(): JSX.Element;
73
- }
2
+ import { AndroidWebViewProps } from './WebViewTypes';
3
+ declare const WebView: React.ForwardRefExoticComponent<AndroidWebViewProps & React.RefAttributes<{}>> & {
4
+ isFileUploadSupported: () => Promise<boolean>;
5
+ };
74
6
  export default WebView;
75
7
  //# sourceMappingURL=WebView.android.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"WebView.android.d.ts","sourceRoot":"","sources":["../src/WebView.android.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAsB1B,OAAO,EACL,6BAA6B,EAC7B,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,KAAK,EAEN,MAAM,gBAAgB,CAAC;AAgBxB;;GAEG;AACH,cAAM,OAAQ,SAAQ,KAAK,CAAC,SAAS,CAAC,mBAAmB,EAAE,KAAK,CAAC;IAC/D,MAAM,CAAC,YAAY;;;;;;;;;;;;MAYjB;IAEF,MAAM,CAAC,qBAAqB,qBAG1B;IAEF,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE/B,KAAK,EAAE,KAAK,CAGV;IAGF,UAAU,wCAA2C;IAErD,mBAAmB,SAA0C;IAE7D,iBAAiB,aAEf;IAEF,WAAW;;;;;;;;;;;;MAA+D;IAE1E,SAAS,aAMP;IAEF,MAAM,aAMJ;IAEF,MAAM,aASJ;IAEF,WAAW,aAMT;IAEF,YAAY,aAMV;IAEF,WAAW,yBAMT;IAEF,aAAa,aAMZ;IAED,UAAU,sCAMR;IAEF,YAAY,aAMV;IAEF;;;;;OAKG;IACH,gBAAgB,yBAMd;IAEF;;;OAGG;IACH,qBAAqB,0CAInB;IAEF;;OAEG;IACH,gBAAgB,eAId;IAEF,cAAc,0CAQZ;IAEF,cAAc,qCAeZ;IAEF,WAAW,yCAKV;IAED,mBAAmB,iDAKlB;IAED,eAAe,0CAeb;IAEF,SAAS,uCAKP;IAEF,iBAAiB,wCAcf;IAEF,oCAAoC,8CAWlC;IAEF,MAAM;CAoFP;AAED,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"WebView.android.d.ts","sourceRoot":"","sources":["../src/WebView.android.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmF,MAAM,OAAO,CAAC;AAsBxG,OAAO,EACL,mBAAmB,EAEpB,MAAM,gBAAgB,CAAC;AA0LxB,QAAA,MAAM,OAAO;iCAHsB,QAAQ,OAAO,CAAC;CAGqB,CAAC;AAEzE,eAAe,OAAO,CAAC"}
@@ -1,318 +1,112 @@
1
- /* eslint-disable */
2
- import React from 'react';
3
- import {
4
- Image, requireNativeComponent, UIManager as NotTypedUIManager, View, NativeModules, findNodeHandle,
5
- } from 'react-native';
6
- import BatchedBridge from 'react-native/Libraries/BatchedBridge/BatchedBridge';
7
- import invariant from 'invariant';
8
- import {
9
- defaultOriginWhitelist, createOnShouldStartLoadWithRequest, defaultRenderError, defaultRenderLoading,
10
- } from './WebViewShared';
11
- import styles from './WebView.styles';
12
-
13
- const __extends = (this && this.__extends) || (function () {
14
- var extendStatics = function (d, b) {
15
- extendStatics = Object.setPrototypeOf
16
- || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; })
17
- || function (d, b) { for (const p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
18
- return extendStatics(d, b);
19
- };
20
- return function (d, b) {
21
- extendStatics(d, b);
22
- function __() { this.constructor = d; }
23
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
24
- };
25
- }());
26
- const __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
- function adopt(value) { return value instanceof P ? value : new P(((resolve) => { resolve(value); })); }
28
- return new (P || (P = Promise))(((resolve, reject) => {
29
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
- function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
31
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
- step((generator = generator.apply(thisArg, _arguments || [])).next());
33
- }));
34
- };
35
- const __generator = (this && this.__generator) || function (thisArg, body) {
36
- let _ = {
37
- label: 0, sent() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: []
38
- }; let f; let y; let t; let
39
- g;
40
- return g = { next: verb(0), throw: verb(1), return: verb(2) }, typeof Symbol === 'function' && (g[Symbol.iterator] = function () { return this; }), g;
41
- function verb(n) { return function (v) { return step([n, v]); }; }
42
- function step(op) {
43
- if (f) throw new TypeError('Generator is already executing.');
44
- while (_) {
45
- try {
46
- 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;
47
- if (y = 0, t) op = [op[0] & 2, t.value];
48
- switch (op[0]) {
49
- case 0: case 1: t = op; break;
50
- case 4: _.label++; return { value: op[1], done: false };
51
- case 5: _.label++; y = op[1]; op = [0]; continue;
52
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
53
- default:
54
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
55
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
56
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
57
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
58
- if (t[2]) _.ops.pop();
59
- _.trys.pop(); continue;
60
- }
61
- op = body.call(thisArg, _);
62
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
63
- }
64
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
65
- }
66
- };
67
- const __rest = (this && this.__rest) || function (s, e) {
68
- const t = {};
69
- for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; }
70
- if (s != null && typeof Object.getOwnPropertySymbols === 'function') {
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")
71
6
  for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
72
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
73
9
  }
74
- }
75
10
  return t;
76
11
  };
77
-
78
- const UIManager = NotTypedUIManager;
79
- const RNCWebView = requireNativeComponent('RNCWebView');
80
- const { resolveAssetSource } = Image;
12
+ import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
13
+ import { Image, View, NativeModules, } from 'react-native';
14
+ import BatchedBridge from 'react-native/Libraries/BatchedBridge/BatchedBridge';
15
+ // @ts-expect-error react-native doesn't have this type
16
+ import codegenNativeCommandsUntyped from 'react-native/Libraries/Utilities/codegenNativeCommands';
17
+ import invariant from 'invariant';
18
+ import RNCWebView from "./WebViewNativeComponent.android";
19
+ import { defaultOriginWhitelist, defaultRenderError, defaultRenderLoading, useWebWiewLogic, } from './WebViewShared';
20
+ 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']
24
+ });
25
+ var resolveAssetSource = Image.resolveAssetSource;
81
26
  /**
82
27
  * A simple counter to uniquely identify WebView instances. Do not use this for anything else.
83
28
  */
84
- let uniqueRef = 0;
85
- /**
86
- * Renders a native WebView.
87
- */
88
- const WebView = /** @class */ (function (_super) {
89
- __extends(WebView, _super);
90
- function WebView() {
91
- const _this = _super !== null && _super.apply(this, arguments) || this;
92
- _this.startUrl = null;
93
- _this.state = {
94
- viewState: _this.props.startInLoadingState ? 'LOADING' : 'IDLE',
95
- lastErrorEvent: null
96
- };
97
- _this.webViewRef = React.createRef();
98
- _this.messagingModuleName = `WebViewMessageHandler${uniqueRef += 1}`;
99
- _this.componentDidMount = function () {
100
- BatchedBridge.registerCallableModule(_this.messagingModuleName, _this);
101
- };
102
- _this.getCommands = function () { return UIManager.getViewManagerConfig('RNCWebView').Commands; };
103
- _this.goForward = function () {
104
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().goForward, undefined);
105
- };
106
- _this.goBack = function () {
107
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().goBack, undefined);
108
- };
109
- _this.reload = function () {
110
- _this.setState({
111
- viewState: 'LOADING'
112
- });
113
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().reload, undefined);
114
- };
115
- _this.stopLoading = function () {
116
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().stopLoading, undefined);
117
- };
118
- _this.requestFocus = function () {
119
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().requestFocus, undefined);
120
- };
121
- _this.postMessage = function (data) {
122
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().postMessage, [String(data)]);
123
- };
124
- _this.clearFormData = function () {
125
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().clearFormData, undefined);
126
- };
127
- _this.clearCache = function (includeDiskFiles) {
128
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().clearCache, [includeDiskFiles]);
129
- };
130
- _this.clearHistory = function () {
131
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().clearHistory, undefined);
132
- };
133
- /**
134
- * Injects a javascript string into the referenced WebView. Deliberately does not
135
- * return a response because using eval() to return a response breaks this method
136
- * on pages with a Content Security Policy that disallows eval(). If you need that
137
- * functionality, look into postMessage/onMessage.
138
- */
139
- _this.injectJavaScript = function (data) {
140
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().injectJavaScript, [data]);
141
- };
142
- /**
143
- * We return an event with a bunch of fields including:
144
- * url, title, loading, canGoBack, canGoForward
145
- */
146
- _this.updateNavigationState = function (event) {
147
- if (_this.props.onNavigationStateChange) {
148
- _this.props.onNavigationStateChange(event.nativeEvent);
149
- }
150
- };
151
- /**
152
- * Returns the native `WebView` node.
153
- */
154
- _this.getWebViewHandle = function () {
155
- const nodeHandle = findNodeHandle(_this.webViewRef.current);
156
- invariant(nodeHandle != null, 'nodeHandle expected to be non-null');
157
- return nodeHandle;
158
- };
159
- _this.onLoadingStart = function (event) {
160
- const { onLoadStart } = _this.props;
161
- const { url } = event.nativeEvent;
162
- _this.startUrl = url;
163
- if (onLoadStart) {
164
- onLoadStart(event);
165
- }
166
- _this.updateNavigationState(event);
167
- };
168
- _this.onLoadingError = function (event) {
169
- event.persist(); // persist this event because we need to store it
170
- const _a = _this.props; const { onError } = _a; const
171
- { onLoadEnd } = _a;
172
- if (onError) {
173
- onError(event);
174
- }
175
- if (onLoadEnd) {
176
- onLoadEnd(event);
177
- }
178
- console.warn('Encountered an error loading page', event.nativeEvent);
179
- _this.setState({
180
- lastErrorEvent: event.nativeEvent,
181
- viewState: 'ERROR'
182
- });
183
- };
184
- _this.onHttpError = function (event) {
185
- const { onHttpError } = _this.props;
186
- if (onHttpError) {
187
- onHttpError(event);
188
- }
189
- };
190
- _this.onRenderProcessGone = function (event) {
191
- const { onRenderProcessGone } = _this.props;
192
- if (onRenderProcessGone) {
193
- onRenderProcessGone(event);
194
- }
195
- };
196
- _this.onLoadingFinish = function (event) {
197
- const _a = _this.props; const { onLoad } = _a; const
198
- { onLoadEnd } = _a;
199
- const { url } = event.nativeEvent;
200
- if (onLoad) {
201
- onLoad(event);
202
- }
203
- if (onLoadEnd) {
204
- onLoadEnd(event);
205
- }
206
- if (url === _this.startUrl) {
207
- _this.setState({
208
- viewState: 'IDLE'
209
- });
210
- }
211
- _this.updateNavigationState(event);
212
- };
213
- _this.onMessage = function (event) {
214
- const { onMessage } = _this.props;
215
- if (onMessage) {
216
- onMessage(event);
217
- }
218
- };
219
- _this.onLoadingProgress = function (event) {
220
- const { onLoadProgress } = _this.props;
221
- const { progress } = event.nativeEvent;
222
- if (progress === 1) {
223
- _this.setState((state) => {
224
- if (state.viewState === 'LOADING') {
225
- return { viewState: 'IDLE' };
226
- }
227
- return null;
228
- });
229
- }
230
- if (onLoadProgress) {
231
- onLoadProgress(event);
232
- }
233
- };
234
- _this.onShouldStartLoadWithRequestCallback = function (shouldStart, url) {
235
- if (shouldStart) {
236
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().loadUrl, [String(url)]);
237
- }
238
- };
239
- return _this;
29
+ var uniqueRef = 0;
30
+ var WebViewComponent = forwardRef(function (_a, ref) {
31
+ 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.allowsFullscreenVideo, allowsFullscreenVideo = _f === void 0 ? false : _f, _g = _a.allowFileAccess, allowFileAccess = _g === void 0 ? false : _g, _h = _a.saveFormDataDisabled, saveFormDataDisabled = _h === void 0 ? false : _h, _j = _a.cacheEnabled, cacheEnabled = _j === void 0 ? true : _j, _k = _a.androidHardwareAccelerationDisabled, androidHardwareAccelerationDisabled = _k === void 0 ? false : _k, _l = _a.androidLayerType, androidLayerType = _l === void 0 ? "none" : _l, _m = _a.originWhitelist, originWhitelist = _m === void 0 ? defaultOriginWhitelist : _m, _o = _a.setSupportMultipleWindows, setSupportMultipleWindows = _o === void 0 ? true : _o, _p = _a.setBuiltInZoomControls, setBuiltInZoomControls = _p === void 0 ? true : _p, _q = _a.setDisplayZoomControls, setDisplayZoomControls = _q === void 0 ? false : _q, _r = _a.nestedScrollEnabled, nestedScrollEnabled = _r === void 0 ? false : _r, 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, nativeConfig = _a.nativeConfig, onShouldStartLoadWithRequestProp = _a.onShouldStartLoadWithRequest, otherProps = __rest(_a, ["overScrollMode", "javaScriptEnabled", "thirdPartyCookiesEnabled", "scalesPageToFit", "allowsFullscreenVideo", "allowFileAccess", "saveFormDataDisabled", "cacheEnabled", "androidHardwareAccelerationDisabled", "androidLayerType", "originWhitelist", "setSupportMultipleWindows", "setBuiltInZoomControls", "setDisplayZoomControls", "nestedScrollEnabled", "startInLoadingState", "onNavigationStateChange", "onLoadStart", "onError", "onLoad", "onLoadEnd", "onLoadProgress", "onHttpError", "onRenderProcessGone", "onMessage", "renderLoading", "renderError", "style", "containerStyle", "source", "nativeConfig", "onShouldStartLoadWithRequest"]);
32
+ var messagingModuleName = useRef("WebViewMessageHandler".concat(uniqueRef += 1)).current;
33
+ var webViewRef = useRef(null);
34
+ var onShouldStartLoadWithRequestCallback = useCallback(function (shouldStart, url, lockIdentifier) {
35
+ if (lockIdentifier) {
36
+ NativeModules.RNCWebView.onShouldStartLoadWithRequestCallback(shouldStart, lockIdentifier);
37
+ }
38
+ else if (shouldStart) {
39
+ Commands.loadUrl(webViewRef.current, url);
40
+ }
41
+ }, []);
42
+ var _s = useWebWiewLogic({
43
+ onNavigationStateChange: onNavigationStateChange,
44
+ onLoad: onLoad,
45
+ onError: onError,
46
+ onHttpErrorProp: onHttpErrorProp,
47
+ onLoadEnd: onLoadEnd,
48
+ onLoadProgress: onLoadProgress,
49
+ onLoadStart: onLoadStart,
50
+ onRenderProcessGoneProp: onRenderProcessGoneProp,
51
+ onMessageProp: onMessageProp,
52
+ startInLoadingState: startInLoadingState,
53
+ originWhitelist: originWhitelist,
54
+ onShouldStartLoadWithRequestProp: onShouldStartLoadWithRequestProp,
55
+ onShouldStartLoadWithRequestCallback: onShouldStartLoadWithRequestCallback
56
+ }), onLoadingStart = _s.onLoadingStart, onShouldStartLoadWithRequest = _s.onShouldStartLoadWithRequest, onMessage = _s.onMessage, viewState = _s.viewState, setViewState = _s.setViewState, lastErrorEvent = _s.lastErrorEvent, onHttpError = _s.onHttpError, onLoadingError = _s.onLoadingError, onLoadingFinish = _s.onLoadingFinish, onLoadingProgress = _s.onLoadingProgress, onRenderProcessGone = _s.onRenderProcessGone;
57
+ useImperativeHandle(ref, function () { return ({
58
+ goForward: function () { return Commands.goForward(webViewRef.current); },
59
+ goBack: function () { return Commands.goBack(webViewRef.current); },
60
+ reload: function () {
61
+ setViewState('LOADING');
62
+ Commands.reload(webViewRef.current);
63
+ },
64
+ stopLoading: function () { return Commands.stopLoading(webViewRef.current); },
65
+ postMessage: function (data) { return Commands.postMessage(webViewRef.current, data); },
66
+ injectJavaScript: function (data) { return Commands.injectJavaScript(webViewRef.current, data); },
67
+ requestFocus: function () { return Commands.requestFocus(webViewRef.current); },
68
+ clearFormData: function () { return Commands.clearFormData(webViewRef.current); },
69
+ clearCache: function (includeDiskFiles) { return Commands.clearCache(webViewRef.current, includeDiskFiles); },
70
+ clearHistory: function () { return Commands.clearHistory(webViewRef.current); }
71
+ }); }, [setViewState, webViewRef]);
72
+ var directEventCallbacks = useMemo(function () { return ({
73
+ onShouldStartLoadWithRequest: onShouldStartLoadWithRequest,
74
+ onMessage: onMessage
75
+ }); }, [onMessage, onShouldStartLoadWithRequest]);
76
+ useEffect(function () {
77
+ BatchedBridge.registerCallableModule(messagingModuleName, directEventCallbacks);
78
+ }, [messagingModuleName, directEventCallbacks]);
79
+ var otherView = null;
80
+ if (viewState === 'LOADING') {
81
+ otherView = (renderLoading || defaultRenderLoading)();
82
+ }
83
+ else if (viewState === 'ERROR') {
84
+ invariant(lastErrorEvent != null, 'lastErrorEvent expected to be non-null');
85
+ otherView = (renderError || defaultRenderError)(lastErrorEvent.domain, lastErrorEvent.code, lastErrorEvent.description);
240
86
  }
241
- WebView.prototype.render = function () {
242
- const _a = this.props; const { onMessage } = _a; const onShouldStartLoadWithRequestProp = _a.onShouldStartLoadWithRequest; const { originWhitelist } = _a; const { renderError } = _a; const { renderLoading } = _a; const { source } = _a; const { style } = _a; const { containerStyle } = _a; const _b = _a.nativeConfig; const nativeConfig = _b === void 0 ? {} : _b; const
243
- otherProps = __rest(_a, ['onMessage', 'onShouldStartLoadWithRequest', 'originWhitelist', 'renderError', 'renderLoading', 'source', 'style', 'containerStyle', 'nativeConfig']);
244
- let otherView = null;
245
- if (this.state.viewState === 'LOADING') {
246
- otherView = (renderLoading || defaultRenderLoading)();
247
- } else if (this.state.viewState === 'ERROR') {
248
- const errorEvent = this.state.lastErrorEvent;
249
- invariant(errorEvent != null, 'lastErrorEvent expected to be non-null');
250
- otherView = (renderError || defaultRenderError)(errorEvent.domain, errorEvent.code, errorEvent.description);
251
- } else if (this.state.viewState !== 'IDLE') {
252
- console.error(`RNCWebView invalid state encountered: ${this.state.viewState}`);
87
+ else if (viewState !== 'IDLE') {
88
+ console.error("RNCWebView invalid state encountered: ".concat(viewState));
89
+ }
90
+ var webViewStyles = [styles.container, styles.webView, style];
91
+ var webViewContainerStyle = [styles.container, containerStyle];
92
+ if (typeof source !== "number" && source && 'method' in source) {
93
+ if (source.method === 'POST' && source.headers) {
94
+ console.warn('WebView: `source.headers` is not supported when using POST.');
253
95
  }
254
- const webViewStyles = [styles.container, styles.webView, style];
255
- const webViewContainerStyle = [styles.container, containerStyle];
256
- if (typeof source !== 'number' && source && 'method' in source) {
257
- if (source.method === 'POST' && source.headers) {
258
- console.warn('WebView: `source.headers` is not supported when using POST.');
259
- } else if (source.method === 'GET' && source.body) {
260
- console.warn('WebView: `source.body` is not supported when using GET.');
261
- }
96
+ else if (source.method === 'GET' && source.body) {
97
+ console.warn('WebView: `source.body` is not supported when using GET.');
262
98
  }
263
- const NativeWebView = nativeConfig.component || RNCWebView;
264
- const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(this.onShouldStartLoadWithRequestCallback,
265
- // casting cause it's in the default props
266
- originWhitelist, onShouldStartLoadWithRequestProp);
267
- const webView = (
268
- <NativeWebView
269
- key="webViewKey"
270
- {...otherProps}
271
- messagingEnabled={typeof onMessage === 'function'}
272
- messagingModuleName={this.messagingModuleName}
273
- onLoadingError={this.onLoadingError}
274
- onLoadingFinish={this.onLoadingFinish}
275
- onLoadingProgress={this.onLoadingProgress}
276
- onLoadingStart={this.onLoadingStart}
277
- onHttpError={this.onHttpError}
278
- onRenderProcessGone={this.onRenderProcessGone}
279
- onMessage={this.onMessage}
280
- onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
281
- ref={this.webViewRef}
282
- // TODO: find a better way to type this.
283
- source={resolveAssetSource(source)}
284
- style={webViewStyles}
285
- {...nativeConfig.props}
286
- />
287
- );
288
- return (
289
- <View style={webViewContainerStyle}>
290
- {webView}
291
- {otherView}
292
- </View>
293
- );
294
- };
295
- WebView.defaultProps = {
296
- overScrollMode: 'always',
297
- javaScriptEnabled: true,
298
- thirdPartyCookiesEnabled: true,
299
- scalesPageToFit: true,
300
- allowsFullscreenVideo: false,
301
- allowFileAccess: false,
302
- saveFormDataDisabled: false,
303
- cacheEnabled: true,
304
- androidHardwareAccelerationDisabled: false,
305
- androidLayerType: 'none',
306
- originWhitelist: defaultOriginWhitelist
307
- };
308
- WebView.isFileUploadSupported = function () {
309
- return __awaiter(void 0, void 0, void 0, function () {
310
- return __generator(this, (_a) =>
311
- // native implementation should return "true" only for Android 5+
312
- [2 /* return */, NativeModules.RNCWebView.isFileUploadSupported()]
313
- );
314
- });
315
- };
316
- return WebView;
317
- }(React.Component));
99
+ }
100
+ var NativeWebView = (nativeConfig === null || nativeConfig === void 0 ? void 0 : nativeConfig.component) || RNCWebView;
101
+ 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} ref={webViewRef}
102
+ // TODO: find a better way to type this.
103
+ source={resolveAssetSource(source)} style={webViewStyles} overScrollMode={overScrollMode} javaScriptEnabled={javaScriptEnabled} thirdPartyCookiesEnabled={thirdPartyCookiesEnabled} scalesPageToFit={scalesPageToFit} allowsFullscreenVideo={allowsFullscreenVideo} allowFileAccess={allowFileAccess} saveFormDataDisabled={saveFormDataDisabled} cacheEnabled={cacheEnabled} androidHardwareAccelerationDisabled={androidHardwareAccelerationDisabled} androidLayerType={androidLayerType} setSupportMultipleWindows={setSupportMultipleWindows} setBuiltInZoomControls={setBuiltInZoomControls} setDisplayZoomControls={setDisplayZoomControls} nestedScrollEnabled={nestedScrollEnabled} {...nativeConfig === null || nativeConfig === void 0 ? void 0 : nativeConfig.props}/>;
104
+ return (<View style={webViewContainerStyle}>
105
+ {webView}
106
+ {otherView}
107
+ </View>);
108
+ });
109
+ // native implementation should return "true" only for Android 5+
110
+ var isFileUploadSupported = NativeModules.RNCWebView.isFileUploadSupported();
111
+ var WebView = Object.assign(WebViewComponent, { isFileUploadSupported: isFileUploadSupported });
318
112
  export default WebView;
package/lib/WebView.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import { IOSWebViewProps, AndroidWebViewProps } from './WebViewTypes';
3
- export declare type WebViewProps = IOSWebViewProps & AndroidWebViewProps;
2
+ import { IOSWebViewProps, AndroidWebViewProps, WindowsWebViewProps } from './WebViewTypes';
3
+ export declare type WebViewProps = IOSWebViewProps & AndroidWebViewProps & WindowsWebViewProps;
4
4
  declare const WebView: React.FunctionComponent<WebViewProps>;
5
5
  export { WebView };
6
6
  export default WebView;
@@ -1 +1 @@
1
- {"version":3,"file":"WebView.d.ts","sourceRoot":"","sources":["../src/WebView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEtE,oBAAY,YAAY,GAAG,eAAe,GAAG,mBAAmB,CAAC;AAMjE,QAAA,MAAM,OAAO,EAAE,KAAK,CAAC,iBAAiB,CAAC,YAAY,CAMlD,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,CAAC;AACnB,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"WebView.d.ts","sourceRoot":"","sources":["../src/WebView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE3F,oBAAY,YAAY,GAAG,eAAe,GAAG,mBAAmB,GAAG,mBAAmB,CAAC;AAIvF,QAAA,MAAM,OAAO,EAAE,KAAK,CAAC,iBAAiB,CAAC,YAAY,CAMlD,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,CAAC;AACnB,eAAe,OAAO,CAAC"}