mirror of
https://github.com/status-im/react-native-webview.git
synced 2026-08-31 03:31:05 +00:00
add compiled file (to do on every rebase)
This commit is contained in:
Vendored
+84
@@ -0,0 +1,84 @@
|
||||
import React from 'react';
|
||||
import { createOnShouldStartLoadWithRequest } from './WebViewShared';
|
||||
import { WebViewRenderProcessGoneEvent, WebViewErrorEvent, WebViewHttpErrorEvent, WebViewMessageEvent, WebViewNavigationEvent, WebViewProgressEvent, WebViewPermissionEvent, AndroidWebViewProps, NativeWebViewAndroid, State } from './WebViewTypes';
|
||||
/**
|
||||
* Renders a native WebView.
|
||||
*/
|
||||
declare class WebView extends React.Component<AndroidWebViewProps, State> {
|
||||
static defaultProps: {
|
||||
overScrollMode: string;
|
||||
javaScriptEnabled: boolean;
|
||||
thirdPartyCookiesEnabled: boolean;
|
||||
scalesPageToFit: boolean;
|
||||
allowsFullscreenVideo: boolean;
|
||||
allowFileAccess: boolean;
|
||||
saveFormDataDisabled: boolean;
|
||||
cacheEnabled: boolean;
|
||||
androidHardwareAccelerationDisabled: boolean;
|
||||
androidLayerType: string;
|
||||
originWhitelist: string[];
|
||||
setSupportMultipleWindows: boolean;
|
||||
setBuiltInZoomControls: boolean;
|
||||
setDisplayZoomControls: boolean;
|
||||
nestedScrollEnabled: boolean;
|
||||
};
|
||||
static isFileUploadSupported: () => Promise<any>;
|
||||
startUrl: string | null;
|
||||
state: State;
|
||||
onShouldStartLoadWithRequest: ReturnType<typeof createOnShouldStartLoadWithRequest> | null;
|
||||
webViewRef: React.RefObject<NativeWebViewAndroid>;
|
||||
messagingModuleName: string;
|
||||
componentDidMount: () => void;
|
||||
getCommands: () => {
|
||||
goForward: number;
|
||||
goBack: number;
|
||||
reload: number;
|
||||
stopLoading: number;
|
||||
postMessage: number;
|
||||
injectJavaScript: number;
|
||||
loadUrl: number;
|
||||
requestFocus: number;
|
||||
clearHistory: number;
|
||||
clearCache: number;
|
||||
clearFormData: number;
|
||||
answerPermissionRequest: number;
|
||||
};
|
||||
goForward: () => void;
|
||||
goBack: () => void;
|
||||
reload: () => void;
|
||||
stopLoading: () => void;
|
||||
requestFocus: () => void;
|
||||
postMessage: (data: string) => void;
|
||||
clearFormData: () => void;
|
||||
clearCache: (includeDiskFiles: boolean) => void;
|
||||
clearHistory: () => void;
|
||||
/**
|
||||
* Injects a javascript string into the referenced WebView. Deliberately does not
|
||||
* return a response because using eval() to return a response breaks this method
|
||||
* on pages with a Content Security Policy that disallows eval(). If you need that
|
||||
* functionality, look into postMessage/onMessage.
|
||||
*/
|
||||
injectJavaScript: (data: string) => void;
|
||||
answerPermissionRequest: (allow: boolean, resources: string[]) => void;
|
||||
/**
|
||||
* We return an event with a bunch of fields including:
|
||||
* url, title, loading, canGoBack, canGoForward
|
||||
*/
|
||||
updateNavigationState: (event: WebViewNavigationEvent) => void;
|
||||
/**
|
||||
* Returns the native `WebView` node.
|
||||
*/
|
||||
getWebViewHandle: () => number;
|
||||
onLoadingStart: (event: WebViewNavigationEvent) => void;
|
||||
onLoadingError: (event: WebViewErrorEvent) => void;
|
||||
onHttpError: (event: WebViewHttpErrorEvent) => void;
|
||||
onRenderProcessGone: (event: WebViewRenderProcessGoneEvent) => void;
|
||||
onLoadingFinish: (event: WebViewNavigationEvent) => void;
|
||||
onMessage: (event: WebViewMessageEvent) => void;
|
||||
onPermissionRequest: (event: WebViewPermissionEvent) => void;
|
||||
onLoadingProgress: (event: WebViewProgressEvent) => void;
|
||||
onShouldStartLoadWithRequestCallback: (shouldStart: boolean, url: string, lockIdentifier?: number | undefined) => void;
|
||||
render(): JSX.Element;
|
||||
}
|
||||
export default WebView;
|
||||
//# sourceMappingURL=WebView.android.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"WebView.android.d.ts","sourceRoot":"","sources":["../src/WebView.android.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAgB1B,OAAO,EAEL,kCAAkC,EAGnC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,6BAA6B,EAC7B,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,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;;;;;;;;;;;;;;;;MAgBjB;IAEF,MAAM,CAAC,qBAAqB,qBAG1B;IAEF,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE/B,KAAK,EAAE,KAAK,CAGV;IAEF,4BAA4B,EAAE,UAAU,CAAC,OAAO,kCAAkC,CAAC,GAAG,IAAI,CAAQ;IAElG,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,uBAAuB,gDAMtB;IAED;;;OAGG;IACH,qBAAqB,0CAInB;IAEF;;OAEG;IACH,gBAAgB,eAId;IAEF,cAAc,0CAQZ;IAEF,cAAc,qCAkBZ;IAEF,WAAW,yCAKV;IAED,mBAAmB,iDAKlB;IAED,eAAe,0CAeb;IAEF,SAAS,uCAKP;IAEF,mBAAmB,0CAKlB;IAED,iBAAiB,wCAcf;IAEF,oCAAoC,mFAclC;IAEF,MAAM;CAoFP;AAED,eAAe,OAAO,CAAC"}
|
||||
@@ -0,0 +1,313 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (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() { 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[Symbol.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 __spreadArrays = (this && this.__spreadArrays) || function () {
|
||||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
||||
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
||||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
||||
r[k] = a[j];
|
||||
return r;
|
||||
};
|
||||
import React from 'react';
|
||||
import { Image, requireNativeComponent, UIManager as NotTypedUIManager, View, NativeModules, findNodeHandle, } from 'react-native';
|
||||
import BatchedBridge from 'react-native/Libraries/BatchedBridge/BatchedBridge';
|
||||
import invariant from 'invariant';
|
||||
import { defaultOriginWhitelist, createOnShouldStartLoadWithRequest, defaultRenderError, defaultRenderLoading, } from './WebViewShared';
|
||||
import styles from './WebView.styles';
|
||||
var UIManager = NotTypedUIManager;
|
||||
var RNCWebView = requireNativeComponent('RNCWebView');
|
||||
var resolveAssetSource = Image.resolveAssetSource;
|
||||
/**
|
||||
* A simple counter to uniquely identify WebView instances. Do not use this for anything else.
|
||||
*/
|
||||
var uniqueRef = 0;
|
||||
/**
|
||||
* Renders a native WebView.
|
||||
*/
|
||||
var WebView = /** @class */ (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.onShouldStartLoadWithRequest = null;
|
||||
_this.webViewRef = React.createRef();
|
||||
_this.messagingModuleName = "WebViewMessageHandler" + (uniqueRef += 1);
|
||||
_this.componentDidMount = function () {
|
||||
BatchedBridge.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);
|
||||
};
|
||||
/**
|
||||
* Injects a javascript string into the referenced WebView. Deliberately does not
|
||||
* return a response because using eval() to return a response breaks this method
|
||||
* on pages with a Content Security Policy that disallows eval(). If you need that
|
||||
* functionality, look into postMessage/onMessage.
|
||||
*/
|
||||
_this.injectJavaScript = function (data) {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().injectJavaScript, [data]);
|
||||
};
|
||||
_this.answerPermissionRequest = function (allow, resources) {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().answerPermissionRequest, __spreadArrays([allow], (resources || [])));
|
||||
};
|
||||
/**
|
||||
* We return an event with a bunch of fields including:
|
||||
* url, title, loading, canGoBack, canGoForward
|
||||
*/
|
||||
_this.updateNavigationState = function (event) {
|
||||
if (_this.props.onNavigationStateChange) {
|
||||
_this.props.onNavigationStateChange(event.nativeEvent);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Returns the native `WebView` node.
|
||||
*/
|
||||
_this.getWebViewHandle = function () {
|
||||
var nodeHandle = findNodeHandle(_this.webViewRef.current);
|
||||
invariant(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(); // persist this event because we need to store it
|
||||
var _a = _this.props, onError = _a.onError, onLoadEnd = _a.onLoadEnd;
|
||||
if (onError) {
|
||||
onError(event);
|
||||
}
|
||||
else {
|
||||
console.warn('Encountered an error loading page', event.nativeEvent);
|
||||
}
|
||||
if (onLoadEnd) {
|
||||
onLoadEnd(event);
|
||||
}
|
||||
if (event.isDefaultPrevented())
|
||||
return;
|
||||
_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, onLoad = _a.onLoad, 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.onPermissionRequest = function (event) {
|
||||
var onPermissionRequest = _this.props.onPermissionRequest;
|
||||
if (onPermissionRequest) {
|
||||
onPermissionRequest(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, lockIdentifier) {
|
||||
if (lockIdentifier) {
|
||||
NativeModules.RNCWebView.onShouldStartLoadWithRequestCallback(shouldStart, lockIdentifier);
|
||||
}
|
||||
else if (shouldStart) {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().loadUrl, [String(url)]);
|
||||
}
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
WebView.prototype.render = function () {
|
||||
var _a = this.props, onMessage = _a.onMessage, onShouldStartLoadWithRequestProp = _a.onShouldStartLoadWithRequest, originWhitelist = _a.originWhitelist, renderError = _a.renderError, renderLoading = _a.renderLoading, source = _a.source, style = _a.style, containerStyle = _a.containerStyle, _b = _a.nativeConfig, nativeConfig = _b === void 0 ? {} : _b, otherProps = __rest(_a, ["onMessage", "onShouldStartLoadWithRequest", "originWhitelist", "renderError", "renderLoading", "source", "style", "containerStyle", "nativeConfig"]);
|
||||
var otherView = null;
|
||||
if (this.state.viewState === 'LOADING') {
|
||||
otherView = (renderLoading || defaultRenderLoading)();
|
||||
}
|
||||
else if (this.state.viewState === 'ERROR') {
|
||||
var errorEvent = this.state.lastErrorEvent;
|
||||
invariant(errorEvent != null, 'lastErrorEvent expected to be non-null');
|
||||
otherView = (renderError || defaultRenderError)(errorEvent.domain, errorEvent.code, errorEvent.description);
|
||||
}
|
||||
else if (this.state.viewState !== 'IDLE') {
|
||||
console.error("RNCWebView invalid state encountered: " + this.state.viewState);
|
||||
}
|
||||
var webViewStyles = [styles.container, styles.webView, style];
|
||||
var webViewContainerStyle = [styles.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;
|
||||
this.onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(this.onShouldStartLoadWithRequestCallback,
|
||||
// casting cause it's in the default props
|
||||
originWhitelist, onShouldStartLoadWithRequestProp);
|
||||
var webView = (<NativeWebView 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={this.onShouldStartLoadWithRequest} ref={this.webViewRef}
|
||||
// TODO: find a better way to type this.
|
||||
source={resolveAssetSource(source)} style={webViewStyles} {...nativeConfig.props}/>);
|
||||
return (<View style={webViewContainerStyle}>
|
||||
{webView}
|
||||
{otherView}
|
||||
</View>);
|
||||
};
|
||||
WebView.defaultProps = {
|
||||
overScrollMode: 'always',
|
||||
javaScriptEnabled: true,
|
||||
thirdPartyCookiesEnabled: true,
|
||||
scalesPageToFit: true,
|
||||
allowsFullscreenVideo: false,
|
||||
allowFileAccess: false,
|
||||
saveFormDataDisabled: false,
|
||||
cacheEnabled: true,
|
||||
androidHardwareAccelerationDisabled: false,
|
||||
androidLayerType: 'none',
|
||||
originWhitelist: defaultOriginWhitelist,
|
||||
setSupportMultipleWindows: true,
|
||||
setBuiltInZoomControls: true,
|
||||
setDisplayZoomControls: false,
|
||||
nestedScrollEnabled: false
|
||||
};
|
||||
WebView.isFileUploadSupported = function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
// native implementation should return "true" only for Android 5+
|
||||
return [2 /*return*/, NativeModules.RNCWebView.isFileUploadSupported()];
|
||||
});
|
||||
}); };
|
||||
return WebView;
|
||||
}(React.Component));
|
||||
export default WebView;
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
import React from 'react';
|
||||
import { IOSWebViewProps, AndroidWebViewProps } from './WebViewTypes';
|
||||
export declare type WebViewProps = IOSWebViewProps & AndroidWebViewProps;
|
||||
declare const WebView: React.FunctionComponent<WebViewProps>;
|
||||
export { WebView };
|
||||
export default WebView;
|
||||
//# sourceMappingURL=WebView.d.ts.map
|
||||
@@ -0,0 +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"}
|
||||
Vendored
+83
@@ -0,0 +1,83 @@
|
||||
import React from 'react';
|
||||
import { WebViewErrorEvent, WebViewHttpErrorEvent, WebViewMessageEvent, WebViewNavigationEvent, WebViewProgressEvent, WebViewTerminatedEvent, IOSWebViewProps, NativeWebViewIOS, State } from './WebViewTypes';
|
||||
declare class WebView extends React.Component<IOSWebViewProps, State> {
|
||||
static defaultProps: {
|
||||
javaScriptEnabled: boolean;
|
||||
cacheEnabled: boolean;
|
||||
originWhitelist: string[];
|
||||
useSharedProcessPool: boolean;
|
||||
};
|
||||
static isFileUploadSupported: () => Promise<boolean>;
|
||||
state: State;
|
||||
webViewRef: React.RefObject<NativeWebViewIOS>;
|
||||
getCommands: () => {
|
||||
goForward: number;
|
||||
goBack: number;
|
||||
reload: number;
|
||||
stopLoading: number;
|
||||
postMessage: number;
|
||||
injectJavaScript: number;
|
||||
loadUrl: number;
|
||||
requestFocus: number;
|
||||
};
|
||||
/**
|
||||
* Go forward one page in the web view's history.
|
||||
*/
|
||||
goForward: () => void;
|
||||
/**
|
||||
* Go back one page in the web view's history.
|
||||
*/
|
||||
goBack: () => void;
|
||||
/**
|
||||
* Reloads the current page.
|
||||
*/
|
||||
reload: () => void;
|
||||
/**
|
||||
* Stop loading the current page.
|
||||
*/
|
||||
stopLoading: () => void;
|
||||
/**
|
||||
* Request focus on WebView rendered page.
|
||||
*/
|
||||
requestFocus: () => void;
|
||||
/**
|
||||
* Posts a message to the web view, which will emit a `message` event.
|
||||
* Accepts one argument, `data`, which must be a string.
|
||||
*
|
||||
* In your webview, you'll need to something like the following.
|
||||
*
|
||||
* ```js
|
||||
* document.addEventListener('message', e => { document.title = e.data; });
|
||||
* ```
|
||||
*/
|
||||
postMessage: (data: string) => void;
|
||||
/**
|
||||
* Injects a javascript string into the referenced WebView. Deliberately does not
|
||||
* return a response because using eval() to return a response breaks this method
|
||||
* on pages with a Content Security Policy that disallows eval(). If you need that
|
||||
* functionality, look into postMessage/onMessage.
|
||||
*/
|
||||
injectJavaScript: (data: string) => void;
|
||||
/**
|
||||
* We return an event with a bunch of fields including:
|
||||
* url, title, loading, canGoBack, canGoForward
|
||||
*/
|
||||
updateNavigationState: (event: WebViewNavigationEvent) => void;
|
||||
/**
|
||||
* Returns the native `WebView` node.
|
||||
*/
|
||||
getWebViewHandle: () => number;
|
||||
onLoadingStart: (event: WebViewNavigationEvent) => void;
|
||||
onLoadingError: (event: WebViewErrorEvent) => void;
|
||||
onHttpError: (event: WebViewHttpErrorEvent) => void;
|
||||
onLoadingFinish: (event: WebViewNavigationEvent) => void;
|
||||
onMessage: (event: WebViewMessageEvent) => void;
|
||||
onLoadingProgress: (event: WebViewProgressEvent) => void;
|
||||
onShouldStartLoadWithRequestCallback: (shouldStart: boolean, _url: string, lockIdentifier: number) => void;
|
||||
onContentProcessDidTerminate: (event: WebViewTerminatedEvent) => void;
|
||||
componentDidUpdate(prevProps: IOSWebViewProps): void;
|
||||
showRedboxOnPropChanges(prevProps: IOSWebViewProps, propName: keyof IOSWebViewProps): void;
|
||||
render(): JSX.Element;
|
||||
}
|
||||
export default WebView;
|
||||
//# sourceMappingURL=WebView.ios.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"WebView.ios.d.ts","sourceRoot":"","sources":["../src/WebView.ios.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAkB1B,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,eAAe,EAEf,gBAAgB,EAEhB,KAAK,EAEN,MAAM,gBAAgB,CAAC;AAyBxB,cAAM,OAAQ,SAAQ,KAAK,CAAC,SAAS,CAAC,eAAe,EAAE,KAAK,CAAC;IAC3D,MAAM,CAAC,YAAY;;;;;MAKjB;IAEF,MAAM,CAAC,qBAAqB,yBAG1B;IAEF,KAAK,EAAE,KAAK,CAGV;IAEF,UAAU,oCAAuC;IAGjD,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,qCAmBZ;IAEF,WAAW,yCAKV;IAED,eAAe,0CAYb;IAEF,SAAS,uCAKP;IAEF,iBAAiB,wCAKf;IAEF,oCAAoC,uEAUlC;IAEF,4BAA4B,0CAK1B;IAEF,kBAAkB,CAAC,SAAS,EAAE,eAAe;IAO7C,uBAAuB,CACrB,SAAS,EAAE,eAAe,EAC1B,QAAQ,EAAE,MAAM,eAAe;IASjC,MAAM;CAqFP;AAED,eAAe,OAAO,CAAC"}
|
||||
@@ -0,0 +1,286 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (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() { 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[Symbol.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;
|
||||
};
|
||||
import React from 'react';
|
||||
import { UIManager as NotTypedUIManager, View, requireNativeComponent, NativeModules, Image, findNodeHandle, } from 'react-native';
|
||||
import invariant from 'invariant';
|
||||
import { defaultOriginWhitelist, createOnShouldStartLoadWithRequest, defaultRenderError, defaultRenderLoading, } from './WebViewShared';
|
||||
import styles from './WebView.styles';
|
||||
var UIManager = NotTypedUIManager;
|
||||
var resolveAssetSource = Image.resolveAssetSource;
|
||||
var processDecelerationRate = function (decelerationRate) {
|
||||
var newDecelerationRate = decelerationRate;
|
||||
if (newDecelerationRate === 'normal') {
|
||||
newDecelerationRate = 0.998;
|
||||
}
|
||||
else if (newDecelerationRate === 'fast') {
|
||||
newDecelerationRate = 0.99;
|
||||
}
|
||||
return newDecelerationRate;
|
||||
};
|
||||
var RNCWebViewManager = NativeModules.RNCWebViewManager;
|
||||
var RNCWebView = requireNativeComponent('RNCWebView');
|
||||
var WebView = /** @class */ (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.createRef();
|
||||
// eslint-disable-next-line react/sort-comp
|
||||
_this.getCommands = function () { return UIManager.getViewManagerConfig('RNCWebView').Commands; };
|
||||
/**
|
||||
* Go forward one page in the web view's history.
|
||||
*/
|
||||
_this.goForward = function () {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().goForward, undefined);
|
||||
};
|
||||
/**
|
||||
* Go back one page in the web view's history.
|
||||
*/
|
||||
_this.goBack = function () {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().goBack, undefined);
|
||||
};
|
||||
/**
|
||||
* Reloads the current page.
|
||||
*/
|
||||
_this.reload = function () {
|
||||
_this.setState({ viewState: 'LOADING' });
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().reload, undefined);
|
||||
};
|
||||
/**
|
||||
* Stop loading the current page.
|
||||
*/
|
||||
_this.stopLoading = function () {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().stopLoading, undefined);
|
||||
};
|
||||
/**
|
||||
* Request focus on WebView rendered page.
|
||||
*/
|
||||
_this.requestFocus = function () {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().requestFocus, undefined);
|
||||
};
|
||||
/**
|
||||
* Posts a message to the web view, which will emit a `message` event.
|
||||
* Accepts one argument, `data`, which must be a string.
|
||||
*
|
||||
* In your webview, you'll need to something like the following.
|
||||
*
|
||||
* ```js
|
||||
* document.addEventListener('message', e => { document.title = e.data; });
|
||||
* ```
|
||||
*/
|
||||
_this.postMessage = function (data) {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().postMessage, [String(data)]);
|
||||
};
|
||||
/**
|
||||
* Injects a javascript string into the referenced WebView. Deliberately does not
|
||||
* return a response because using eval() to return a response breaks this method
|
||||
* on pages with a Content Security Policy that disallows eval(). If you need that
|
||||
* functionality, look into postMessage/onMessage.
|
||||
*/
|
||||
_this.injectJavaScript = function (data) {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().injectJavaScript, [data]);
|
||||
};
|
||||
/**
|
||||
* We return an event with a bunch of fields including:
|
||||
* url, title, loading, canGoBack, canGoForward
|
||||
*/
|
||||
_this.updateNavigationState = function (event) {
|
||||
if (_this.props.onNavigationStateChange) {
|
||||
_this.props.onNavigationStateChange(event.nativeEvent);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Returns the native `WebView` node.
|
||||
*/
|
||||
_this.getWebViewHandle = function () {
|
||||
var nodeHandle = findNodeHandle(_this.webViewRef.current);
|
||||
invariant(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(); // persist this event because we need to store it
|
||||
var _a = _this.props, onError = _a.onError, onLoadEnd = _a.onLoadEnd;
|
||||
if (onError) {
|
||||
onError(event);
|
||||
}
|
||||
else {
|
||||
console.warn('Encountered an error loading page', event.nativeEvent);
|
||||
}
|
||||
if (onLoadEnd) {
|
||||
onLoadEnd(event);
|
||||
}
|
||||
if (event.isDefaultPrevented())
|
||||
return;
|
||||
_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 || defaultRenderLoading)();
|
||||
}
|
||||
else if (this.state.viewState === 'ERROR') {
|
||||
var errorEvent = this.state.lastErrorEvent;
|
||||
invariant(errorEvent != null, 'lastErrorEvent expected to be non-null');
|
||||
otherView = (renderError || defaultRenderError)(errorEvent.domain, errorEvent.code, errorEvent.description);
|
||||
}
|
||||
else if (this.state.viewState !== 'IDLE') {
|
||||
console.error("RNCWebView invalid state encountered: " + this.state.viewState);
|
||||
}
|
||||
var webViewStyles = [styles.container, styles.webView, style];
|
||||
var webViewContainerStyle = [styles.container, containerStyle];
|
||||
var onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(this.onShouldStartLoadWithRequestCallback,
|
||||
// casting cause it's in the default props
|
||||
originWhitelist, onShouldStartLoadWithRequestProp);
|
||||
var decelerationRate = processDecelerationRate(decelerationRateProp);
|
||||
var NativeWebView = nativeConfig.component
|
||||
|| RNCWebView;
|
||||
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}
|
||||
// TODO: find a better way to type this.
|
||||
source={resolveAssetSource(this.props.source)} style={webViewStyles} {...nativeConfig.props}/>);
|
||||
return (<View style={webViewContainerStyle}>
|
||||
{webView}
|
||||
{otherView}
|
||||
</View>);
|
||||
};
|
||||
WebView.defaultProps = {
|
||||
javaScriptEnabled: true,
|
||||
cacheEnabled: true,
|
||||
originWhitelist: defaultOriginWhitelist,
|
||||
useSharedProcessPool: true
|
||||
};
|
||||
WebView.isFileUploadSupported = function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
// no native implementation for iOS, depends only on permissions
|
||||
return [2 /*return*/, true];
|
||||
});
|
||||
}); };
|
||||
return WebView;
|
||||
}(React.Component));
|
||||
export default WebView;
|
||||
@@ -0,0 +1,13 @@
|
||||
import React from 'react';
|
||||
import { View } from 'react-native';
|
||||
// This "dummy" WebView is to render something for unsupported platforms,
|
||||
// like for example Expo SDK "web" platform. It matches the previous react-native
|
||||
// implementation which is produced by Expo SDK 37.0.0.1 implementation, with
|
||||
// similar interface than the native ones have.
|
||||
var WebView = function () { return (<View style={{
|
||||
alignSelf: 'flex-start',
|
||||
borderColor: 'rgb(255, 0, 0)',
|
||||
borderWidth: 1
|
||||
}}/>); };
|
||||
export { WebView };
|
||||
export default WebView;
|
||||
Vendored
+83
@@ -0,0 +1,83 @@
|
||||
import React from 'react';
|
||||
import { WebViewErrorEvent, WebViewHttpErrorEvent, WebViewMessageEvent, WebViewNavigationEvent, WebViewProgressEvent, WebViewTerminatedEvent, MacOSWebViewProps, NativeWebViewMacOS, State } from './WebViewTypes';
|
||||
declare class WebView extends React.Component<MacOSWebViewProps, State> {
|
||||
static defaultProps: {
|
||||
javaScriptEnabled: boolean;
|
||||
cacheEnabled: boolean;
|
||||
originWhitelist: string[];
|
||||
useSharedProcessPool: boolean;
|
||||
};
|
||||
static isFileUploadSupported: () => Promise<boolean>;
|
||||
state: State;
|
||||
webViewRef: React.RefObject<NativeWebViewMacOS>;
|
||||
getCommands: () => {
|
||||
goForward: number;
|
||||
goBack: number;
|
||||
reload: number;
|
||||
stopLoading: number;
|
||||
postMessage: number;
|
||||
injectJavaScript: number;
|
||||
loadUrl: number;
|
||||
requestFocus: number;
|
||||
};
|
||||
/**
|
||||
* Go forward one page in the web view's history.
|
||||
*/
|
||||
goForward: () => void;
|
||||
/**
|
||||
* Go back one page in the web view's history.
|
||||
*/
|
||||
goBack: () => void;
|
||||
/**
|
||||
* Reloads the current page.
|
||||
*/
|
||||
reload: () => void;
|
||||
/**
|
||||
* Stop loading the current page.
|
||||
*/
|
||||
stopLoading: () => void;
|
||||
/**
|
||||
* Request focus on WebView rendered page.
|
||||
*/
|
||||
requestFocus: () => void;
|
||||
/**
|
||||
* Posts a message to the web view, which will emit a `message` event.
|
||||
* Accepts one argument, `data`, which must be a string.
|
||||
*
|
||||
* In your webview, you'll need to something like the following.
|
||||
*
|
||||
* ```js
|
||||
* document.addEventListener('message', e => { document.title = e.data; });
|
||||
* ```
|
||||
*/
|
||||
postMessage: (data: string) => void;
|
||||
/**
|
||||
* Injects a javascript string into the referenced WebView. Deliberately does not
|
||||
* return a response because using eval() to return a response breaks this method
|
||||
* on pages with a Content Security Policy that disallows eval(). If you need that
|
||||
* functionality, look into postMessage/onMessage.
|
||||
*/
|
||||
injectJavaScript: (data: string) => void;
|
||||
/**
|
||||
* We return an event with a bunch of fields including:
|
||||
* url, title, loading, canGoBack, canGoForward
|
||||
*/
|
||||
updateNavigationState: (event: WebViewNavigationEvent) => void;
|
||||
/**
|
||||
* Returns the native `WebView` node.
|
||||
*/
|
||||
getWebViewHandle: () => number;
|
||||
onLoadingStart: (event: WebViewNavigationEvent) => void;
|
||||
onLoadingError: (event: WebViewErrorEvent) => void;
|
||||
onHttpError: (event: WebViewHttpErrorEvent) => void;
|
||||
onLoadingFinish: (event: WebViewNavigationEvent) => void;
|
||||
onMessage: (event: WebViewMessageEvent) => void;
|
||||
onLoadingProgress: (event: WebViewProgressEvent) => void;
|
||||
onShouldStartLoadWithRequestCallback: (shouldStart: boolean, _url: string, lockIdentifier: number) => void;
|
||||
onContentProcessDidTerminate: (event: WebViewTerminatedEvent) => void;
|
||||
componentDidUpdate(prevProps: MacOSWebViewProps): void;
|
||||
showRedboxOnPropChanges(prevProps: MacOSWebViewProps, propName: keyof MacOSWebViewProps): void;
|
||||
render(): JSX.Element;
|
||||
}
|
||||
export default WebView;
|
||||
//# sourceMappingURL=WebView.macos.d.ts.map
|
||||
@@ -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,qCAmBZ;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"}
|
||||
@@ -0,0 +1,274 @@
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (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() { 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[Symbol.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;
|
||||
};
|
||||
import React from 'react';
|
||||
import { UIManager as NotTypedUIManager, View, requireNativeComponent, NativeModules, Image, findNodeHandle, } from 'react-native';
|
||||
import invariant from 'invariant';
|
||||
import { defaultOriginWhitelist, createOnShouldStartLoadWithRequest, defaultRenderError, defaultRenderLoading, } from './WebViewShared';
|
||||
import styles from './WebView.styles';
|
||||
var UIManager = NotTypedUIManager;
|
||||
var resolveAssetSource = Image.resolveAssetSource;
|
||||
var RNCWebViewManager = NativeModules.RNCWebViewManager;
|
||||
var RNCWebView = requireNativeComponent('RNCWebView');
|
||||
var WebView = /** @class */ (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.createRef();
|
||||
// eslint-disable-next-line react/sort-comp
|
||||
_this.getCommands = function () { return UIManager.getViewManagerConfig('RNCWebView').Commands; };
|
||||
/**
|
||||
* Go forward one page in the web view's history.
|
||||
*/
|
||||
_this.goForward = function () {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().goForward, undefined);
|
||||
};
|
||||
/**
|
||||
* Go back one page in the web view's history.
|
||||
*/
|
||||
_this.goBack = function () {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().goBack, undefined);
|
||||
};
|
||||
/**
|
||||
* Reloads the current page.
|
||||
*/
|
||||
_this.reload = function () {
|
||||
_this.setState({ viewState: 'LOADING' });
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().reload, undefined);
|
||||
};
|
||||
/**
|
||||
* Stop loading the current page.
|
||||
*/
|
||||
_this.stopLoading = function () {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().stopLoading, undefined);
|
||||
};
|
||||
/**
|
||||
* Request focus on WebView rendered page.
|
||||
*/
|
||||
_this.requestFocus = function () {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().requestFocus, undefined);
|
||||
};
|
||||
/**
|
||||
* Posts a message to the web view, which will emit a `message` event.
|
||||
* Accepts one argument, `data`, which must be a string.
|
||||
*
|
||||
* In your webview, you'll need to something like the following.
|
||||
*
|
||||
* ```js
|
||||
* document.addEventListener('message', e => { document.title = e.data; });
|
||||
* ```
|
||||
*/
|
||||
_this.postMessage = function (data) {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().postMessage, [String(data)]);
|
||||
};
|
||||
/**
|
||||
* Injects a javascript string into the referenced WebView. Deliberately does not
|
||||
* return a response because using eval() to return a response breaks this method
|
||||
* on pages with a Content Security Policy that disallows eval(). If you need that
|
||||
* functionality, look into postMessage/onMessage.
|
||||
*/
|
||||
_this.injectJavaScript = function (data) {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), _this.getCommands().injectJavaScript, [data]);
|
||||
};
|
||||
/**
|
||||
* We return an event with a bunch of fields including:
|
||||
* url, title, loading, canGoBack, canGoForward
|
||||
*/
|
||||
_this.updateNavigationState = function (event) {
|
||||
if (_this.props.onNavigationStateChange) {
|
||||
_this.props.onNavigationStateChange(event.nativeEvent);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Returns the native `WebView` node.
|
||||
*/
|
||||
_this.getWebViewHandle = function () {
|
||||
var nodeHandle = findNodeHandle(_this.webViewRef.current);
|
||||
invariant(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(); // persist this event because we need to store it
|
||||
var _a = _this.props, onError = _a.onError, onLoadEnd = _a.onLoadEnd;
|
||||
if (onError) {
|
||||
onError(event);
|
||||
}
|
||||
else {
|
||||
console.warn('Encountered an error loading page', event.nativeEvent);
|
||||
}
|
||||
if (onLoadEnd) {
|
||||
onLoadEnd(event);
|
||||
}
|
||||
if (event.isDefaultPrevented())
|
||||
return;
|
||||
_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');
|
||||
};
|
||||
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, _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"]);
|
||||
var otherView = null;
|
||||
if (this.state.viewState === 'LOADING') {
|
||||
otherView = (renderLoading || defaultRenderLoading)();
|
||||
}
|
||||
else if (this.state.viewState === 'ERROR') {
|
||||
var errorEvent = this.state.lastErrorEvent;
|
||||
invariant(errorEvent != null, 'lastErrorEvent expected to be non-null');
|
||||
otherView = (renderError || defaultRenderError)(errorEvent.domain, errorEvent.code, errorEvent.description);
|
||||
}
|
||||
else if (this.state.viewState !== 'IDLE') {
|
||||
console.error("RNCWebView invalid state encountered: " + this.state.viewState);
|
||||
}
|
||||
var webViewStyles = [styles.container, styles.webView, style];
|
||||
var webViewContainerStyle = [styles.container, containerStyle];
|
||||
var onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(this.onShouldStartLoadWithRequestCallback,
|
||||
// casting cause it's in the default props
|
||||
originWhitelist, onShouldStartLoadWithRequestProp);
|
||||
var NativeWebView = nativeConfig.component
|
||||
|| RNCWebView;
|
||||
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}
|
||||
// TODO: find a better way to type this.
|
||||
source={resolveAssetSource(this.props.source)} style={webViewStyles} {...nativeConfig.props}/>);
|
||||
return (<View style={webViewContainerStyle}>
|
||||
{webView}
|
||||
{otherView}
|
||||
</View>);
|
||||
};
|
||||
WebView.defaultProps = {
|
||||
javaScriptEnabled: true,
|
||||
cacheEnabled: true,
|
||||
originWhitelist: defaultOriginWhitelist,
|
||||
useSharedProcessPool: true
|
||||
};
|
||||
WebView.isFileUploadSupported = function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
// no native implementation for macOS, depends only on permissions
|
||||
return [2 /*return*/, true];
|
||||
});
|
||||
}); };
|
||||
return WebView;
|
||||
}(React.Component));
|
||||
export default WebView;
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
import { ViewStyle, TextStyle } from 'react-native';
|
||||
interface Styles {
|
||||
container: ViewStyle;
|
||||
errorText: TextStyle;
|
||||
errorTextTitle: TextStyle;
|
||||
loadingOrErrorView: ViewStyle;
|
||||
webView: ViewStyle;
|
||||
loadingProgressBar: ViewStyle;
|
||||
}
|
||||
declare const styles: Styles;
|
||||
export default styles;
|
||||
//# sourceMappingURL=WebView.styles.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"WebView.styles.d.ts","sourceRoot":"","sources":["../src/WebView.styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEhE,UAAU,MAAM;IACd,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,EAAE,SAAS,CAAC;IACrB,cAAc,EAAE,SAAS,CAAC;IAC1B,kBAAkB,EAAE,SAAS,CAAC;IAC9B,OAAO,EAAE,SAAS,CAAC;IACnB,kBAAkB,EAAE,SAAS,CAAC;CAC/B;AAED,QAAA,MAAM,MAAM,QA8BV,CAAC;AAEH,eAAe,MAAM,CAAC"}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { StyleSheet } from 'react-native';
|
||||
var styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
overflow: 'hidden'
|
||||
},
|
||||
loadingOrErrorView: {
|
||||
position: 'absolute',
|
||||
flex: 1,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
backgroundColor: 'white'
|
||||
},
|
||||
loadingProgressBar: {
|
||||
height: 20
|
||||
},
|
||||
errorText: {
|
||||
fontSize: 14,
|
||||
textAlign: 'center',
|
||||
marginBottom: 2
|
||||
},
|
||||
errorTextTitle: {
|
||||
fontSize: 15,
|
||||
fontWeight: '500',
|
||||
marginBottom: 10
|
||||
},
|
||||
webView: {
|
||||
backgroundColor: '#ffffff'
|
||||
}
|
||||
});
|
||||
export default styles;
|
||||
Vendored
+40
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* Portions copyright for react-native-windows:
|
||||
*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
import React from 'react';
|
||||
import { NativeWebViewWindows, WebViewSharedProps, WebViewProgressEvent, WebViewNavigationEvent, WebViewErrorEvent, WebViewHttpErrorEvent, WebViewMessageEvent, State } from './WebViewTypes';
|
||||
export default class WebView extends React.Component<WebViewSharedProps, State> {
|
||||
static defaultProps: {
|
||||
javaScriptEnabled: boolean;
|
||||
};
|
||||
state: State;
|
||||
webViewRef: React.RefObject<NativeWebViewWindows>;
|
||||
goForward: () => void;
|
||||
goBack: () => void;
|
||||
reload: () => void;
|
||||
injectJavaScript: (data: string) => void;
|
||||
postMessage: (data: string) => void;
|
||||
getInjectableJSMessage: (message: string) => string;
|
||||
/**
|
||||
* We return an event with a bunch of fields including:
|
||||
* url, title, loading, canGoBack, canGoForward
|
||||
*/
|
||||
updateNavigationState: (event: WebViewNavigationEvent) => void;
|
||||
getWebViewHandle: () => number | null;
|
||||
onLoadingStart: (event: WebViewNavigationEvent) => void;
|
||||
onLoadingProgress: (event: WebViewProgressEvent) => void;
|
||||
onLoadingError: (event: WebViewErrorEvent) => void;
|
||||
onLoadingFinish: (event: WebViewNavigationEvent) => void;
|
||||
onMessage: (event: WebViewMessageEvent) => void;
|
||||
onHttpError: (event: WebViewHttpErrorEvent) => void;
|
||||
render(): JSX.Element;
|
||||
}
|
||||
//# sourceMappingURL=WebView.windows.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"WebView.windows.d.ts","sourceRoot":"","sources":["../src/WebView.windows.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAa1B,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EAEnB,KAAK,EACN,MAAM,gBAAgB,CAAC;AA0BxB,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,KAAK,CAAC,SAAS,CAAC,kBAAkB,EAAE,KAAK,CAAC;IAE7E,MAAM,CAAC,YAAY;;MAEjB;IAEF,KAAK,EAAE,KAAK,CAGX;IAED,UAAU,wCAA2C;IAErD,SAAS,aAMR;IAED,MAAM,aAML;IAED,MAAM,aAML;IAED,gBAAgB,yBAMf;IAED,WAAW,yBAOT;IAEF,sBAAsB,8BAIrB;IAID;;;OAGG;IACH,qBAAqB,0CAIpB;IAED,gBAAgB,sBAGf;IAED,cAAc,0CAMb;IAED,iBAAiB,wCAKf;IAEF,cAAc,qCAkBZ;IAEF,eAAe,0CAYd;IAED,SAAS,uCAKR;IAED,WAAW,yCAKV;IAED,MAAM;CA6EP"}
|
||||
@@ -0,0 +1,195 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* Portions copyright for react-native-windows:
|
||||
*
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (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 __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;
|
||||
};
|
||||
import React from 'react';
|
||||
import { UIManager as NotTypedUIManager, View, requireNativeComponent, StyleSheet, Image, findNodeHandle, } from 'react-native';
|
||||
import { createOnShouldStartLoadWithRequest, } from './WebViewShared';
|
||||
var UIManager = NotTypedUIManager;
|
||||
var resolveAssetSource = Image.resolveAssetSource;
|
||||
var RCTWebView = requireNativeComponent('RCTWebView');
|
||||
var styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1
|
||||
},
|
||||
hidden: {
|
||||
height: 0,
|
||||
flex: 0
|
||||
},
|
||||
loadingView: {
|
||||
flex: 1,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center'
|
||||
},
|
||||
loadingProgressBar: {
|
||||
height: 20
|
||||
}
|
||||
});
|
||||
var WebView = /** @class */ (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.createRef();
|
||||
_this.goForward = function () {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), UIManager.getViewManagerConfig('RCTWebView').Commands.goForward, undefined);
|
||||
};
|
||||
_this.goBack = function () {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), UIManager.getViewManagerConfig('RCTWebView').Commands.goBack, undefined);
|
||||
};
|
||||
_this.reload = function () {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), UIManager.getViewManagerConfig('RCTWebView').Commands.reload, undefined);
|
||||
};
|
||||
_this.injectJavaScript = function (data) {
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), UIManager.getViewManagerConfig('RCTWebView').Commands.injectJavaScript, [data]);
|
||||
};
|
||||
_this.postMessage = function (data) {
|
||||
var message = _this.getInjectableJSMessage(data);
|
||||
UIManager.dispatchViewManagerCommand(_this.getWebViewHandle(), UIManager.getViewManagerConfig('RCTWebView').Commands.injectJavaScript, [message]);
|
||||
};
|
||||
_this.getInjectableJSMessage = function (message) {
|
||||
return "(function() {window.dispatchEvent(new MessageEvent('message', {data: " + JSON.stringify(message) + "}));})();";
|
||||
};
|
||||
/**
|
||||
* We return an event with a bunch of fields including:
|
||||
* url, title, loading, canGoBack, canGoForward
|
||||
*/
|
||||
_this.updateNavigationState = function (event) {
|
||||
if (_this.props.onNavigationStateChange) {
|
||||
_this.props.onNavigationStateChange(event.nativeEvent);
|
||||
}
|
||||
};
|
||||
_this.getWebViewHandle = function () {
|
||||
// eslint-disable-next-line react/no-string-refs
|
||||
return findNodeHandle(_this.webViewRef.current);
|
||||
};
|
||||
_this.onLoadingStart = function (event) {
|
||||
var onLoadStart = _this.props.onLoadStart;
|
||||
if (onLoadStart) {
|
||||
onLoadStart(event);
|
||||
}
|
||||
_this.updateNavigationState(event);
|
||||
};
|
||||
_this.onLoadingProgress = function (event) {
|
||||
var onLoadProgress = _this.props.onLoadProgress;
|
||||
if (onLoadProgress) {
|
||||
onLoadProgress(event);
|
||||
}
|
||||
};
|
||||
_this.onLoadingError = function (event) {
|
||||
event.persist(); // persist this event because we need to store it
|
||||
var _a = _this.props, onError = _a.onError, onLoadEnd = _a.onLoadEnd;
|
||||
if (onError) {
|
||||
onError(event);
|
||||
}
|
||||
else {
|
||||
console.warn('Encountered an error loading page', event.nativeEvent);
|
||||
}
|
||||
if (onLoadEnd) {
|
||||
onLoadEnd(event);
|
||||
}
|
||||
if (event.isDefaultPrevented())
|
||||
return;
|
||||
_this.setState({
|
||||
lastErrorEvent: event.nativeEvent,
|
||||
viewState: 'ERROR'
|
||||
});
|
||||
};
|
||||
_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.onHttpError = function (event) {
|
||||
var onHttpError = _this.props.onHttpError;
|
||||
if (onHttpError) {
|
||||
onHttpError(event);
|
||||
}
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
WebView.prototype.render = function () {
|
||||
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"]);
|
||||
var otherView = null;
|
||||
if (this.state.viewState === 'LOADING') {
|
||||
otherView = this.props.renderLoading && this.props.renderLoading();
|
||||
}
|
||||
else if (this.state.viewState === 'ERROR') {
|
||||
var errorEvent = this.state.lastErrorEvent;
|
||||
otherView = this.props.renderError
|
||||
&& this.props.renderError(errorEvent.domain, errorEvent.code, errorEvent.description);
|
||||
}
|
||||
else if (this.state.viewState !== 'IDLE') {
|
||||
console.error('RCTWebView invalid state encountered: ', this.state.viewState);
|
||||
}
|
||||
var webViewStyles = [styles.container, this.props.style];
|
||||
if (this.state.viewState === 'LOADING'
|
||||
|| this.state.viewState === 'ERROR') {
|
||||
// if we're in either LOADING or ERROR states, don't show the webView
|
||||
webViewStyles.push(styles.hidden);
|
||||
}
|
||||
var onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(function () { },
|
||||
// casting cause it's in the default props
|
||||
originWhitelist, onShouldStartLoadWithRequestProp);
|
||||
var NativeWebView = nativeConfig.component
|
||||
|| RCTWebView;
|
||||
var webView = (<NativeWebView ref={this.webViewRef} 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} source={resolveAssetSource(this.props.source)} style={webViewStyles} {...nativeConfig.props}/>);
|
||||
return (<View style={styles.container}>
|
||||
{webView}
|
||||
{otherView}
|
||||
</View>);
|
||||
};
|
||||
WebView.defaultProps = {
|
||||
javaScriptEnabled: true
|
||||
};
|
||||
return WebView;
|
||||
}(React.Component));
|
||||
export default WebView;
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
import { OnShouldStartLoadWithRequest, ShouldStartLoadRequestEvent } from './WebViewTypes';
|
||||
declare const defaultOriginWhitelist: string[];
|
||||
declare const createOnShouldStartLoadWithRequest: (loadRequest: (shouldStart: boolean, url: string, lockIdentifier: number) => void, originWhitelist: readonly string[], onShouldStartLoadWithRequest?: OnShouldStartLoadWithRequest | undefined) => ({ nativeEvent }: ShouldStartLoadRequestEvent) => void;
|
||||
declare const defaultRenderLoading: () => JSX.Element;
|
||||
declare const defaultRenderError: (errorDomain: string | undefined, errorCode: number, errorDesc: string) => JSX.Element;
|
||||
export { defaultOriginWhitelist, createOnShouldStartLoadWithRequest, defaultRenderLoading, defaultRenderError, };
|
||||
//# sourceMappingURL=WebViewShared.d.ts.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"WebViewShared.d.ts","sourceRoot":"","sources":["../src/WebViewShared.tsx"],"names":[],"mappings":"AAGA,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC5B,MAAM,gBAAgB,CAAC;AAGxB,QAAA,MAAM,sBAAsB,UAA4B,CAAC;AAuBzD,QAAA,MAAM,kCAAkC,2PA8BvC,CAAC;AAEF,QAAA,MAAM,oBAAoB,mBAIzB,CAAC;AACF,QAAA,MAAM,kBAAkB,wFAWvB,CAAC;AAEF,OAAO,EACL,sBAAsB,EACtB,kCAAkC,EAClC,oBAAoB,EACpB,kBAAkB,GACnB,CAAC"}
|
||||
@@ -0,0 +1,59 @@
|
||||
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
||||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
||||
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
||||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
||||
r[k] = a[j];
|
||||
return r;
|
||||
};
|
||||
import escapeStringRegexp from 'escape-string-regexp';
|
||||
import React from 'react';
|
||||
import { Linking, View, ActivityIndicator, Text } from 'react-native';
|
||||
import styles from './WebView.styles';
|
||||
var defaultOriginWhitelist = ['http://*', 'https://*'];
|
||||
var extractOrigin = function (url) {
|
||||
var result = /^[A-Za-z][A-Za-z0-9+\-.]+:(\/\/)?[^/]*/.exec(url);
|
||||
return result === null ? '' : result[0];
|
||||
};
|
||||
var originWhitelistToRegex = function (originWhitelist) {
|
||||
return "^" + escapeStringRegexp(originWhitelist).replace(/\\\*/g, '.*');
|
||||
};
|
||||
var passesWhitelist = function (compiledWhitelist, url) {
|
||||
var origin = extractOrigin(url);
|
||||
return compiledWhitelist.some(function (x) { return new RegExp(x).test(origin); });
|
||||
};
|
||||
var compileWhitelist = function (originWhitelist) {
|
||||
return __spreadArrays(['about:blank'], (originWhitelist || [])).map(originWhitelistToRegex);
|
||||
};
|
||||
var createOnShouldStartLoadWithRequest = function (loadRequest, originWhitelist, onShouldStartLoadWithRequest) {
|
||||
return function (_a) {
|
||||
var nativeEvent = _a.nativeEvent;
|
||||
var shouldStart = true;
|
||||
var url = nativeEvent.url, lockIdentifier = nativeEvent.lockIdentifier;
|
||||
if (!passesWhitelist(compileWhitelist(originWhitelist), url)) {
|
||||
Linking.canOpenURL(url).then(function (supported) {
|
||||
if (supported) {
|
||||
return Linking.openURL(url);
|
||||
}
|
||||
console.warn("Can't open url: " + url);
|
||||
return undefined;
|
||||
})["catch"](function (e) {
|
||||
console.warn('Error opening URL: ', e);
|
||||
});
|
||||
shouldStart = false;
|
||||
}
|
||||
else if (onShouldStartLoadWithRequest) {
|
||||
shouldStart = onShouldStartLoadWithRequest(nativeEvent);
|
||||
}
|
||||
loadRequest(shouldStart, url, lockIdentifier);
|
||||
};
|
||||
};
|
||||
var defaultRenderLoading = function () { return (<View style={styles.loadingOrErrorView}>
|
||||
<ActivityIndicator />
|
||||
</View>); };
|
||||
var defaultRenderError = function (errorDomain, errorCode, errorDesc) { return (<View style={styles.loadingOrErrorView}>
|
||||
<Text style={styles.errorTextTitle}>Error loading page</Text>
|
||||
<Text style={styles.errorText}>{"Domain: " + errorDomain}</Text>
|
||||
<Text style={styles.errorText}>{"Error Code: " + errorCode}</Text>
|
||||
<Text style={styles.errorText}>{"Description: " + errorDesc}</Text>
|
||||
</View>); };
|
||||
export { defaultOriginWhitelist, createOnShouldStartLoadWithRequest, defaultRenderLoading, defaultRenderError, };
|
||||
Vendored
+1034
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -0,0 +1,47 @@
|
||||
/* eslint-disable react/no-multi-comp, max-classes-per-file */
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (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 __());
|
||||
};
|
||||
})();
|
||||
import { Component } from 'react';
|
||||
var NativeWebViewIOS = /** @class */ (function (_super) {
|
||||
__extends(NativeWebViewIOS, _super);
|
||||
function NativeWebViewIOS() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return NativeWebViewIOS;
|
||||
}(NativeWebViewIOSBase));
|
||||
export { NativeWebViewIOS };
|
||||
var NativeWebViewMacOS = /** @class */ (function (_super) {
|
||||
__extends(NativeWebViewMacOS, _super);
|
||||
function NativeWebViewMacOS() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return NativeWebViewMacOS;
|
||||
}(NativeWebViewMacOSBase));
|
||||
export { NativeWebViewMacOS };
|
||||
var NativeWebViewAndroid = /** @class */ (function (_super) {
|
||||
__extends(NativeWebViewAndroid, _super);
|
||||
function NativeWebViewAndroid() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return NativeWebViewAndroid;
|
||||
}(NativeWebViewAndroidBase));
|
||||
export { NativeWebViewAndroid };
|
||||
var NativeWebViewWindows = /** @class */ (function (_super) {
|
||||
__extends(NativeWebViewWindows, _super);
|
||||
function NativeWebViewWindows() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return NativeWebViewWindows;
|
||||
}(NativeWebViewWindowsBase));
|
||||
export { NativeWebViewWindows };
|
||||
Reference in New Issue
Block a user