@exodus/react-native-webview 9.4.0-no-android.0 → 11.26.1-exodus.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +21 -18
  2. package/android/.editorconfig +6 -0
  3. package/android/build.gradle +137 -0
  4. package/android/gradle.properties +6 -0
  5. package/android/src/main/AndroidManifest.xml +15 -0
  6. package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewFileProvider.java +14 -0
  7. package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +1650 -0
  8. package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewModule.java +550 -0
  9. package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewPackage.kt +15 -0
  10. package/android/src/main/java/com/reactnativecommunity/webview/WebViewConfig.java +12 -0
  11. package/android/src/main/java/com/reactnativecommunity/webview/events/TopHttpErrorEvent.kt +25 -0
  12. package/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingErrorEvent.kt +25 -0
  13. package/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingFinishEvent.kt +24 -0
  14. package/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingProgressEvent.kt +24 -0
  15. package/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingStartEvent.kt +25 -0
  16. package/android/src/main/java/com/reactnativecommunity/webview/events/TopMessageEvent.kt +24 -0
  17. package/android/src/main/java/com/reactnativecommunity/webview/events/TopRenderProcessGoneEvent.kt +26 -0
  18. package/android/src/main/java/com/reactnativecommunity/webview/events/TopShouldStartLoadWithRequestEvent.kt +29 -0
  19. package/android/src/main/res/xml/file_provider_paths.xml +6 -0
  20. package/apple/RNCWKProcessPoolManager.h +15 -0
  21. package/apple/RNCWKProcessPoolManager.m +36 -0
  22. package/apple/RNCWebView.h +117 -0
  23. package/apple/RNCWebView.m +1532 -0
  24. package/apple/RNCWebViewManager.h +13 -0
  25. package/apple/RNCWebViewManager.m +288 -0
  26. package/index.d.ts +65 -0
  27. package/index.js +4 -0
  28. package/ios/RNCWebView.xcodeproj/project.pbxproj +2 -0
  29. package/lib/WebView.android.d.ts +7 -0
  30. package/lib/WebView.android.js +112 -1
  31. package/lib/WebView.d.ts +7 -0
  32. package/lib/WebView.ios.d.ts +7 -0
  33. package/lib/WebView.ios.js +134 -202
  34. package/lib/WebView.js +9 -2
  35. package/lib/WebView.styles.d.ts +12 -0
  36. package/lib/WebView.styles.js +7 -7
  37. package/lib/WebViewNativeComponent.android.d.ts +4 -0
  38. package/lib/WebViewNativeComponent.android.js +3 -0
  39. package/lib/WebViewNativeComponent.ios.d.ts +4 -0
  40. package/lib/WebViewNativeComponent.ios.js +3 -0
  41. package/lib/WebViewShared.d.ts +37 -0
  42. package/lib/WebViewShared.js +121 -24
  43. package/lib/WebViewTypes.d.ts +893 -0
  44. package/lib/WebViewTypes.js +31 -16
  45. package/lib/index.d.ts +4 -0
  46. package/lib/index.js +3 -0
  47. package/package.json +83 -87
  48. package/react-native-webview.podspec +3 -3
  49. package/react-native.config.js +37 -0
@@ -1,12 +1,65 @@
1
- import React from 'react';
2
- import { UIManager as NotTypedUIManager, View, requireNativeComponent, NativeModules, Image, findNodeHandle, } from 'react-native';
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
- import { defaultOriginWhitelist, createOnShouldStartLoadWithRequest, defaultRenderError, defaultRenderLoading, } from './WebViewShared';
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
- const UIManager = NotTypedUIManager;
7
- const { resolveAssetSource } = Image;
8
- const processDecelerationRate = (decelerationRate) => {
9
- let newDecelerationRate = decelerationRate;
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,82 @@ const processDecelerationRate = (decelerationRate) => {
15
68
  }
16
69
  return newDecelerationRate;
17
70
  };
