@momo-kits/webview 0.0.4-beta → 0.0.7
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.
- package/index.js +4 -1
- package/lib/WebView.android.js +318 -1
- package/lib/WebView.ios.js +284 -1
- package/lib/WebView.js +16 -1
- package/lib/WebView.macos.js +272 -1
- package/lib/WebView.styles.js +35 -1
- package/lib/WebView.windows.js +189 -1
- package/lib/WebViewShared.js +61 -1
- package/lib/WebViewTypes.js +48 -1
- package/package.json +3 -10
- package/publish.sh +1 -1
- package/babel.config.js +0 -1
package/index.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import WebView from './lib/WebView';
|
|
3
|
+
|
|
4
|
+
export default WebView;
|
package/lib/WebView.android.js
CHANGED
|
@@ -1 +1,318 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends"));var _react=_interopRequireDefault(require("react"));var _reactNative=require("react-native");var _BatchedBridge=_interopRequireDefault(require("react-native/Libraries/BatchedBridge/BatchedBridge"));var _invariant=_interopRequireDefault(require("invariant"));var _WebViewShared=require("./WebViewShared");var _WebView=_interopRequireDefault(require("./WebView.styles"));var _jsxFileName="/Users/trinh.ho2/momo-folk/kits/src/libs/webview/dist/lib/WebView.android.js";var __extends=this&&this.__extends||function(){var _extendStatics=function extendStatics(d,b){_extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b;}||function(d,b){for(var p in b){if(b.hasOwnProperty(p))d[p]=b[p];}};return _extendStatics(d,b);};return function(d,b){_extendStatics(d,b);function __(){this.constructor=d;}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __());};}();var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){function adopt(value){return value instanceof P?value:new P(function(resolve){resolve(value);});}return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value));}catch(e){reject(e);}}function rejected(value){try{step(generator.throw(value));}catch(e){reject(e);}}function step(result){result.done?resolve(result.value):adopt(result.value).then(fulfilled,rejected);}step((generator=generator.apply(thisArg,_arguments||[])).next());});};var __generator=this&&this.__generator||function(thisArg,body){var _={label:0,sent:function sent(){if(t[0]&1)throw t[1];return t[1];},trys:[],ops:[]};var f;var y;var t;var g;return g={next:verb(0),throw:verb(1),return:verb(2)},typeof Symbol==='function'&&(g[typeof Symbol==="function"?Symbol.iterator:"@@iterator"]=function(){return this;}),g;function verb(n){return function(v){return step([n,v]);};}function step(op){if(f)throw new TypeError('Generator is already executing.');while(_){try{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;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue;}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break;}if(op[0]===6&&_.label<t[1]){_.label=t[1];t=op;break;}if(t&&_.label<t[2]){_.label=t[2];_.ops.push(op);break;}if(t[2])_.ops.pop();_.trys.pop();continue;}op=body.call(thisArg,_);}catch(e){op=[6,e];y=0;}finally{f=t=0;}}if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true};}};var __rest=this&&this.__rest||function(s,e){var t={};for(var p in s){if(Object.prototype.hasOwnProperty.call(s,p)&&e.indexOf(p)<0)t[p]=s[p];}if(s!=null&&typeof Object.getOwnPropertySymbols==='function'){for(var i=0,p=Object.getOwnPropertySymbols(s);i<p.length;i++){if(e.indexOf(p[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p[i]))t[p[i]]=s[p[i]];}}return t;};var UIManager=_reactNative.UIManager;var RNCWebView=(0,_reactNative.requireNativeComponent)('RNCWebView');var resolveAssetSource=_reactNative.Image.resolveAssetSource;var uniqueRef=0;var WebView=function(_super){__extends(WebView,_super);function WebView(){var _this=_super!==null&&_super.apply(this,arguments)||this;_this.startUrl=null;_this.state={viewState:_this.props.startInLoadingState?'LOADING':'IDLE',lastErrorEvent:null};_this.webViewRef=_react.default.createRef();_this.messagingModuleName="WebViewMessageHandler"+(uniqueRef+=1);_this.componentDidMount=function(){_BatchedBridge.default.registerCallableModule(_this.messagingModuleName,_this);};_this.getCommands=function(){return UIManager.getViewManagerConfig('RNCWebView').Commands;};_this.goForward=function(){UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().goForward,undefined);};_this.goBack=function(){UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().goBack,undefined);};_this.reload=function(){_this.setState({viewState:'LOADING'});UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().reload,undefined);};_this.stopLoading=function(){UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().stopLoading,undefined);};_this.requestFocus=function(){UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().requestFocus,undefined);};_this.postMessage=function(data){UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().postMessage,[String(data)]);};_this.clearFormData=function(){UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().clearFormData,undefined);};_this.clearCache=function(includeDiskFiles){UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().clearCache,[includeDiskFiles]);};_this.clearHistory=function(){UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().clearHistory,undefined);};_this.injectJavaScript=function(data){UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().injectJavaScript,[data]);};_this.updateNavigationState=function(event){if(_this.props.onNavigationStateChange){_this.props.onNavigationStateChange(event.nativeEvent);}};_this.getWebViewHandle=function(){var nodeHandle=(0,_reactNative.findNodeHandle)(_this.webViewRef.current);(0,_invariant.default)(nodeHandle!=null,'nodeHandle expected to be non-null');return nodeHandle;};_this.onLoadingStart=function(event){var onLoadStart=_this.props.onLoadStart;var url=event.nativeEvent.url;_this.startUrl=url;if(onLoadStart){onLoadStart(event);}_this.updateNavigationState(event);};_this.onLoadingError=function(event){event.persist();var _a=_this.props;var onError=_a.onError;var onLoadEnd=_a.onLoadEnd;if(onError){onError(event);}if(onLoadEnd){onLoadEnd(event);}console.warn('Encountered an error loading page',event.nativeEvent);_this.setState({lastErrorEvent:event.nativeEvent,viewState:'ERROR'});};_this.onHttpError=function(event){var onHttpError=_this.props.onHttpError;if(onHttpError){onHttpError(event);}};_this.onRenderProcessGone=function(event){var onRenderProcessGone=_this.props.onRenderProcessGone;if(onRenderProcessGone){onRenderProcessGone(event);}};_this.onLoadingFinish=function(event){var _a=_this.props;var onLoad=_a.onLoad;var onLoadEnd=_a.onLoadEnd;var url=event.nativeEvent.url;if(onLoad){onLoad(event);}if(onLoadEnd){onLoadEnd(event);}if(url===_this.startUrl){_this.setState({viewState:'IDLE'});}_this.updateNavigationState(event);};_this.onMessage=function(event){var onMessage=_this.props.onMessage;if(onMessage){onMessage(event);}};_this.onLoadingProgress=function(event){var onLoadProgress=_this.props.onLoadProgress;var progress=event.nativeEvent.progress;if(progress===1){_this.setState(function(state){if(state.viewState==='LOADING'){return{viewState:'IDLE'};}return null;});}if(onLoadProgress){onLoadProgress(event);}};_this.onShouldStartLoadWithRequestCallback=function(shouldStart,url){if(shouldStart){UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().loadUrl,[String(url)]);}};return _this;}WebView.prototype.render=function(){var _a=this.props;var onMessage=_a.onMessage;var onShouldStartLoadWithRequestProp=_a.onShouldStartLoadWithRequest;var originWhitelist=_a.originWhitelist;var renderError=_a.renderError;var renderLoading=_a.renderLoading;var source=_a.source;var style=_a.style;var containerStyle=_a.containerStyle;var _b=_a.nativeConfig;var nativeConfig=_b===void 0?{}:_b;var otherProps=__rest(_a,['onMessage','onShouldStartLoadWithRequest','originWhitelist','renderError','renderLoading','source','style','containerStyle','nativeConfig']);var otherView=null;if(this.state.viewState==='LOADING'){otherView=(renderLoading||_WebViewShared.defaultRenderLoading)();}else if(this.state.viewState==='ERROR'){var errorEvent=this.state.lastErrorEvent;(0,_invariant.default)(errorEvent!=null,'lastErrorEvent expected to be non-null');otherView=(renderError||_WebViewShared.defaultRenderError)(errorEvent.domain,errorEvent.code,errorEvent.description);}else if(this.state.viewState!=='IDLE'){console.error("RNCWebView invalid state encountered: "+this.state.viewState);}var webViewStyles=[_WebView.default.container,_WebView.default.webView,style];var webViewContainerStyle=[_WebView.default.container,containerStyle];if(typeof source!=='number'&&source&&'method'in source){if(source.method==='POST'&&source.headers){console.warn('WebView: `source.headers` is not supported when using POST.');}else if(source.method==='GET'&&source.body){console.warn('WebView: `source.body` is not supported when using GET.');}}var NativeWebView=nativeConfig.component||RNCWebView;var onShouldStartLoadWithRequest=(0,_WebViewShared.createOnShouldStartLoadWithRequest)(this.onShouldStartLoadWithRequestCallback,originWhitelist,onShouldStartLoadWithRequestProp);var webView=_react.default.createElement(NativeWebView,(0,_extends2.default)({key:"webViewKey"},otherProps,{messagingEnabled:typeof onMessage==='function',messagingModuleName:this.messagingModuleName,onLoadingError:this.onLoadingError,onLoadingFinish:this.onLoadingFinish,onLoadingProgress:this.onLoadingProgress,onLoadingStart:this.onLoadingStart,onHttpError:this.onHttpError,onRenderProcessGone:this.onRenderProcessGone,onMessage:this.onMessage,onShouldStartLoadWithRequest:onShouldStartLoadWithRequest,ref:this.webViewRef,source:resolveAssetSource(source),style:webViewStyles},nativeConfig.props,{__source:{fileName:_jsxFileName,lineNumber:268,columnNumber:13}}));return _react.default.createElement(_reactNative.View,{style:webViewContainerStyle,__source:{fileName:_jsxFileName,lineNumber:289,columnNumber:13}},webView,otherView);};WebView.defaultProps={overScrollMode:'always',javaScriptEnabled:true,thirdPartyCookiesEnabled:true,scalesPageToFit:true,allowsFullscreenVideo:false,allowFileAccess:false,saveFormDataDisabled:false,cacheEnabled:true,androidHardwareAccelerationDisabled:false,androidLayerType:'none',originWhitelist:_WebViewShared.defaultOriginWhitelist};WebView.isFileUploadSupported=function(){return __awaiter(void 0,void 0,void 0,function(){return __generator(this,function(_a){return[2,_reactNative.NativeModules.RNCWebView.isFileUploadSupported()];});});};return WebView;}(_react.default.Component);var _default=WebView;exports.default=_default;
|
|
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') {
|
|
71
|
+
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]];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return t;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const UIManager = NotTypedUIManager;
|
|
79
|
+
const RNCWebView = requireNativeComponent('RNCWebView');
|
|
80
|
+
const { resolveAssetSource } = Image;
|
|
81
|
+
/**
|
|
82
|
+
* A simple counter to uniquely identify WebView instances. Do not use this for anything else.
|
|
83
|
+
*/
|
|
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;
|
|
240
|
+
}
|
|
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}`);
|
|
253
|
+
}
|
|
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
|
+
}
|
|
262
|
+
}
|
|
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));
|
|
318
|
+
export default WebView;
|
package/lib/WebView.ios.js
CHANGED
|
@@ -1 +1,284 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends"));var _react=_interopRequireDefault(require("react"));var _reactNative=require("react-native");var _invariant=_interopRequireDefault(require("invariant"));var _WebViewShared=require("./WebViewShared");var _WebView=_interopRequireDefault(require("./WebView.styles"));var _jsxFileName="/Users/trinh.ho2/momo-folk/kits/src/libs/webview/dist/lib/WebView.ios.js";var __extends=this&&this.__extends||function(){var _extendStatics=function extendStatics(d,b){_extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b;}||function(d,b){for(var p in b){if(b.hasOwnProperty(p))d[p]=b[p];}};return _extendStatics(d,b);};return function(d,b){_extendStatics(d,b);function __(){this.constructor=d;}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __());};}();var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){function adopt(value){return value instanceof P?value:new P(function(resolve){resolve(value);});}return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value));}catch(e){reject(e);}}function rejected(value){try{step(generator["throw"](value));}catch(e){reject(e);}}function step(result){result.done?resolve(result.value):adopt(result.value).then(fulfilled,rejected);}step((generator=generator.apply(thisArg,_arguments||[])).next());});};var __generator=this&&this.__generator||function(thisArg,body){var _={label:0,sent:function sent(){if(t[0]&1)throw t[1];return t[1];},trys:[],ops:[]},f,y,t,g;return g={next:verb(0),"throw":verb(1),"return":verb(2)},typeof Symbol==="function"&&(g[typeof Symbol==="function"?Symbol.iterator:"@@iterator"]=function(){return this;}),g;function verb(n){return function(v){return step([n,v]);};}function step(op){if(f)throw new TypeError("Generator is already executing.");while(_){try{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;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue;}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break;}if(op[0]===6&&_.label<t[1]){_.label=t[1];t=op;break;}if(t&&_.label<t[2]){_.label=t[2];_.ops.push(op);break;}if(t[2])_.ops.pop();_.trys.pop();continue;}op=body.call(thisArg,_);}catch(e){op=[6,e];y=0;}finally{f=t=0;}}if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true};}};var __rest=this&&this.__rest||function(s,e){var t={};for(var p in s){if(Object.prototype.hasOwnProperty.call(s,p)&&e.indexOf(p)<0)t[p]=s[p];}if(s!=null&&typeof Object.getOwnPropertySymbols==="function")for(var i=0,p=Object.getOwnPropertySymbols(s);i<p.length;i++){if(e.indexOf(p[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p[i]))t[p[i]]=s[p[i]];}return t;};var UIManager=_reactNative.UIManager;var resolveAssetSource=_reactNative.Image.resolveAssetSource;var processDecelerationRate=function processDecelerationRate(decelerationRate){var newDecelerationRate=decelerationRate;if(newDecelerationRate==='normal'){newDecelerationRate=0.998;}else if(newDecelerationRate==='fast'){newDecelerationRate=0.99;}return newDecelerationRate;};var RNCWebViewManager=_reactNative.NativeModules.RNCWebViewManager;var RNCWebView=(0,_reactNative.requireNativeComponent)('RNCWebView');var WebView=function(_super){__extends(WebView,_super);function WebView(){var _this=_super!==null&&_super.apply(this,arguments)||this;_this.state={viewState:_this.props.startInLoadingState?'LOADING':'IDLE',lastErrorEvent:null};_this.webViewRef=_react.default.createRef();_this.getCommands=function(){return UIManager.getViewManagerConfig('RNCWebView').Commands;};_this.goForward=function(){UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().goForward,undefined);};_this.goBack=function(){UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().goBack,undefined);};_this.reload=function(){_this.setState({viewState:'LOADING'});UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().reload,undefined);};_this.stopLoading=function(){UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().stopLoading,undefined);};_this.requestFocus=function(){UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().requestFocus,undefined);};_this.postMessage=function(data){UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().postMessage,[String(data)]);};_this.injectJavaScript=function(data){UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(),_this.getCommands().injectJavaScript,[data]);};_this.updateNavigationState=function(event){if(_this.props.onNavigationStateChange){_this.props.onNavigationStateChange(event.nativeEvent);}};_this.getWebViewHandle=function(){var nodeHandle=(0,_reactNative.findNodeHandle)(_this.webViewRef.current);(0,_invariant.default)(nodeHandle!=null,'nodeHandle expected to be non-null');return nodeHandle;};_this.onLoadingStart=function(event){var onLoadStart=_this.props.onLoadStart;if(onLoadStart){onLoadStart(event);}_this.updateNavigationState(event);};_this.onLoadingError=function(event){event.persist();var _a=_this.props,onError=_a.onError,onLoadEnd=_a.onLoadEnd;if(onLoadEnd){onLoadEnd(event);}if(onError){onError(event);}console.warn('Encountered an error loading page',event.nativeEvent);_this.setState({lastErrorEvent:event.nativeEvent,viewState:'ERROR'});};_this.onHttpError=function(event){var onHttpError=_this.props.onHttpError;if(onHttpError){onHttpError(event);}};_this.onLoadingFinish=function(event){var _a=_this.props,onLoad=_a.onLoad,onLoadEnd=_a.onLoadEnd;if(onLoad){onLoad(event);}if(onLoadEnd){onLoadEnd(event);}_this.setState({viewState:'IDLE'});_this.updateNavigationState(event);};_this.onMessage=function(event){var onMessage=_this.props.onMessage;if(onMessage){onMessage(event);}};_this.onLoadingProgress=function(event){var onLoadProgress=_this.props.onLoadProgress;if(onLoadProgress){onLoadProgress(event);}};_this.onShouldStartLoadWithRequestCallback=function(shouldStart,_url,lockIdentifier){var viewManager=_this.props.nativeConfig&&_this.props.nativeConfig.viewManager||RNCWebViewManager;viewManager.startLoadWithResult(!!shouldStart,lockIdentifier);};_this.onContentProcessDidTerminate=function(event){var onContentProcessDidTerminate=_this.props.onContentProcessDidTerminate;if(onContentProcessDidTerminate){onContentProcessDidTerminate(event);}};return _this;}WebView.prototype.componentDidUpdate=function(prevProps){this.showRedboxOnPropChanges(prevProps,'allowsInlineMediaPlayback');this.showRedboxOnPropChanges(prevProps,'incognito');this.showRedboxOnPropChanges(prevProps,'mediaPlaybackRequiresUserAction');this.showRedboxOnPropChanges(prevProps,'dataDetectorTypes');};WebView.prototype.showRedboxOnPropChanges=function(prevProps,propName){if(this.props[propName]!==prevProps[propName]){console.error("Changes to property "+propName+" do nothing after the initial render.");}};WebView.prototype.render=function(){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"]);var otherView=null;if(this.state.viewState==='LOADING'){otherView=(renderLoading||_WebViewShared.defaultRenderLoading)();}else if(this.state.viewState==='ERROR'){var errorEvent=this.state.lastErrorEvent;(0,_invariant.default)(errorEvent!=null,'lastErrorEvent expected to be non-null');otherView=(renderError||_WebViewShared.defaultRenderError)(errorEvent.domain,errorEvent.code,errorEvent.description);}else if(this.state.viewState!=='IDLE'){console.error("RNCWebView invalid state encountered: "+this.state.viewState);}var webViewStyles=[_WebView.default.container,_WebView.default.webView,style];var webViewContainerStyle=[_WebView.default.container,containerStyle];var onShouldStartLoadWithRequest=(0,_WebViewShared.createOnShouldStartLoadWithRequest)(this.onShouldStartLoadWithRequestCallback,originWhitelist,onShouldStartLoadWithRequestProp);var decelerationRate=processDecelerationRate(decelerationRateProp);var NativeWebView=nativeConfig.component||RNCWebView;var webView=_react.default.createElement(NativeWebView,(0,_extends2.default)({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,source:resolveAssetSource(this.props.source),style:webViewStyles},nativeConfig.props,{__source:{fileName:_jsxFileName,lineNumber:262,columnNumber:24}}));return _react.default.createElement(_reactNative.View,{style:webViewContainerStyle,__source:{fileName:_jsxFileName,lineNumber:265,columnNumber:17}},webView,otherView);};WebView.defaultProps={javaScriptEnabled:true,cacheEnabled:true,originWhitelist:_WebViewShared.defaultOriginWhitelist,useSharedProcessPool:true};WebView.isFileUploadSupported=function(){return __awaiter(void 0,void 0,void 0,function(){return __generator(this,function(_a){return[2,true];});});};return WebView;}(_react.default.Component);var _default=WebView;exports.default=_default;
|
|
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;
|