@exodus/react-native-webview 9.4.0-no-android.0 → 11.26.1-exodus.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -18
- package/android/.editorconfig +6 -0
- package/android/build.gradle +137 -0
- package/android/gradle.properties +6 -0
- package/android/src/main/AndroidManifest.xml +15 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewFileProvider.java +14 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +1650 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewModule.java +550 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewPackage.kt +15 -0
- package/android/src/main/java/com/reactnativecommunity/webview/WebViewConfig.java +12 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopHttpErrorEvent.kt +25 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingErrorEvent.kt +25 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingFinishEvent.kt +24 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingProgressEvent.kt +24 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingStartEvent.kt +25 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopMessageEvent.kt +24 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopRenderProcessGoneEvent.kt +26 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopShouldStartLoadWithRequestEvent.kt +29 -0
- package/android/src/main/res/xml/file_provider_paths.xml +6 -0
- package/apple/RNCWKProcessPoolManager.h +15 -0
- package/apple/RNCWKProcessPoolManager.m +36 -0
- package/apple/RNCWebView.h +117 -0
- package/apple/RNCWebView.m +1532 -0
- package/apple/RNCWebViewManager.h +13 -0
- package/apple/RNCWebViewManager.m +288 -0
- package/index.d.ts +65 -0
- package/index.js +4 -0
- package/ios/RNCWebView.xcodeproj/project.pbxproj +2 -0
- package/lib/WebView.android.d.ts +7 -0
- package/lib/WebView.android.js +125 -1
- package/lib/WebView.d.ts +7 -0
- package/lib/WebView.ios.d.ts +7 -0
- package/lib/WebView.ios.js +148 -202
- package/lib/WebView.js +9 -2
- package/lib/WebView.styles.d.ts +12 -0
- package/lib/WebView.styles.js +7 -7
- package/lib/WebViewNativeComponent.android.d.ts +4 -0
- package/lib/WebViewNativeComponent.android.js +3 -0
- package/lib/WebViewNativeComponent.ios.d.ts +4 -0
- package/lib/WebViewNativeComponent.ios.js +3 -0
- package/lib/WebViewShared.d.ts +37 -0
- package/lib/WebViewShared.js +121 -24
- package/lib/WebViewTypes.d.ts +873 -0
- package/lib/WebViewTypes.js +31 -16
- package/lib/index.d.ts +4 -0
- package/lib/index.js +3 -0
- package/package.json +83 -87
- package/react-native-webview.podspec +4 -4
- package/react-native.config.js +37 -0
package/lib/WebView.ios.js
CHANGED
|
@@ -1,12 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
38
|
+
var t = {};
|
|
39
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
40
|
+
t[p] = s[p];
|
|
41
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
42
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
43
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
44
|
+
t[p[i]] = s[p[i]];
|
|
45
|
+
}
|
|
46
|
+
return t;
|
|
47
|
+
};
|
|
48
|
+
import React, { forwardRef, useCallback, useImperativeHandle, useRef } from 'react';
|
|
49
|
+
import { Image, View, NativeModules, } from 'react-native';
|
|
3
50
|
import invariant from 'invariant';
|
|
4
|
-
|
|
51
|
+
// @ts-expect-error react-native doesn't have this type
|
|
52
|
+
import codegenNativeCommandsUntyped from 'react-native/Libraries/Utilities/codegenNativeCommands';
|
|
53
|
+
import RNCWebView from "./WebViewNativeComponent.ios";
|
|
54
|
+
import { defaultOriginWhitelist, defaultRenderError, defaultRenderLoading, useWebWiewLogic, } from './WebViewShared';
|
|
5
55
|
import styles from './WebView.styles';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
56
|
+
var codegenNativeCommands = codegenNativeCommandsUntyped;
|
|
57
|
+
var Commands = codegenNativeCommands({
|
|
58
|
+
supportedCommands: ['goBack', 'goForward', 'reload', 'stopLoading', /* 'injectJavaScript', */ 'requestFocus', 'postMessage', 'loadUrl']
|
|
59
|
+
});
|
|
60
|
+
var resolveAssetSource = Image.resolveAssetSource;
|
|
61
|
+
var processDecelerationRate = function (decelerationRate) {
|
|
62
|
+
var newDecelerationRate = decelerationRate;
|
|
10
63
|
if (newDecelerationRate === 'normal') {
|
|
11
64
|
newDecelerationRate = 0.998;
|
|
12
65
|
}
|
|
@@ -15,203 +68,96 @@ const processDecelerationRate = (decelerationRate) => {
|
|
|
15
68
|
}
|
|
16
69
|
return newDecelerationRate;
|
|
17
70
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
viewState: this.props.startInLoadingState ? 'LOADING' : 'IDLE',
|
|
25
|
-
lastErrorEvent: null,
|
|
26
|
-
};
|
|
27
|
-
this.webViewRef = React.createRef();
|
|
28
|
-
// eslint-disable-next-line react/sort-comp
|
|
29
|
-
this.getCommands = () => UIManager.getViewManagerConfig('RNCWebView').Commands;
|
|
30
|
-
/**
|
|
31
|
-
* Go forward one page in the web view's history.
|
|
32
|
-
*/
|
|
33
|
-
this.goForward = () => {
|
|
34
|
-
UIManager.dispatchViewManagerCommand(this.getWebViewHandle(), this.getCommands().goForward, undefined);
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Go back one page in the web view's history.
|
|
38
|
-
*/
|
|
39
|
-
this.goBack = () => {
|
|
40
|
-
UIManager.dispatchViewManagerCommand(this.getWebViewHandle(), this.getCommands().goBack, undefined);
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Reloads the current page.
|
|
44
|
-
*/
|
|
45
|
-
this.reload = () => {
|
|
46
|
-
this.setState({ viewState: 'LOADING' });
|
|
47
|
-
UIManager.dispatchViewManagerCommand(this.getWebViewHandle(), this.getCommands().reload, undefined);
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Stop loading the current page.
|
|
51
|
-
*/
|
|
52
|
-
this.stopLoading = () => {
|
|
53
|
-
UIManager.dispatchViewManagerCommand(this.getWebViewHandle(), this.getCommands().stopLoading, undefined);
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* Request focus on WebView rendered page.
|
|
57
|
-
*/
|
|
58
|
-
this.requestFocus = () => {
|
|
59
|
-
UIManager.dispatchViewManagerCommand(this.getWebViewHandle(), this.getCommands().requestFocus, undefined);
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Posts a message to the web view, which will emit a `message` event.
|
|
63
|
-
* Accepts one argument, `data`, which must be a string.
|
|
64
|
-
*
|
|
65
|
-
* In your webview, you'll need to something like the following.
|
|
66
|
-
*
|
|
67
|
-
* ```js
|
|
68
|
-
* document.addEventListener('message', e => { document.title = e.data; });
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
this.postMessage = (data) => {
|
|
72
|
-
UIManager.dispatchViewManagerCommand(this.getWebViewHandle(), this.getCommands().postMessage, [String(data)]);
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Injects a javascript string into the referenced WebView. Deliberately does not
|
|
76
|
-
* return a response because using eval() to return a response breaks this method
|
|
77
|
-
* on pages with a Content Security Policy that disallows eval(). If you need that
|
|
78
|
-
* functionality, look into postMessage/onMessage.
|
|
79
|
-
*/
|
|
80
|
-
this.injectJavaScript = (data) => {
|
|
81
|
-
UIManager.dispatchViewManagerCommand(this.getWebViewHandle(), this.getCommands().injectJavaScript, [data]);
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* We return an event with a bunch of fields including:
|
|
85
|
-
* url, title, loading, canGoBack, canGoForward
|
|
86
|
-
*/
|
|
87
|
-
this.updateNavigationState = (event) => {
|
|
88
|
-
if (this.props.onNavigationStateChange) {
|
|
89
|
-
this.props.onNavigationStateChange(event.nativeEvent);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* Returns the native `WebView` node.
|
|
94
|
-
*/
|
|
95
|
-
this.getWebViewHandle = () => {
|
|
96
|
-
const nodeHandle = findNodeHandle(this.webViewRef.current);
|
|
97
|
-
invariant(nodeHandle != null, 'nodeHandle expected to be non-null');
|
|
98
|
-
return nodeHandle;
|
|
99
|
-
};
|
|
100
|
-
this.onLoadingStart = (event) => {
|
|
101
|
-
const { onLoadStart } = this.props;
|
|
102
|
-
if (onLoadStart) {
|
|
103
|
-
onLoadStart(event);
|
|
104
|
-
}
|
|
105
|
-
this.updateNavigationState(event);
|
|
106
|
-
};
|
|
107
|
-
this.onLoadingError = (event) => {
|
|
108
|
-
event.persist(); // persist this event because we need to store it
|
|
109
|
-
const { onError, onLoadEnd } = this.props;
|
|
110
|
-
if (onLoadEnd) {
|
|
111
|
-
onLoadEnd(event);
|
|
112
|
-
}
|
|
113
|
-
if (onError) {
|
|
114
|
-
onError(event);
|
|
115
|
-
}
|
|
116
|
-
console.warn('Encountered an error loading page', event.nativeEvent);
|
|
117
|
-
this.setState({
|
|
118
|
-
lastErrorEvent: event.nativeEvent,
|
|
119
|
-
viewState: 'ERROR',
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
this.onHttpError = (event) => {
|
|
123
|
-
const { onHttpError } = this.props;
|
|
124
|
-
if (onHttpError) {
|
|
125
|
-
onHttpError(event);
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
this.onLoadingFinish = (event) => {
|
|
129
|
-
const { onLoad, onLoadEnd } = this.props;
|
|
130
|
-
if (onLoad) {
|
|
131
|
-
onLoad(event);
|
|
132
|
-
}
|
|
133
|
-
if (onLoadEnd) {
|
|
134
|
-
onLoadEnd(event);
|
|
135
|
-
}
|
|
136
|
-
this.setState({
|
|
137
|
-
viewState: 'IDLE',
|
|
138
|
-
});
|
|
139
|
-
this.updateNavigationState(event);
|
|
140
|
-
};
|
|
141
|
-
this.onMessage = (event) => {
|
|
142
|
-
const { onMessage } = this.props;
|
|
143
|
-
if (onMessage) {
|
|
144
|
-
onMessage(event);
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
this.onLoadingProgress = (event) => {
|
|
148
|
-
const { onLoadProgress } = this.props;
|
|
149
|
-
if (onLoadProgress) {
|
|
150
|
-
onLoadProgress(event);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
this.onShouldStartLoadWithRequestCallback = (shouldStart, _url, lockIdentifier) => {
|
|
154
|
-
const viewManager = (this.props.nativeConfig && this.props.nativeConfig.viewManager)
|
|
155
|
-
|| RNCWebViewManager;
|
|
156
|
-
viewManager.startLoadWithResult(!!shouldStart, lockIdentifier);
|
|
157
|
-
};
|
|
158
|
-
this.onContentProcessDidTerminate = (event) => {
|
|
159
|
-
const { onContentProcessDidTerminate } = this.props;
|
|
160
|
-
if (onContentProcessDidTerminate) {
|
|
161
|
-
onContentProcessDidTerminate(event);
|
|
162
|
-
}
|
|
163
|
-
};
|
|
71
|
+
var RNCWebViewManager = NativeModules.RNCWebViewManager;
|
|
72
|
+
var useWarnIfChanges = function (value, name) {
|
|
73
|
+
var ref = useRef(value);
|
|
74
|
+
if (ref.current !== value) {
|
|
75
|
+
console.warn("Changes to property ".concat(name, " do nothing after the initial render."));
|
|
76
|
+
ref.current = value;
|
|
164
77
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Harcoded defaults for security.
|
|
81
|
+
*/
|
|
82
|
+
var allowFileAccessFromFileURLs = false;
|
|
83
|
+
var allowUniversalAccessFromFileURLs = false;
|
|
84
|
+
var injectedJavaScriptForMainFrameOnly = true;
|
|
85
|
+
var injectedJavaScriptBeforeContentLoadedForMainFrameOnly = true;
|
|
86
|
+
var mediaPlaybackRequiresUserAction = true;
|
|
87
|
+
// iOS only configs
|
|
88
|
+
var allowsInlineMediaPlayback = true;
|
|
89
|
+
var allowsAirPlayForMediaPlayback = false;
|
|
90
|
+
var useSharedProcessPool = false;
|
|
91
|
+
var sharedCookiesEnabled = false;
|
|
92
|
+
var enableApplePay = false;
|
|
93
|
+
var onFileDownload = function () { return console.error('tried to download file'); };
|
|
94
|
+
var dataDetectorTypes = 'none';
|
|
95
|
+
var WebViewComponent = forwardRef(function (_a, ref) {
|
|
96
|
+
var _b = _a.javaScriptEnabled, javaScriptEnabled = _b === void 0 ? true : _b, _c = _a.cacheEnabled, cacheEnabled = _c === void 0 ? true : _c, _d = _a.originWhitelist, originWhitelist = _d === void 0 ? defaultOriginWhitelist : _d, _e = _a.textInteractionEnabled, textInteractionEnabled = _e === void 0 ? true : _e, injectedJavaScript = _a.injectedJavaScript, injectedJavaScriptBeforeContentLoaded = _a.injectedJavaScriptBeforeContentLoaded, startInLoadingState = _a.startInLoadingState, onNavigationStateChange = _a.onNavigationStateChange, onLoadStart = _a.onLoadStart, onError = _a.onError, onLoad = _a.onLoad, onLoadEnd = _a.onLoadEnd, onLoadProgress = _a.onLoadProgress, onContentProcessDidTerminateProp = _a.onContentProcessDidTerminate, onHttpErrorProp = _a.onHttpError, onMessageProp = _a.onMessage, renderLoading = _a.renderLoading, renderError = _a.renderError, style = _a.style, containerStyle = _a.containerStyle, source = _a.source, incognito = _a.incognito, decelerationRateProp = _a.decelerationRate, onShouldStartLoadWithRequestProp = _a.onShouldStartLoadWithRequest, otherProps = __rest(_a, ["javaScriptEnabled", "cacheEnabled", "originWhitelist", "textInteractionEnabled", "injectedJavaScript", "injectedJavaScriptBeforeContentLoaded", "startInLoadingState", "onNavigationStateChange", "onLoadStart", "onError", "onLoad", "onLoadEnd", "onLoadProgress", "onContentProcessDidTerminate", "onHttpError", "onMessage", "renderLoading", "renderError", "style", "containerStyle", "source", "incognito", "decelerationRate", "onShouldStartLoadWithRequest"]);
|
|
97
|
+
var webViewRef = useRef(null);
|
|
98
|
+
var onShouldStartLoadWithRequestCallback = useCallback(function (shouldStart, _url, lockIdentifier) {
|
|
99
|
+
if (lockIdentifier === void 0) { lockIdentifier = 0; }
|
|
100
|
+
var viewManager = RNCWebViewManager;
|
|
101
|
+
viewManager.startLoadWithResult(!!shouldStart, lockIdentifier);
|
|
102
|
+
}, []);
|
|
103
|
+
var _f = useWebWiewLogic({
|
|
104
|
+
onNavigationStateChange: onNavigationStateChange,
|
|
105
|
+
onLoad: onLoad,
|
|
106
|
+
onError: onError,
|
|
107
|
+
onHttpErrorProp: onHttpErrorProp,
|
|
108
|
+
onLoadEnd: onLoadEnd,
|
|
109
|
+
onLoadProgress: onLoadProgress,
|
|
110
|
+
onLoadStart: onLoadStart,
|
|
111
|
+
onMessageProp: onMessageProp,
|
|
112
|
+
startInLoadingState: startInLoadingState,
|
|
113
|
+
originWhitelist: originWhitelist,
|
|
114
|
+
onShouldStartLoadWithRequestProp: onShouldStartLoadWithRequestProp,
|
|
115
|
+
onShouldStartLoadWithRequestCallback: onShouldStartLoadWithRequestCallback,
|
|
116
|
+
onContentProcessDidTerminateProp: onContentProcessDidTerminateProp
|
|
117
|
+
}), onLoadingStart = _f.onLoadingStart, onShouldStartLoadWithRequest = _f.onShouldStartLoadWithRequest, onMessage = _f.onMessage, viewState = _f.viewState, setViewState = _f.setViewState, lastErrorEvent = _f.lastErrorEvent, onHttpError = _f.onHttpError, onLoadingError = _f.onLoadingError, onLoadingFinish = _f.onLoadingFinish, onLoadingProgress = _f.onLoadingProgress, onContentProcessDidTerminate = _f.onContentProcessDidTerminate;
|
|
118
|
+
useImperativeHandle(ref, function () { return ({
|
|
119
|
+
goForward: function () { return Commands.goForward(webViewRef.current); },
|
|
120
|
+
goBack: function () { return Commands.goBack(webViewRef.current); },
|
|
121
|
+
reload: function () {
|
|
122
|
+
setViewState('LOADING');
|
|
123
|
+
Commands.reload(webViewRef.current);
|
|
124
|
+
},
|
|
125
|
+
stopLoading: function () { return Commands.stopLoading(webViewRef.current); },
|
|
126
|
+
postMessage: function (data) { return Commands.postMessage(webViewRef.current, data); },
|
|
127
|
+
// injectJavaScript: (data: string) => Commands.injectJavaScript(webViewRef.current, data),
|
|
128
|
+
requestFocus: function () { return Commands.requestFocus(webViewRef.current); }
|
|
129
|
+
}); }, [setViewState, webViewRef]);
|
|
130
|
+
useWarnIfChanges(allowsInlineMediaPlayback, 'allowsInlineMediaPlayback');
|
|
131
|
+
useWarnIfChanges(allowsAirPlayForMediaPlayback, 'allowsAirPlayForMediaPlayback');
|
|
132
|
+
useWarnIfChanges(incognito, 'incognito');
|
|
133
|
+
useWarnIfChanges(mediaPlaybackRequiresUserAction, 'mediaPlaybackRequiresUserAction');
|
|
134
|
+
useWarnIfChanges(dataDetectorTypes, 'dataDetectorTypes');
|
|
135
|
+
var otherView = null;
|
|
136
|
+
if (viewState === 'LOADING') {
|
|
137
|
+
otherView = (renderLoading || defaultRenderLoading)();
|
|
170
138
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
139
|
+
else if (viewState === 'ERROR') {
|
|
140
|
+
invariant(lastErrorEvent != null, 'lastErrorEvent expected to be non-null');
|
|
141
|
+
otherView = (renderError || defaultRenderError)(lastErrorEvent.domain, lastErrorEvent.code, lastErrorEvent.description);
|
|
175
142
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
let otherView = null;
|
|
179
|
-
if (this.state.viewState === 'LOADING') {
|
|
180
|
-
otherView = (renderLoading || defaultRenderLoading)();
|
|
181
|
-
}
|
|
182
|
-
else if (this.state.viewState === 'ERROR') {
|
|
183
|
-
const errorEvent = this.state.lastErrorEvent;
|
|
184
|
-
invariant(errorEvent != null, 'lastErrorEvent expected to be non-null');
|
|
185
|
-
otherView = (renderError || defaultRenderError)(errorEvent.domain, errorEvent.code, errorEvent.description);
|
|
186
|
-
}
|
|
187
|
-
else if (this.state.viewState !== 'IDLE') {
|
|
188
|
-
console.error(`RNCWebView invalid state encountered: ${this.state.viewState}`);
|
|
189
|
-
}
|
|
190
|
-
const webViewStyles = [styles.container, styles.webView, style];
|
|
191
|
-
const webViewContainerStyle = [styles.container, containerStyle];
|
|
192
|
-
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(this.onShouldStartLoadWithRequestCallback,
|
|
193
|
-
// casting cause it's in the default props
|
|
194
|
-
originWhitelist, onShouldStartLoadWithRequestProp);
|
|
195
|
-
const decelerationRate = processDecelerationRate(decelerationRateProp);
|
|
196
|
-
const NativeWebView = nativeConfig.component
|
|
197
|
-
|| RNCWebView;
|
|
198
|
-
const 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}
|
|
199
|
-
// TODO: find a better way to type this.
|
|
200
|
-
source={resolveAssetSource(this.props.source)} style={webViewStyles} {...nativeConfig.props}/>);
|
|
201
|
-
return (<View style={webViewContainerStyle}>
|
|
202
|
-
{webView}
|
|
203
|
-
{otherView}
|
|
204
|
-
</View>);
|
|
143
|
+
else if (viewState !== 'IDLE') {
|
|
144
|
+
console.error("RNCWebView invalid state encountered: ".concat(viewState));
|
|
205
145
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
146
|
+
var webViewStyles = [styles.container, styles.webView, style];
|
|
147
|
+
var webViewContainerStyle = [styles.container, containerStyle];
|
|
148
|
+
var decelerationRate = processDecelerationRate(decelerationRateProp);
|
|
149
|
+
var NativeWebView = RNCWebView;
|
|
150
|
+
var webView = (<NativeWebView key="webViewKey" {...otherProps} allowFileAccessFromFileURLs={allowFileAccessFromFileURLs} allowUniversalAccessFromFileURLs={allowUniversalAccessFromFileURLs} enableApplePay={enableApplePay} javaScriptEnabled={javaScriptEnabled} cacheEnabled={cacheEnabled} dataDetectorTypes={dataDetectorTypes} useSharedProcessPool={useSharedProcessPool} textInteractionEnabled={textInteractionEnabled} decelerationRate={decelerationRate} messagingEnabled={typeof onMessageProp === 'function'} onLoadingError={onLoadingError} onLoadingFinish={onLoadingFinish} onLoadingProgress={onLoadingProgress} onFileDownload={onFileDownload} onLoadingStart={onLoadingStart} onHttpError={onHttpError} onMessage={onMessage} onShouldStartLoadWithRequest={onShouldStartLoadWithRequest} onContentProcessDidTerminate={onContentProcessDidTerminate} injectedJavaScript={injectedJavaScript} injectedJavaScriptBeforeContentLoaded={injectedJavaScriptBeforeContentLoaded} injectedJavaScriptForMainFrameOnly={injectedJavaScriptForMainFrameOnly} injectedJavaScriptBeforeContentLoadedForMainFrameOnly={injectedJavaScriptBeforeContentLoadedForMainFrameOnly} allowsAirPlayForMediaPlayback={allowsAirPlayForMediaPlayback} allowsInlineMediaPlayback={allowsInlineMediaPlayback} incognito={incognito} mediaPlaybackRequiresUserAction={mediaPlaybackRequiresUserAction} ref={webViewRef} sharedCookiesEnabled={sharedCookiesEnabled}
|
|
151
|
+
// TODO: find a better way to type this.
|
|
152
|
+
source={resolveAssetSource(source)} style={webViewStyles}/>);
|
|
153
|
+
return (<View style={webViewContainerStyle}>
|
|
154
|
+
{webView}
|
|
155
|
+
{otherView}
|
|
156
|
+
</View>);
|
|
157
|
+
});
|
|
158
|
+
// no native implementation for iOS, depends only on permissions
|
|
159
|
+
var isFileUploadSupported = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
160
|
+
return [2 /*return*/, true];
|
|
161
|
+
}); }); };
|
|
162
|
+
var WebView = Object.assign(WebViewComponent, { isFileUploadSupported: isFileUploadSupported });
|
|
217
163
|
export default WebView;
|
package/lib/WebView.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Text, View } from 'react-native';
|
|
3
|
+
// This "dummy" WebView is to render something for unsupported platforms,
|
|
4
|
+
// like for example Expo SDK "web" platform.
|
|
5
|
+
var WebView = function () { return (<View style={{ alignSelf: 'flex-start' }}>
|
|
6
|
+
<Text style={{ color: 'red' }}>
|
|
7
|
+
React Native WebView does not support this platform.
|
|
8
|
+
</Text>
|
|
9
|
+
</View>); };
|
|
3
10
|
export { WebView };
|
|
4
11
|
export default WebView;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ViewStyle, TextStyle } from 'react-native';
|
|
2
|
+
interface Styles {
|
|
3
|
+
container: ViewStyle;
|
|
4
|
+
errorText: TextStyle;
|
|
5
|
+
errorTextTitle: TextStyle;
|
|
6
|
+
loadingOrErrorView: ViewStyle;
|
|
7
|
+
webView: ViewStyle;
|
|
8
|
+
loadingProgressBar: ViewStyle;
|
|
9
|
+
}
|
|
10
|
+
declare const styles: Styles;
|
|
11
|
+
export default styles;
|
|
12
|
+
//# sourceMappingURL=WebView.styles.d.ts.map
|
package/lib/WebView.styles.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { StyleSheet } from 'react-native';
|
|
2
|
-
|
|
2
|
+
var styles = StyleSheet.create({
|
|
3
3
|
container: {
|
|
4
4
|
flex: 1,
|
|
5
|
-
overflow: 'hidden'
|
|
5
|
+
overflow: 'hidden'
|
|
6
6
|
},
|
|
7
7
|
loadingOrErrorView: {
|
|
8
8
|
position: 'absolute',
|
|
@@ -14,20 +14,20 @@ const styles = StyleSheet.create({
|
|
|
14
14
|
backgroundColor: 'white'
|
|
15
15
|
},
|
|
16
16
|
loadingProgressBar: {
|
|
17
|
-
height: 20
|
|
17
|
+
height: 20
|
|
18
18
|
},
|
|
19
19
|
errorText: {
|
|
20
20
|
fontSize: 14,
|
|
21
21
|
textAlign: 'center',
|
|
22
|
-
marginBottom: 2
|
|
22
|
+
marginBottom: 2
|
|
23
23
|
},
|
|
24
24
|
errorTextTitle: {
|
|
25
25
|
fontSize: 15,
|
|
26
26
|
fontWeight: '500',
|
|
27
|
-
marginBottom: 10
|
|
27
|
+
marginBottom: 10
|
|
28
28
|
},
|
|
29
29
|
webView: {
|
|
30
|
-
backgroundColor: '#ffffff'
|
|
31
|
-
}
|
|
30
|
+
backgroundColor: '#ffffff'
|
|
31
|
+
}
|
|
32
32
|
});
|
|
33
33
|
export default styles;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { OnShouldStartLoadWithRequest, ShouldStartLoadRequestEvent, WebViewError, WebViewErrorEvent, WebViewHttpErrorEvent, WebViewMessageEvent, WebViewNavigation, WebViewNavigationEvent, WebViewProgressEvent, WebViewRenderProcessGoneEvent, WebViewTerminatedEvent } from './WebViewTypes';
|
|
3
|
+
declare const defaultOriginWhitelist: readonly ["http://*", "https://*"];
|
|
4
|
+
declare const createOnShouldStartLoadWithRequest: (loadRequest: (shouldStart: boolean, url: string, lockIdentifier: number) => void, originWhitelist: readonly string[], onShouldStartLoadWithRequest?: OnShouldStartLoadWithRequest | undefined) => ({ nativeEvent }: ShouldStartLoadRequestEvent) => void;
|
|
5
|
+
declare const defaultRenderLoading: () => JSX.Element;
|
|
6
|
+
declare const defaultRenderError: (errorDomain: string | undefined, errorCode: number, errorDesc: string) => JSX.Element;
|
|
7
|
+
export { defaultOriginWhitelist, createOnShouldStartLoadWithRequest, defaultRenderLoading, defaultRenderError, };
|
|
8
|
+
export declare const useWebWiewLogic: ({ startInLoadingState, onNavigationStateChange, onLoadStart, onLoad, onLoadProgress, onLoadEnd, onError, onHttpErrorProp, onMessageProp, onRenderProcessGoneProp, onContentProcessDidTerminateProp, originWhitelist, onShouldStartLoadWithRequestProp, onShouldStartLoadWithRequestCallback, }: {
|
|
9
|
+
startInLoadingState?: boolean | undefined;
|
|
10
|
+
onNavigationStateChange?: ((event: WebViewNavigation) => void) | undefined;
|
|
11
|
+
onLoadStart?: ((event: WebViewNavigationEvent) => void) | undefined;
|
|
12
|
+
onLoad?: ((event: WebViewNavigationEvent) => void) | undefined;
|
|
13
|
+
onLoadProgress?: ((event: WebViewProgressEvent) => void) | undefined;
|
|
14
|
+
onLoadEnd?: ((event: WebViewNavigationEvent | WebViewErrorEvent) => void) | undefined;
|
|
15
|
+
onError?: ((event: WebViewErrorEvent) => void) | undefined;
|
|
16
|
+
onHttpErrorProp?: ((event: WebViewHttpErrorEvent) => void) | undefined;
|
|
17
|
+
onMessageProp?: ((event: WebViewMessageEvent) => void) | undefined;
|
|
18
|
+
onRenderProcessGoneProp?: ((event: WebViewRenderProcessGoneEvent) => void) | undefined;
|
|
19
|
+
onContentProcessDidTerminateProp?: ((event: WebViewTerminatedEvent) => void) | undefined;
|
|
20
|
+
originWhitelist: readonly string[];
|
|
21
|
+
onShouldStartLoadWithRequestProp?: OnShouldStartLoadWithRequest | undefined;
|
|
22
|
+
onShouldStartLoadWithRequestCallback: (shouldStart: boolean, url: string, lockIdentifier?: number | undefined) => void;
|
|
23
|
+
}) => {
|
|
24
|
+
onShouldStartLoadWithRequest: ({ nativeEvent }: ShouldStartLoadRequestEvent) => void;
|
|
25
|
+
onLoadingStart: (event: WebViewNavigationEvent) => void;
|
|
26
|
+
onLoadingProgress: (event: WebViewProgressEvent) => void;
|
|
27
|
+
onLoadingError: (event: WebViewErrorEvent) => void;
|
|
28
|
+
onLoadingFinish: (event: WebViewNavigationEvent) => void;
|
|
29
|
+
onHttpError: (event: WebViewHttpErrorEvent) => void;
|
|
30
|
+
onRenderProcessGone: (event: WebViewRenderProcessGoneEvent) => void;
|
|
31
|
+
onContentProcessDidTerminate: (event: WebViewTerminatedEvent) => void;
|
|
32
|
+
onMessage: (event: WebViewMessageEvent) => void;
|
|
33
|
+
viewState: "IDLE" | "LOADING" | "ERROR";
|
|
34
|
+
setViewState: React.Dispatch<React.SetStateAction<"IDLE" | "LOADING" | "ERROR">>;
|
|
35
|
+
lastErrorEvent: WebViewError | null;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=WebViewShared.d.ts.map
|