@momo-kits/webview 0.0.59-rc.1 → 0.0.60-beta.10

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.
@@ -1,284 +0,0 @@
1
- /* eslint-disable */
2
-
3
- var __extends = (this && this.__extends) || (function () {
4
- var extendStatics = function (d, b) {
5
- extendStatics = Object.setPrototypeOf ||
6
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
8
- return extendStatics(d, b);
9
- };
10
- return function (d, b) {
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
- return new (P || (P = Promise))(function (resolve, reject) {
19
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
- step((generator = generator.apply(thisArg, _arguments || [])).next());
23
- });
24
- };
25
- var __generator = (this && this.__generator) || function (thisArg, body) {
26
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
- function verb(n) { return function (v) { return step([n, v]); }; }
29
- function step(op) {
30
- if (f) throw new TypeError("Generator is already executing.");
31
- while (_) try {
32
- 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;
33
- if (y = 0, t) op = [op[0] & 2, t.value];
34
- switch (op[0]) {
35
- case 0: case 1: t = op; break;
36
- case 4: _.label++; return { value: op[1], done: false };
37
- case 5: _.label++; y = op[1]; op = [0]; continue;
38
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
- default:
40
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
- if (t[2]) _.ops.pop();
45
- _.trys.pop(); continue;
46
- }
47
- op = body.call(thisArg, _);
48
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
- }
51
- };
52
- var __rest = (this && this.__rest) || function (s, e) {
53
- var t = {};
54
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
55
- t[p] = s[p];
56
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
57
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
58
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
59
- t[p[i]] = s[p[i]];
60
- }
61
- return t;
62
- };
63
- import React from 'react';
64
- import { UIManager as NotTypedUIManager, View, requireNativeComponent, NativeModules, Image, findNodeHandle, } from 'react-native';
65
- import invariant from 'invariant';
66
- import { defaultOriginWhitelist, createOnShouldStartLoadWithRequest, defaultRenderError, defaultRenderLoading, } from './WebViewShared';
67
- import styles from './WebView.styles';
68
- var UIManager = NotTypedUIManager;
69
- var resolveAssetSource = Image.resolveAssetSource;
70
- var processDecelerationRate = function (decelerationRate) {
71
- var newDecelerationRate = decelerationRate;
72
- if (newDecelerationRate === 'normal') {
73
- newDecelerationRate = 0.998;
74
- }
75
- else if (newDecelerationRate === 'fast') {
76
- newDecelerationRate = 0.99;
77
- }
78
- return newDecelerationRate;
79
- };
80
- var RNCWebViewManager = NativeModules.RNCWebViewManager;
81
- var RNCWebView = requireNativeComponent('RNCWebView');
82
- var WebView = /** @class */ (function (_super) {
83
- __extends(WebView, _super);
84
- function WebView() {
85
- var _this = _super !== null && _super.apply(this, arguments) || this;
86
- _this.state = {
87
- viewState: _this.props.startInLoadingState ? 'LOADING' : 'IDLE',
88
- lastErrorEvent: null
89
- };
90
- _this.webViewRef = React.createRef();
91
- // eslint-disable-next-line react/sort-comp
92
- _this.getCommands = function () { return UIManager.getViewManagerConfig('RNCWebView').Commands; };
93
- /**
94
- * Go forward one page in the web view's history.
95
- */
96
- _this.goForward = function () {
97
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().goForward, undefined);
98
- };
99
- /**
100
- * Go back one page in the web view's history.
101
- */
102
- _this.goBack = function () {
103
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().goBack, undefined);
104
- };
105
- /**
106
- * Reloads the current page.
107
- */
108
- _this.reload = function () {
109
- _this.setState({ viewState: 'LOADING' });
110
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().reload, undefined);
111
- };
112
- /**
113
- * Stop loading the current page.
114
- */
115
- _this.stopLoading = function () {
116
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().stopLoading, undefined);
117
- };
118
- /**
119
- * Request focus on WebView rendered page.
120
- */
121
- _this.requestFocus = function () {
122
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().requestFocus, undefined);
123
- };
124
- /**
125
- * Posts a message to the web view, which will emit a `message` event.
126
- * Accepts one argument, `data`, which must be a string.
127
- *
128
- * In your webview, you'll need to something like the following.
129
- *
130
- * ```js
131
- * document.addEventListener('message', e => { document.title = e.data; });
132
- * ```
133
- */
134
- _this.postMessage = function (data) {
135
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().postMessage, [String(data)]);
136
- };
137
- /**
138
- * Injects a javascript string into the referenced WebView. Deliberately does not
139
- * return a response because using eval() to return a response breaks this method
140
- * on pages with a Content Security Policy that disallows eval(). If you need that
141
- * functionality, look into postMessage/onMessage.
142
- */
143
- _this.injectJavaScript = function (data) {
144
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().injectJavaScript, [data]);
145
- };
146
- /**
147
- * We return an event with a bunch of fields including:
148
- * url, title, loading, canGoBack, canGoForward
149
- */
150
- _this.updateNavigationState = function (event) {
151
- if (_this.props.onNavigationStateChange) {
152
- _this.props.onNavigationStateChange(event.nativeEvent);
153
- }
154
- };
155
- /**
156
- * Returns the native `WebView` node.
157
- */
158
- _this.getWebViewHandle = function () {
159
- var nodeHandle = findNodeHandle(_this.webViewRef.current);
160
- invariant(nodeHandle != null, 'nodeHandle expected to be non-null');
161
- return nodeHandle;
162
- };
163
- _this.onLoadingStart = function (event) {
164
- var onLoadStart = _this.props.onLoadStart;
165
- if (onLoadStart) {
166
- onLoadStart(event);
167
- }
168
- _this.updateNavigationState(event);
169
- };
170
- _this.onLoadingError = function (event) {
171
- event.persist(); // persist this event because we need to store it
172
- var _a = _this.props, onError = _a.onError, onLoadEnd = _a.onLoadEnd;
173
- if (onLoadEnd) {
174
- onLoadEnd(event);
175
- }
176
- if (onError) {
177
- onError(event);
178
- }
179
- console.warn('Encountered an error loading page', event.nativeEvent);
180
- _this.setState({
181
- lastErrorEvent: event.nativeEvent,
182
- viewState: 'ERROR'
183
- });
184
- };
185
- _this.onHttpError = function (event) {
186
- var onHttpError = _this.props.onHttpError;
187
- if (onHttpError) {
188
- onHttpError(event);
189
- }
190
- };
191
- _this.onLoadingFinish = function (event) {
192
- var _a = _this.props, onLoad = _a.onLoad, onLoadEnd = _a.onLoadEnd;
193
- if (onLoad) {
194
- onLoad(event);
195
- }
196
- if (onLoadEnd) {
197
- onLoadEnd(event);
198
- }
199
- _this.setState({
200
- viewState: 'IDLE'
201
- });
202
- _this.updateNavigationState(event);
203
- };
204
- _this.onMessage = function (event) {
205
- var onMessage = _this.props.onMessage;
206
- if (onMessage) {
207
- onMessage(event);
208
- }
209
- };
210
- _this.onLoadingProgress = function (event) {
211
- var onLoadProgress = _this.props.onLoadProgress;
212
- if (onLoadProgress) {
213
- onLoadProgress(event);
214
- }
215
- };
216
- _this.onShouldStartLoadWithRequestCallback = function (shouldStart, _url, lockIdentifier) {
217
- var viewManager = (_this.props.nativeConfig && _this.props.nativeConfig.viewManager)
218
- || RNCWebViewManager;
219
- viewManager.startLoadWithResult(!!shouldStart, lockIdentifier);
220
- };
221
- _this.onContentProcessDidTerminate = function (event) {
222
- var onContentProcessDidTerminate = _this.props.onContentProcessDidTerminate;
223
- if (onContentProcessDidTerminate) {
224
- onContentProcessDidTerminate(event);
225
- }
226
- };
227
- return _this;
228
- }
229
- WebView.prototype.componentDidUpdate = function (prevProps) {
230
- this.showRedboxOnPropChanges(prevProps, 'allowsInlineMediaPlayback');
231
- this.showRedboxOnPropChanges(prevProps, 'incognito');
232
- this.showRedboxOnPropChanges(prevProps, 'mediaPlaybackRequiresUserAction');
233
- this.showRedboxOnPropChanges(prevProps, 'dataDetectorTypes');
234
- };
235
- WebView.prototype.showRedboxOnPropChanges = function (prevProps, propName) {
236
- if (this.props[propName] !== prevProps[propName]) {
237
- console.error("Changes to property " + propName + " do nothing after the initial render.");
238
- }
239
- };
240
- WebView.prototype.render = function () {
241
- var _a = this.props, decelerationRateProp = _a.decelerationRate, _b = _a.nativeConfig, nativeConfig = _b === void 0 ? {} : _b, onMessage = _a.onMessage, onShouldStartLoadWithRequestProp = _a.onShouldStartLoadWithRequest, originWhitelist = _a.originWhitelist, renderError = _a.renderError, renderLoading = _a.renderLoading, _c = _a.injectedJavaScriptForMainFrameOnly, injectedJavaScriptForMainFrameOnly = _c === void 0 ? true : _c, _d = _a.injectedJavaScriptBeforeContentLoadedForMainFrameOnly, injectedJavaScriptBeforeContentLoadedForMainFrameOnly = _d === void 0 ? true : _d, style = _a.style, containerStyle = _a.containerStyle, otherProps = __rest(_a, ["decelerationRate", "nativeConfig", "onMessage", "onShouldStartLoadWithRequest", "originWhitelist", "renderError", "renderLoading", "injectedJavaScriptForMainFrameOnly", "injectedJavaScriptBeforeContentLoadedForMainFrameOnly", "style", "containerStyle"]);
242
- var otherView = null;
243
- if (this.state.viewState === 'LOADING') {
244
- otherView = (renderLoading || defaultRenderLoading)();
245
- }
246
- else if (this.state.viewState === 'ERROR') {
247
- var errorEvent = this.state.lastErrorEvent;
248
- invariant(errorEvent != null, 'lastErrorEvent expected to be non-null');
249
- otherView = (renderError || defaultRenderError)(errorEvent.domain, errorEvent.code, errorEvent.description);
250
- }
251
- else if (this.state.viewState !== 'IDLE') {
252
- console.error("RNCWebView invalid state encountered: " + this.state.viewState);
253
- }
254
- var webViewStyles = [styles.container, styles.webView, style];
255
- var webViewContainerStyle = [styles.container, containerStyle];
256
- var onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(this.onShouldStartLoadWithRequestCallback,
257
- // casting cause it's in the default props
258
- originWhitelist, onShouldStartLoadWithRequestProp);
259
- var decelerationRate = processDecelerationRate(decelerationRateProp);
260
- var NativeWebView = nativeConfig.component
261
- || RNCWebView;
262
- var webView = (<NativeWebView key="webViewKey" {...otherProps} decelerationRate={decelerationRate} messagingEnabled={typeof onMessage === 'function'} onLoadingError={this.onLoadingError} onLoadingFinish={this.onLoadingFinish} onLoadingProgress={this.onLoadingProgress} onFileDownload={this.props.onFileDownload} onLoadingStart={this.onLoadingStart} onHttpError={this.onHttpError} onMessage={this.onMessage} onScroll={this.props.onScroll} onShouldStartLoadWithRequest={onShouldStartLoadWithRequest} onContentProcessDidTerminate={this.onContentProcessDidTerminate} injectedJavaScript={this.props.injectedJavaScript} injectedJavaScriptBeforeContentLoaded={this.props.injectedJavaScriptBeforeContentLoaded} injectedJavaScriptForMainFrameOnly={injectedJavaScriptForMainFrameOnly} injectedJavaScriptBeforeContentLoadedForMainFrameOnly={injectedJavaScriptBeforeContentLoadedForMainFrameOnly} ref={this.webViewRef}
263
- // TODO: find a better way to type this.
264
- source={resolveAssetSource(this.props.source)} style={webViewStyles} {...nativeConfig.props}/>);
265
- return (<View style={webViewContainerStyle}>
266
- {webView}
267
- {otherView}
268
- </View>);
269
- };
270
- WebView.defaultProps = {
271
- javaScriptEnabled: true,
272
- cacheEnabled: true,
273
- originWhitelist: defaultOriginWhitelist,
274
- useSharedProcessPool: true
275
- };
276
- WebView.isFileUploadSupported = function () { return __awaiter(void 0, void 0, void 0, function () {
277
- return __generator(this, function (_a) {
278
- // no native implementation for iOS, depends only on permissions
279
- return [2 /*return*/, true];
280
- });
281
- }); };
282
- return WebView;
283
- }(React.Component));
284
- export default WebView;
package/lib/WebView.js DELETED
@@ -1,16 +0,0 @@
1
- import React from 'react';
2
- import { View } from 'react-native';
3
- // This "dummy" WebView is to render something for unsupported platforms,
4
- // like for example Expo SDK "web" platform. It matches the previous react-native
5
- // implementation which is produced by Expo SDK 37.0.0.1 implementation, with
6
- // similar interface than the native ones have.
7
- const WebView = () => (
8
- <View style={{
9
- alignSelf: 'flex-start',
10
- borderColor: 'rgb(255, 0, 0)',
11
- borderWidth: 1
12
- }}
13
- />
14
- );
15
- export { WebView };
16
- export default WebView;
@@ -1,83 +0,0 @@
1
- import React from 'react';
2
- import { WebViewErrorEvent, WebViewHttpErrorEvent, WebViewMessageEvent, WebViewNavigationEvent, WebViewProgressEvent, WebViewTerminatedEvent, MacOSWebViewProps, NativeWebViewMacOS, State } from './WebViewTypes';
3
- declare class WebView extends React.Component<MacOSWebViewProps, State> {
4
- static defaultProps: {
5
- javaScriptEnabled: boolean;
6
- cacheEnabled: boolean;
7
- originWhitelist: string[];
8
- useSharedProcessPool: boolean;
9
- };
10
- static isFileUploadSupported: () => Promise<boolean>;
11
- state: State;
12
- webViewRef: React.RefObject<NativeWebViewMacOS>;
13
- getCommands: () => {
14
- goForward: number;
15
- goBack: number;
16
- reload: number;
17
- stopLoading: number;
18
- postMessage: number;
19
- injectJavaScript: number;
20
- loadUrl: number;
21
- requestFocus: number;
22
- };
23
- /**
24
- * Go forward one page in the web view's history.
25
- */
26
- goForward: () => void;
27
- /**
28
- * Go back one page in the web view's history.
29
- */
30
- goBack: () => void;
31
- /**
32
- * Reloads the current page.
33
- */
34
- reload: () => void;
35
- /**
36
- * Stop loading the current page.
37
- */
38
- stopLoading: () => void;
39
- /**
40
- * Request focus on WebView rendered page.
41
- */
42
- requestFocus: () => void;
43
- /**
44
- * Posts a message to the web view, which will emit a `message` event.
45
- * Accepts one argument, `data`, which must be a string.
46
- *
47
- * In your webview, you'll need to something like the following.
48
- *
49
- * ```js
50
- * document.addEventListener('message', e => { document.title = e.data; });
51
- * ```
52
- */
53
- postMessage: (data: string) => void;
54
- /**
55
- * Injects a javascript string into the referenced WebView. Deliberately does not
56
- * return a response because using eval() to return a response breaks this method
57
- * on pages with a Content Security Policy that disallows eval(). If you need that
58
- * functionality, look into postMessage/onMessage.
59
- */
60
- injectJavaScript: (data: string) => void;
61
- /**
62
- * We return an event with a bunch of fields including:
63
- * url, title, loading, canGoBack, canGoForward
64
- */
65
- updateNavigationState: (event: WebViewNavigationEvent) => void;
66
- /**
67
- * Returns the native `WebView` node.
68
- */
69
- getWebViewHandle: () => number;
70
- onLoadingStart: (event: WebViewNavigationEvent) => void;
71
- onLoadingError: (event: WebViewErrorEvent) => void;
72
- onHttpError: (event: WebViewHttpErrorEvent) => void;
73
- onLoadingFinish: (event: WebViewNavigationEvent) => void;
74
- onMessage: (event: WebViewMessageEvent) => void;
75
- onLoadingProgress: (event: WebViewProgressEvent) => void;
76
- onShouldStartLoadWithRequestCallback: (shouldStart: boolean, _url: string, lockIdentifier: number) => void;
77
- onContentProcessDidTerminate: (event: WebViewTerminatedEvent) => void;
78
- componentDidUpdate(prevProps: MacOSWebViewProps): void;
79
- showRedboxOnPropChanges(prevProps: MacOSWebViewProps, propName: keyof MacOSWebViewProps): void;
80
- render(): JSX.Element;
81
- }
82
- export default WebView;
83
- //# sourceMappingURL=WebView.macos.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebView.macos.d.ts","sourceRoot":"","sources":["../src/WebView.macos.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAkB1B,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAElB,KAAK,EAEN,MAAM,gBAAgB,CAAC;AAcxB,cAAM,OAAQ,SAAQ,KAAK,CAAC,SAAS,CAAC,iBAAiB,EAAE,KAAK,CAAC;IAC7D,MAAM,CAAC,YAAY;;;;;MAKjB;IAEF,MAAM,CAAC,qBAAqB,yBAG1B;IAEF,KAAK,EAAE,KAAK,CAGV;IAEF,UAAU,sCAAyC;IAGnD,WAAW;;;;;;;;;MAA+D;IAE1E;;OAEG;IACH,SAAS,aAMP;IAEF;;OAEG;IACH,MAAM,aAMJ;IAEF;;OAEG;IACH,MAAM,aAOJ;IAEF;;OAEG;IACH,WAAW,aAMT;IAEF;;OAEG;IACH,YAAY,aAMV;IAEF;;;;;;;;;OASG;IACH,WAAW,yBAMT;IAEF;;;;;OAKG;IACH,gBAAgB,yBAMd;IAEF;;;OAGG;IACH,qBAAqB,0CAInB;IAEF;;OAEG;IACH,gBAAgB,eAId;IAEF,cAAc,0CAMZ;IAEF,cAAc,qCAeZ;IAEF,WAAW,yCAKV;IAED,eAAe,0CAYb;IAEF,SAAS,uCAKP;IAEF,iBAAiB,wCAKf;IAEF,oCAAoC,uEAUlC;IAEF,4BAA4B,0CAK1B;IAEF,kBAAkB,CAAC,SAAS,EAAE,iBAAiB;IAM/C,uBAAuB,CACrB,SAAS,EAAE,iBAAiB,EAC5B,QAAQ,EAAE,MAAM,iBAAiB;IASnC,MAAM;CA0EP;AAED,eAAe,OAAO,CAAC"}
@@ -1,272 +0,0 @@
1
- /* eslint-disable */
2
-
3
- var __extends = (this && this.__extends) || (function () {
4
- var extendStatics = function (d, b) {
5
- extendStatics = Object.setPrototypeOf ||
6
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
7
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
8
- return extendStatics(d, b);
9
- };
10
- return function (d, b) {
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
- return new (P || (P = Promise))(function (resolve, reject) {
19
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
- step((generator = generator.apply(thisArg, _arguments || [])).next());
23
- });
24
- };
25
- var __generator = (this && this.__generator) || function (thisArg, body) {
26
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
- function verb(n) { return function (v) { return step([n, v]); }; }
29
- function step(op) {
30
- if (f) throw new TypeError("Generator is already executing.");
31
- while (_) try {
32
- 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;
33
- if (y = 0, t) op = [op[0] & 2, t.value];
34
- switch (op[0]) {
35
- case 0: case 1: t = op; break;
36
- case 4: _.label++; return { value: op[1], done: false };
37
- case 5: _.label++; y = op[1]; op = [0]; continue;
38
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
- default:
40
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
- if (t[2]) _.ops.pop();
45
- _.trys.pop(); continue;
46
- }
47
- op = body.call(thisArg, _);
48
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
- }
51
- };
52
- var __rest = (this && this.__rest) || function (s, e) {
53
- var t = {};
54
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
55
- t[p] = s[p];
56
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
57
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
58
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
59
- t[p[i]] = s[p[i]];
60
- }
61
- return t;
62
- };
63
- import React from 'react';
64
- import { UIManager as NotTypedUIManager, View, requireNativeComponent, NativeModules, Image, findNodeHandle, } from 'react-native';
65
- import invariant from 'invariant';
66
- import { defaultOriginWhitelist, createOnShouldStartLoadWithRequest, defaultRenderError, defaultRenderLoading, } from './WebViewShared';
67
- import styles from './WebView.styles';
68
- var UIManager = NotTypedUIManager;
69
- var resolveAssetSource = Image.resolveAssetSource;
70
- var RNCWebViewManager = NativeModules.RNCWebViewManager;
71
- var RNCWebView = requireNativeComponent('RNCWebView');
72
- var WebView = /** @class */ (function (_super) {
73
- __extends(WebView, _super);
74
- function WebView() {
75
- var _this = _super !== null && _super.apply(this, arguments) || this;
76
- _this.state = {
77
- viewState: _this.props.startInLoadingState ? 'LOADING' : 'IDLE',
78
- lastErrorEvent: null
79
- };
80
- _this.webViewRef = React.createRef();
81
- // eslint-disable-next-line react/sort-comp
82
- _this.getCommands = function () { return UIManager.getViewManagerConfig('RNCWebView').Commands; };
83
- /**
84
- * Go forward one page in the web view's history.
85
- */
86
- _this.goForward = function () {
87
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().goForward, undefined);
88
- };
89
- /**
90
- * Go back one page in the web view's history.
91
- */
92
- _this.goBack = function () {
93
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().goBack, undefined);
94
- };
95
- /**
96
- * Reloads the current page.
97
- */
98
- _this.reload = function () {
99
- _this.setState({ viewState: 'LOADING' });
100
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().reload, undefined);
101
- };
102
- /**
103
- * Stop loading the current page.
104
- */
105
- _this.stopLoading = function () {
106
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().stopLoading, undefined);
107
- };
108
- /**
109
- * Request focus on WebView rendered page.
110
- */
111
- _this.requestFocus = function () {
112
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().requestFocus, undefined);
113
- };
114
- /**
115
- * Posts a message to the web view, which will emit a `message` event.
116
- * Accepts one argument, `data`, which must be a string.
117
- *
118
- * In your webview, you'll need to something like the following.
119
- *
120
- * ```js
121
- * document.addEventListener('message', e => { document.title = e.data; });
122
- * ```
123
- */
124
- _this.postMessage = function (data) {
125
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().postMessage, [String(data)]);
126
- };
127
- /**
128
- * Injects a javascript string into the referenced WebView. Deliberately does not
129
- * return a response because using eval() to return a response breaks this method
130
- * on pages with a Content Security Policy that disallows eval(). If you need that
131
- * functionality, look into postMessage/onMessage.
132
- */
133
- _this.injectJavaScript = function (data) {
134
- UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().injectJavaScript, [data]);
135
- };
136
- /**
137
- * We return an event with a bunch of fields including:
138
- * url, title, loading, canGoBack, canGoForward
139
- */
140
- _this.updateNavigationState = function (event) {
141
- if (_this.props.onNavigationStateChange) {
142
- _this.props.onNavigationStateChange(event.nativeEvent);
143
- }
144
- };
145
- /**
146
- * Returns the native `WebView` node.
147
- */
148
- _this.getWebViewHandle = function () {
149
- var nodeHandle = findNodeHandle(_this.webViewRef.current);
150
- invariant(nodeHandle != null, 'nodeHandle expected to be non-null');
151
- return nodeHandle;
152
- };
153
- _this.onLoadingStart = function (event) {
154
- var onLoadStart = _this.props.onLoadStart;
155
- if (onLoadStart) {
156
- onLoadStart(event);
157
- }
158
- _this.updateNavigationState(event);
159
- };
160
- _this.onLoadingError = function (event) {
161
- event.persist(); // persist this event because we need to store it
162
- var _a = _this.props, onError = _a.onError, onLoadEnd = _a.onLoadEnd;
163
- if (onLoadEnd) {
164
- onLoadEnd(event);
165
- }
166
- if (onError) {
167
- onError(event);
168
- }
169
- console.warn('Encountered an error loading page', event.nativeEvent);
170
- _this.setState({
171
- lastErrorEvent: event.nativeEvent,
172
- viewState: 'ERROR'
173
- });
174
- };
175
- _this.onHttpError = function (event) {
176
- var onHttpError = _this.props.onHttpError;
177
- if (onHttpError) {
178
- onHttpError(event);
179
- }
180
- };
181
- _this.onLoadingFinish = function (event) {
182
- var _a = _this.props, onLoad = _a.onLoad, onLoadEnd = _a.onLoadEnd;
183
- if (onLoad) {
184
- onLoad(event);
185
- }
186
- if (onLoadEnd) {
187
- onLoadEnd(event);
188
- }
189
- _this.setState({
190
- viewState: 'IDLE'
191
- });
192
- _this.updateNavigationState(event);
193
- };
194
- _this.onMessage = function (event) {
195
- var onMessage = _this.props.onMessage;
196
- if (onMessage) {
197
- onMessage(event);
198
- }
199
- };
200
- _this.onLoadingProgress = function (event) {
201
- var onLoadProgress = _this.props.onLoadProgress;
202
- if (onLoadProgress) {
203
- onLoadProgress(event);
204
- }
205
- };
206
- _this.onShouldStartLoadWithRequestCallback = function (shouldStart, _url, lockIdentifier) {
207
- var viewManager = (_this.props.nativeConfig && _this.props.nativeConfig.viewManager)
208
- || RNCWebViewManager;
209
- viewManager.startLoadWithResult(!!shouldStart, lockIdentifier);
210
- };
211
- _this.onContentProcessDidTerminate = function (event) {
212
- var onContentProcessDidTerminate = _this.props.onContentProcessDidTerminate;
213
- if (onContentProcessDidTerminate) {
214
- onContentProcessDidTerminate(event);
215
- }
216
- };
217
- return _this;
218
- }
219
- WebView.prototype.componentDidUpdate = function (prevProps) {
220
- this.showRedboxOnPropChanges(prevProps, 'allowsInlineMediaPlayback');
221
- this.showRedboxOnPropChanges(prevProps, 'incognito');
222
- this.showRedboxOnPropChanges(prevProps, 'mediaPlaybackRequiresUserAction');
223
- };
224
- WebView.prototype.showRedboxOnPropChanges = function (prevProps, propName) {
225
- if (this.props[propName] !== prevProps[propName]) {
226
- console.error("Changes to property " + propName + " do nothing after the initial render.");
227
- }
228
- };
229
- WebView.prototype.render = function () {
230
- var _a = this.props, _b = _a.nativeConfig, nativeConfig = _b === void 0 ? {} : _b, onMessage = _a.onMessage, onShouldStartLoadWithRequestProp = _a.onShouldStartLoadWithRequest, originWhitelist = _a.originWhitelist, renderError = _a.renderError, renderLoading = _a.renderLoading, style = _a.style, containerStyle = _a.containerStyle, otherProps = __rest(_a, ["nativeConfig", "onMessage", "onShouldStartLoadWithRequest", "originWhitelist", "renderError", "renderLoading", "style", "containerStyle"]);
231
- var otherView = null;
232
- if (this.state.viewState === 'LOADING') {
233
- otherView = (renderLoading || defaultRenderLoading)();
234
- }
235
- else if (this.state.viewState === 'ERROR') {
236
- var errorEvent = this.state.lastErrorEvent;
237
- invariant(errorEvent != null, 'lastErrorEvent expected to be non-null');
238
- otherView = (renderError || defaultRenderError)(errorEvent.domain, errorEvent.code, errorEvent.description);
239
- }
240
- else if (this.state.viewState !== 'IDLE') {
241
- console.error("RNCWebView invalid state encountered: " + this.state.viewState);
242
- }
243
- var webViewStyles = [styles.container, styles.webView, style];
244
- var webViewContainerStyle = [styles.container, containerStyle];
245
- var onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(this.onShouldStartLoadWithRequestCallback,
246
- // casting cause it's in the default props
247
- originWhitelist, onShouldStartLoadWithRequestProp);
248
- var NativeWebView = nativeConfig.component
249
- || RNCWebView;
250
- var webView = (<NativeWebView key="webViewKey" {...otherProps} messagingEnabled={typeof onMessage === 'function'} onLoadingError={this.onLoadingError} onLoadingFinish={this.onLoadingFinish} onLoadingProgress={this.onLoadingProgress} onLoadingStart={this.onLoadingStart} onHttpError={this.onHttpError} onMessage={this.onMessage} onScroll={this.props.onScroll} onShouldStartLoadWithRequest={onShouldStartLoadWithRequest} onContentProcessDidTerminate={this.onContentProcessDidTerminate} ref={this.webViewRef}
251
- // TODO: find a better way to type this.
252
- source={resolveAssetSource(this.props.source)} style={webViewStyles} {...nativeConfig.props}/>);
253
- return (<View style={webViewContainerStyle}>
254
- {webView}
255
- {otherView}
256
- </View>);
257
- };
258
- WebView.defaultProps = {
259
- javaScriptEnabled: true,
260
- cacheEnabled: true,
261
- originWhitelist: defaultOriginWhitelist,
262
- useSharedProcessPool: true
263
- };
264
- WebView.isFileUploadSupported = function () { return __awaiter(void 0, void 0, void 0, function () {
265
- return __generator(this, function (_a) {
266
- // no native implementation for macOS, depends only on permissions
267
- return [2 /*return*/, true];
268
- });
269
- }); };
270
- return WebView;
271
- }(React.Component));
272
- export default WebView;
@@ -1,12 +0,0 @@
1
- import { ViewStyle, TextStyle } from 'react-native';
2
- interface Styles {
3
- container: ViewStyle;
4
- errorText: TextStyle;
5
- errorTextTitle: TextStyle;
6
- loadingOrErrorView: ViewStyle;
7
- webView: ViewStyle;
8
- loadingProgressBar: ViewStyle;
9
- }
10
- declare const styles: Styles;
11
- export default styles;
12
- //# sourceMappingURL=WebView.styles.d.ts.map