18
- const RNCWebViewManager = NativeModules.RNCWebViewManager;
19
- const RNCWebView = requireNativeComponent('RNCWebView');
20
- class WebView extends React.Component {
21
- constructor() {
22
- super(...arguments);
23
- this.state = {
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
- componentDidUpdate(prevProps) {
166
- this.showRedboxOnPropChanges(prevProps, 'allowsInlineMediaPlayback');
167
- this.showRedboxOnPropChanges(prevProps, 'incognito');
168
- this.showRedboxOnPropChanges(prevProps, 'mediaPlaybackRequiresUserAction');
169
- this.showRedboxOnPropChanges(prevProps, 'dataDetectorTypes');
78
+ };
79
+ var WebViewComponent = forwardRef(function (_a, ref) {
80
+ 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.useSharedProcessPool, useSharedProcessPool = _e === void 0 ? true : _e, _f = _a.textInteractionEnabled, textInteractionEnabled = _f === void 0 ? true : _f, injectedJavaScript = _a.injectedJavaScript, injectedJavaScriptBeforeContentLoaded = _a.injectedJavaScriptBeforeContentLoaded, _g = _a.injectedJavaScriptForMainFrameOnly, injectedJavaScriptForMainFrameOnly = _g === void 0 ? true : _g, _h = _a.injectedJavaScriptBeforeContentLoadedForMainFrameOnly, injectedJavaScriptBeforeContentLoadedForMainFrameOnly = _h === void 0 ? true : _h, startInLoadingState = _a.startInLoadingState, onNavigationStateChange = _a.onNavigationStateChange, onLoadStart = _a.onLoadStart, onError = _a.onError, onLoad = _a.onLoad, onLoadEnd = _a.onLoadEnd, onLoadProgress = _a.onLoadProgress, onContentProcessDidTerminateProp = _a.onContentProcessDidTerminate, onFileDownload = _a.onFileDownload, onHttpErrorProp = _a.onHttpError, onMessageProp = _a.onMessage, renderLoading = _a.renderLoading, renderError = _a.renderError, style = _a.style, containerStyle = _a.containerStyle, source = _a.source, nativeConfig = _a.nativeConfig, allowsInlineMediaPlayback = _a.allowsInlineMediaPlayback, allowsAirPlayForMediaPlayback = _a.allowsAirPlayForMediaPlayback, mediaPlaybackRequiresUserAction = _a.mediaPlaybackRequiresUserAction, dataDetectorTypes = _a.dataDetectorTypes, incognito = _a.incognito, decelerationRateProp = _a.decelerationRate, onShouldStartLoadWithRequestProp = _a.onShouldStartLoadWithRequest, otherProps = __rest(_a, ["javaScriptEnabled", "cacheEnabled", "originWhitelist", "useSharedProcessPool", "textInteractionEnabled", "injectedJavaScript", "injectedJavaScriptBeforeContentLoaded", "injectedJavaScriptForMainFrameOnly", "injectedJavaScriptBeforeContentLoadedForMainFrameOnly", "startInLoadingState", "onNavigationStateChange", "onLoadStart", "onError", "onLoad", "onLoadEnd", "onLoadProgress", "onContentProcessDidTerminate", "onFileDownload", "onHttpError", "onMessage", "renderLoading", "renderError", "style", "containerStyle", "source", "nativeConfig", "allowsInlineMediaPlayback", "allowsAirPlayForMediaPlayback", "mediaPlaybackRequiresUserAction", "dataDetectorTypes", "incognito", "decelerationRate", "onShouldStartLoadWithRequest"]);
81
+ var webViewRef = useRef(null);
82
+ var onShouldStartLoadWithRequestCallback = useCallback(function (shouldStart, _url, lockIdentifier) {
83
+ if (lockIdentifier === void 0) { lockIdentifier = 0; }
84
+ var viewManager = (nativeConfig === null || nativeConfig === void 0 ? void 0 : nativeConfig.viewManager)
85
+ || RNCWebViewManager;
86
+ viewManager.startLoadWithResult(!!shouldStart, lockIdentifier);
87
+ }, [nativeConfig === null || nativeConfig === void 0 ? void 0 : nativeConfig.viewManager]);
88
+ var _j = useWebWiewLogic({
89
+ onNavigationStateChange: onNavigationStateChange,
90
+ onLoad: onLoad,
91
+ onError: onError,
92
+ onHttpErrorProp: onHttpErrorProp,
93
+ onLoadEnd: onLoadEnd,
94
+ onLoadProgress: onLoadProgress,
95
+ onLoadStart: onLoadStart,
96
+ onMessageProp: onMessageProp,
97
+ startInLoadingState: startInLoadingState,
98
+ originWhitelist: originWhitelist,
99
+ onShouldStartLoadWithRequestProp: onShouldStartLoadWithRequestProp,
100
+ onShouldStartLoadWithRequestCallback: onShouldStartLoadWithRequestCallback,
101
+ onContentProcessDidTerminateProp: onContentProcessDidTerminateProp
102
+ }), onLoadingStart = _j.onLoadingStart, onShouldStartLoadWithRequest = _j.onShouldStartLoadWithRequest, onMessage = _j.onMessage, viewState = _j.viewState, setViewState = _j.setViewState, lastErrorEvent = _j.lastErrorEvent, onHttpError = _j.onHttpError, onLoadingError = _j.onLoadingError, onLoadingFinish = _j.onLoadingFinish, onLoadingProgress = _j.onLoadingProgress, onContentProcessDidTerminate = _j.onContentProcessDidTerminate;
103
+ useImperativeHandle(ref, function () { return ({
104
+ goForward: function () { return Commands.goForward(webViewRef.current); },
105
+ goBack: function () { return Commands.goBack(webViewRef.current); },
106
+ reload: function () {
107
+ setViewState('LOADING');
108
+ Commands.reload(webViewRef.current);
109
+ },
110
+ stopLoading: function () { return Commands.stopLoading(webViewRef.current); },
111
+ postMessage: function (data) { return Commands.postMessage(webViewRef.current, data); },
112
+ injectJavaScript: function (data) { return Commands.injectJavaScript(webViewRef.current, data); },
113
+ requestFocus: function () { return Commands.requestFocus(webViewRef.current); }
114
+ }); }, [setViewState, webViewRef]);
115
+ useWarnIfChanges(allowsInlineMediaPlayback, 'allowsInlineMediaPlayback');
116
+ useWarnIfChanges(allowsAirPlayForMediaPlayback, 'allowsAirPlayForMediaPlayback');
117
+ useWarnIfChanges(incognito, 'incognito');
118
+ useWarnIfChanges(mediaPlaybackRequiresUserAction, 'mediaPlaybackRequiresUserAction');
119
+ useWarnIfChanges(dataDetectorTypes, 'dataDetectorTypes');
120
+ var otherView = null;
121
+ if (viewState === 'LOADING') {
122
+ otherView = (renderLoading || defaultRenderLoading)();
170
123
  }
171
- showRedboxOnPropChanges(prevProps, propName) {
172
- if (this.props[propName] !== prevProps[propName]) {
173
- console.error(`Changes to property ${propName} do nothing after the initial render.`);
174
- }
124
+ else if (viewState === 'ERROR') {
125
+ invariant(lastErrorEvent != null, 'lastErrorEvent expected to be non-null');
126
+ otherView = (renderError || defaultRenderError)(lastErrorEvent.domain, lastErrorEvent.code, lastErrorEvent.description);
175
127
  }
176
- render() {
177
- const { decelerationRate: decelerationRateProp, nativeConfig = {}, onMessage, onShouldStartLoadWithRequest: onShouldStartLoadWithRequestProp, originWhitelist, renderError, renderLoading, injectedJavaScriptForMainFrameOnly = true, injectedJavaScriptBeforeContentLoadedForMainFrameOnly = true, style, containerStyle, ...otherProps } = this.props;
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>);
128
+ else if (viewState !== 'IDLE') {
129
+ console.error("RNCWebView invalid state encountered: ".concat(viewState));
205
130
  }
206
- }
207
- WebView.defaultProps = {
208
- javaScriptEnabled: true,
209
- cacheEnabled: true,
210
- originWhitelist: defaultOriginWhitelist,
211
- useSharedProcessPool: true,
212
- };
213
- WebView.isFileUploadSupported = async () => {
214
- // no native implementation for iOS, depends only on permissions
215
- return true;
216
- };
131
+ var webViewStyles = [styles.container, styles.webView, style];
132
+ var webViewContainerStyle = [styles.container, containerStyle];
133
+ var decelerationRate = processDecelerationRate(decelerationRateProp);
134
+ var NativeWebView = (nativeConfig === null || nativeConfig === void 0 ? void 0 : nativeConfig.component)
135
+ || RNCWebView;
136
+ var webView = (<NativeWebView key="webViewKey" {...otherProps} javaScriptEnabled={javaScriptEnabled} cacheEnabled={cacheEnabled} 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} dataDetectorTypes={dataDetectorTypes} allowsAirPlayForMediaPlayback={allowsAirPlayForMediaPlayback} allowsInlineMediaPlayback={allowsInlineMediaPlayback} incognito={incognito} mediaPlaybackRequiresUserAction={mediaPlaybackRequiresUserAction} ref={webViewRef}
137
+ // TODO: find a better way to type this.
138
+ source={resolveAssetSource(source)} style={webViewStyles} {...nativeConfig === null || nativeConfig === void 0 ? void 0 : nativeConfig.props}/>);
139
+ return (<View style={webViewContainerStyle}>
140
+ {webView}
141
+ {otherView}
142
+ </View>);
143
+ });
144
+ // no native implementation for iOS, depends only on permissions
145
+ var isFileUploadSupported = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
146
+ return [2 /*return*/, true];
147
+ }); }); };
148
+ var WebView = Object.assign(WebViewComponent, { isFileUploadSupported: isFileUploadSupported });
217
149
  export default WebView;
package/lib/WebView.js CHANGED
@@ -1,4 +1,11 @@
1
- // This files provides compatibility without tree platform.
2
- import { WebView } from 'react-native';
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
@@ -1,8 +1,8 @@
1
1
  import { StyleSheet } from 'react-native';
2
- const styles = StyleSheet.create({
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,4 @@
1
+ import type { NativeWebViewAndroid } from "./WebViewTypes";
2
+ declare const RNCWebView: typeof NativeWebViewAndroid;
3
+ export default RNCWebView;
4
+ //# sourceMappingURL=WebViewNativeComponent.android.d.ts.map
@@ -0,0 +1,3 @@
1
+ import { requireNativeComponent } from "react-native";
2
+ var RNCWebView = requireNativeComponent('RNCWebView');
3
+ export default RNCWebView;
@@ -0,0 +1,4 @@
1
+ import type { NativeWebViewIOS } from "./WebViewTypes";
2
+ declare const RNCWebView: typeof NativeWebViewIOS;
3
+ export default RNCWebView;
4
+ //# sourceMappingURL=WebViewNativeComponent.ios.d.ts.map
@@ -0,0 +1,3 @@
1
+ import { requireNativeComponent } from "react-native";
2
+ var RNCWebView = requireNativeComponent('RNCWebView');
3
+ export default RNCWebView;
@@ -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