@exodus/react-native-webview 13.16.0-exodus.2 → 13.16.0-exodus.4
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/android/build.gradle +11 -7
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebChromeClient.java +15 -18
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewClient.java +0 -21
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt +5 -50
- package/android/src/newarch/com/reactnativecommunity/webview/RNCWebViewManager.java +0 -58
- package/android/src/oldarch/com/reactnativecommunity/webview/RNCWebViewManager.java +0 -40
- package/apple/RNCWebView.mm +0 -8
- package/apple/RNCWebViewDecisionManager.m +17 -0
- package/apple/RNCWebViewImpl.h +0 -10
- package/apple/RNCWebViewImpl.m +24 -72
- package/apple/RNCWebViewManager.mm +0 -8
- package/lib/RNCWebViewNativeComponent.d.ts +0 -26
- package/lib/RNCWebViewNativeComponent.js +1 -1
- package/lib/WebView.android.js +1 -1
- package/lib/WebView.d.ts +2 -2
- package/lib/WebView.ios.js +1 -1
- package/lib/WebViewShared.d.ts +5 -5
- package/lib/WebViewShared.js +1 -1
- package/lib/WebViewTypes.d.ts +5 -358
- package/lib/WebViewTypes.js +1 -1
- package/package.json +4 -11
- package/react-native-webview.podspec +1 -1
- package/src/RNCWebViewNativeComponent.ts +0 -37
- package/src/WebView.android.tsx +293 -284
- package/src/WebView.ios.tsx +223 -256
- package/src/WebView.tsx +2 -8
- package/src/WebViewShared.tsx +2 -11
- package/src/WebViewTypes.ts +2 -396
- package/src/__tests__/WebViewShared-test.js +40 -62
- package/src/__tests__/__snapshots__/WebViewShared-test.js.snap +0 -1
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopHttpErrorEvent.kt +0 -25
- package/lib/WebView.windows.d.ts +0 -17
- package/lib/WebView.windows.js +0 -1
- package/lib/WebViewNativeComponent.windows.d.ts +0 -3
- package/lib/WebViewNativeComponent.windows.js +0 -1
- package/src/WebView.macos.tsx +0 -252
- package/src/WebView.windows.tsx +0 -217
- package/src/WebViewNativeComponent.macos.ts +0 -7
- package/src/WebViewNativeComponent.windows.ts +0 -8
|
@@ -2,6 +2,7 @@ import { Linking } from 'react-native';
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
defaultOriginWhitelist,
|
|
5
|
+
defaultDeeplinkWhitelist,
|
|
5
6
|
createOnShouldStartLoadWithRequest,
|
|
6
7
|
} from '../WebViewShared';
|
|
7
8
|
|
|
@@ -48,7 +49,8 @@ describe('WebViewShared', () => {
|
|
|
48
49
|
test('loadRequest is called without onShouldStartLoadWithRequest override', async () => {
|
|
49
50
|
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
|
|
50
51
|
loadRequest,
|
|
51
|
-
defaultOriginWhitelist
|
|
52
|
+
defaultOriginWhitelist,
|
|
53
|
+
defaultDeeplinkWhitelist
|
|
52
54
|
);
|
|
53
55
|
|
|
54
56
|
onShouldStartLoadWithRequest({
|
|
@@ -65,10 +67,11 @@ describe('WebViewShared', () => {
|
|
|
65
67
|
);
|
|
66
68
|
});
|
|
67
69
|
|
|
68
|
-
test('
|
|
70
|
+
test('non-whitelisted protocol is blocked without calling Linking.openURL', async () => {
|
|
69
71
|
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
|
|
70
72
|
loadRequest,
|
|
71
|
-
defaultOriginWhitelist
|
|
73
|
+
defaultOriginWhitelist,
|
|
74
|
+
defaultDeeplinkWhitelist
|
|
72
75
|
);
|
|
73
76
|
|
|
74
77
|
onShouldStartLoadWithRequest({
|
|
@@ -77,7 +80,8 @@ describe('WebViewShared', () => {
|
|
|
77
80
|
|
|
78
81
|
await flushPromises();
|
|
79
82
|
|
|
80
|
-
|
|
83
|
+
// Exodus: non-whitelisted protocols are blocked, not opened
|
|
84
|
+
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
81
85
|
expect(loadRequest).toHaveBeenCalledWith(
|
|
82
86
|
false,
|
|
83
87
|
'invalid://example.com/',
|
|
@@ -89,6 +93,7 @@ describe('WebViewShared', () => {
|
|
|
89
93
|
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
|
|
90
94
|
loadRequest,
|
|
91
95
|
defaultOriginWhitelist,
|
|
96
|
+
defaultDeeplinkWhitelist,
|
|
92
97
|
alwaysTrueOnShouldStartLoadWithRequest
|
|
93
98
|
);
|
|
94
99
|
|
|
@@ -106,10 +111,11 @@ describe('WebViewShared', () => {
|
|
|
106
111
|
);
|
|
107
112
|
});
|
|
108
113
|
|
|
109
|
-
test('
|
|
114
|
+
test('non-whitelisted protocol is blocked even with true onShouldStartLoadWithRequest override', async () => {
|
|
110
115
|
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
|
|
111
116
|
loadRequest,
|
|
112
117
|
defaultOriginWhitelist,
|
|
118
|
+
defaultDeeplinkWhitelist,
|
|
113
119
|
alwaysTrueOnShouldStartLoadWithRequest
|
|
114
120
|
);
|
|
115
121
|
|
|
@@ -119,11 +125,8 @@ describe('WebViewShared', () => {
|
|
|
119
125
|
|
|
120
126
|
await flushPromises();
|
|
121
127
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
);
|
|
125
|
-
// We don't expect the URL to have been loaded in the WebView because it
|
|
126
|
-
// is not in the origin whitelist
|
|
128
|
+
// Exodus: non-whitelisted protocols are blocked, not opened
|
|
129
|
+
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
127
130
|
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
128
131
|
false,
|
|
129
132
|
'invalid://example.com/',
|
|
@@ -135,6 +138,7 @@ describe('WebViewShared', () => {
|
|
|
135
138
|
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
|
|
136
139
|
loadRequest,
|
|
137
140
|
defaultOriginWhitelist,
|
|
141
|
+
defaultDeeplinkWhitelist,
|
|
138
142
|
alwaysFalseOnShouldStartLoadWithRequest
|
|
139
143
|
);
|
|
140
144
|
|
|
@@ -155,7 +159,8 @@ describe('WebViewShared', () => {
|
|
|
155
159
|
test('loadRequest with limited whitelist', async () => {
|
|
156
160
|
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
|
|
157
161
|
loadRequest,
|
|
158
|
-
['https://*']
|
|
162
|
+
['https://*'],
|
|
163
|
+
defaultDeeplinkWhitelist
|
|
159
164
|
);
|
|
160
165
|
|
|
161
166
|
onShouldStartLoadWithRequest({
|
|
@@ -171,43 +176,42 @@ describe('WebViewShared', () => {
|
|
|
171
176
|
1
|
|
172
177
|
);
|
|
173
178
|
|
|
179
|
+
// Exodus: http:// is in the default blocklist, so it's blocked without Linking.openURL
|
|
174
180
|
onShouldStartLoadWithRequest({
|
|
175
181
|
nativeEvent: { url: 'http://insecure.com/', lockIdentifier: 2 },
|
|
176
182
|
});
|
|
177
183
|
|
|
178
184
|
await flushPromises();
|
|
179
185
|
|
|
180
|
-
expect(Linking.openURL).
|
|
186
|
+
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
181
187
|
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
182
188
|
false,
|
|
183
189
|
'http://insecure.com/',
|
|
184
190
|
2
|
|
185
191
|
);
|
|
186
192
|
|
|
193
|
+
// Exodus: git+https:// is not in the deeplink whitelist, so it's blocked
|
|
187
194
|
onShouldStartLoadWithRequest({
|
|
188
195
|
nativeEvent: { url: 'git+https://insecure.com/', lockIdentifier: 3 },
|
|
189
196
|
});
|
|
190
197
|
|
|
191
198
|
await flushPromises();
|
|
192
199
|
|
|
193
|
-
expect(Linking.openURL).
|
|
194
|
-
'git+https://insecure.com/'
|
|
195
|
-
);
|
|
200
|
+
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
196
201
|
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
197
202
|
false,
|
|
198
203
|
'git+https://insecure.com/',
|
|
199
204
|
3
|
|
200
205
|
);
|
|
201
206
|
|
|
207
|
+
// Exodus: fakehttps:// is not in the deeplink whitelist, so it's blocked
|
|
202
208
|
onShouldStartLoadWithRequest({
|
|
203
209
|
nativeEvent: { url: 'fakehttps://insecure.com/', lockIdentifier: 4 },
|
|
204
210
|
});
|
|
205
211
|
|
|
206
212
|
await flushPromises();
|
|
207
213
|
|
|
208
|
-
expect(Linking.openURL).
|
|
209
|
-
'fakehttps://insecure.com/'
|
|
210
|
-
);
|
|
214
|
+
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
211
215
|
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
212
216
|
false,
|
|
213
217
|
'fakehttps://insecure.com/',
|
|
@@ -215,16 +219,16 @@ describe('WebViewShared', () => {
|
|
|
215
219
|
);
|
|
216
220
|
});
|
|
217
221
|
|
|
218
|
-
test('loadRequest allows for valid URIs', async () => {
|
|
222
|
+
test('loadRequest allows for valid URIs matching origin whitelist', async () => {
|
|
223
|
+
// Exodus: Use lowercase schemes since URL API normalizes scheme to lowercase
|
|
219
224
|
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
|
|
220
225
|
loadRequest,
|
|
221
226
|
[
|
|
222
227
|
'plus+https://*',
|
|
223
|
-
'
|
|
228
|
+
'dot.https://*',
|
|
224
229
|
'dash-https://*',
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
]
|
|
230
|
+
],
|
|
231
|
+
defaultDeeplinkWhitelist
|
|
228
232
|
);
|
|
229
233
|
|
|
230
234
|
onShouldStartLoadWithRequest({
|
|
@@ -243,7 +247,7 @@ describe('WebViewShared', () => {
|
|
|
243
247
|
);
|
|
244
248
|
|
|
245
249
|
onShouldStartLoadWithRequest({
|
|
246
|
-
nativeEvent: { url: '
|
|
250
|
+
nativeEvent: { url: 'dot.https://www.example.com/', lockIdentifier: 2 },
|
|
247
251
|
});
|
|
248
252
|
|
|
249
253
|
await flushPromises();
|
|
@@ -251,7 +255,7 @@ describe('WebViewShared', () => {
|
|
|
251
255
|
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
252
256
|
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
253
257
|
true,
|
|
254
|
-
'
|
|
258
|
+
'dot.https://www.example.com/',
|
|
255
259
|
2
|
|
256
260
|
);
|
|
257
261
|
|
|
@@ -270,53 +274,27 @@ describe('WebViewShared', () => {
|
|
|
270
274
|
'dash-https://www.example.com/',
|
|
271
275
|
3
|
|
272
276
|
);
|
|
277
|
+
});
|
|
273
278
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
expect(Linking.openURL).toHaveBeenLastCalledWith(
|
|
281
|
-
'0invalid://www.example.com/'
|
|
282
|
-
);
|
|
283
|
-
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
284
|
-
false,
|
|
285
|
-
'0invalid://www.example.com/',
|
|
286
|
-
4
|
|
287
|
-
);
|
|
288
|
-
|
|
289
|
-
onShouldStartLoadWithRequest({
|
|
290
|
-
nativeEvent: { url: '+invalid://www.example.com/', lockIdentifier: 5 },
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
await flushPromises();
|
|
294
|
-
|
|
295
|
-
expect(Linking.openURL).toHaveBeenLastCalledWith(
|
|
296
|
-
'+invalid://www.example.com/'
|
|
297
|
-
);
|
|
298
|
-
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
299
|
-
false,
|
|
300
|
-
'+invalid://www.example.com/',
|
|
301
|
-
5
|
|
279
|
+
test('non-whitelisted protocols are blocked without Linking.openURL', async () => {
|
|
280
|
+
const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
|
|
281
|
+
loadRequest,
|
|
282
|
+
['https://*'],
|
|
283
|
+
defaultDeeplinkWhitelist
|
|
302
284
|
);
|
|
303
285
|
|
|
286
|
+
// Exodus: non-whitelisted protocols are blocked, not opened via Linking
|
|
304
287
|
onShouldStartLoadWithRequest({
|
|
305
|
-
nativeEvent: {
|
|
306
|
-
url: 'FAKE+plus+https://www.example.com/',
|
|
307
|
-
lockIdentifier: 6,
|
|
308
|
-
},
|
|
288
|
+
nativeEvent: { url: '0invalid://www.example.com/', lockIdentifier: 1 },
|
|
309
289
|
});
|
|
310
290
|
|
|
311
291
|
await flushPromises();
|
|
312
292
|
|
|
313
|
-
expect(Linking.openURL).
|
|
314
|
-
'FAKE+plus+https://www.example.com/'
|
|
315
|
-
);
|
|
293
|
+
expect(Linking.openURL).toHaveBeenCalledTimes(0);
|
|
316
294
|
expect(loadRequest).toHaveBeenLastCalledWith(
|
|
317
295
|
false,
|
|
318
|
-
'
|
|
319
|
-
|
|
296
|
+
'0invalid://www.example.com/',
|
|
297
|
+
1
|
|
320
298
|
);
|
|
321
299
|
});
|
|
322
300
|
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
package com.reactnativecommunity.webview.events
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.WritableMap
|
|
4
|
-
import com.facebook.react.uimanager.events.Event
|
|
5
|
-
import com.facebook.react.uimanager.events.RCTEventEmitter
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Event emitted when an HTTP error is received.
|
|
9
|
-
*/
|
|
10
|
-
class TopHttpErrorEvent(viewId: Int, private val mEventData: WritableMap) :
|
|
11
|
-
Event<TopHttpErrorEvent>(viewId) {
|
|
12
|
-
companion object {
|
|
13
|
-
const val EVENT_NAME = "topHttpError"
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
override fun getEventName(): String = EVENT_NAME
|
|
17
|
-
|
|
18
|
-
override fun canCoalesce(): Boolean = false
|
|
19
|
-
|
|
20
|
-
override fun getCoalescingKey(): Short = 0
|
|
21
|
-
|
|
22
|
-
override fun dispatch(rctEventEmitter: RCTEventEmitter) =
|
|
23
|
-
rctEventEmitter.receiveEvent(viewTag, eventName, mEventData)
|
|
24
|
-
|
|
25
|
-
}
|
package/lib/WebView.windows.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* Portions copyright for react-native-windows:
|
|
8
|
-
*
|
|
9
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
10
|
-
* Licensed under the MIT License.
|
|
11
|
-
*/
|
|
12
|
-
import React from 'react';
|
|
13
|
-
import { WindowsWebViewProps } from './WebViewTypes';
|
|
14
|
-
declare const WebView: React.ForwardRefExoticComponent<WindowsWebViewProps & React.RefAttributes<{}>> & {
|
|
15
|
-
isFileUploadSupported: () => Promise<boolean>;
|
|
16
|
-
};
|
|
17
|
-
export default WebView;
|
package/lib/WebView.windows.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));var _objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));var _react=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _codegenNativeCommands=_interopRequireDefault(require("react-native/Libraries/Utilities/codegenNativeCommands"));var _invariant=_interopRequireDefault(require("invariant"));var _WebViewNativeComponent=require("./WebViewNativeComponent.windows");var _WebViewShared=require("./WebViewShared");var _WebView=_interopRequireDefault(require("./WebView.styles"));var _jsxRuntime=require("react/jsx-runtime");var _excluded=["cacheEnabled","originWhitelist","deeplinkWhitelist","startInLoadingState","onNavigationStateChange","onLoadStart","onError","onLoad","onLoadEnd","onLoadProgress","onOpenWindow","onSourceChanged","onHttpError","onMessage","renderLoading","renderError","style","containerStyle","source","nativeConfig","onShouldStartLoadWithRequest","useWebView2","validateMeta","validateData"];var _this=this,_jsxFileName="/Users/raulgomezacuna/Development/react-native-webview/src/WebView.windows.tsx";function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var r=new WeakMap(),t=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(e){return e?t:r;})(e);}function _interopRequireWildcard(e,r){if(!r&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache(r);if(t&&t.has(e))return t.get(e);var n={__proto__:null},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if("default"!==u&&Object.prototype.hasOwnProperty.call(e,u)){var i=a?Object.getOwnPropertyDescriptor(e,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=e[u];}return n.default=e,t&&t.set(e,n),n;}var Commands=(0,_codegenNativeCommands.default)({supportedCommands:['goBack','goForward','reload','stopLoading','injectJavaScript','requestFocus','clearCache','postMessage','loadUrl']});var resolveAssetSource=_reactNative.Image.resolveAssetSource;var WebViewComponent=(0,_react.forwardRef)(function(_ref,ref){var _ref$cacheEnabled=_ref.cacheEnabled,cacheEnabled=_ref$cacheEnabled===void 0?true:_ref$cacheEnabled,_ref$originWhitelist=_ref.originWhitelist,originWhitelist=_ref$originWhitelist===void 0?_WebViewShared.defaultOriginWhitelist:_ref$originWhitelist,_ref$deeplinkWhitelis=_ref.deeplinkWhitelist,deeplinkWhitelist=_ref$deeplinkWhitelis===void 0?_WebViewShared.defaultDeeplinkWhitelist:_ref$deeplinkWhitelis,startInLoadingState=_ref.startInLoadingState,onNavigationStateChange=_ref.onNavigationStateChange,onLoadStart=_ref.onLoadStart,onError=_ref.onError,onLoad=_ref.onLoad,onLoadEnd=_ref.onLoadEnd,onLoadProgress=_ref.onLoadProgress,onOpenWindowProp=_ref.onOpenWindow,onSourceChanged=_ref.onSourceChanged,onHttpErrorProp=_ref.onHttpError,onMessageProp=_ref.onMessage,renderLoading=_ref.renderLoading,renderError=_ref.renderError,style=_ref.style,containerStyle=_ref.containerStyle,source=_ref.source,nativeConfig=_ref.nativeConfig,onShouldStartLoadWithRequestProp=_ref.onShouldStartLoadWithRequest,useWebView2=_ref.useWebView2,validateMeta=_ref.validateMeta,validateData=_ref.validateData,otherProps=(0,_objectWithoutProperties2.default)(_ref,_excluded);var webViewRef=(0,_react.useRef)(null);var RCTWebViewString=useWebView2?'RCTWebView2':'RCTWebView';var onShouldStartLoadWithRequestCallback=(0,_react.useCallback)(function(shouldStart,url,lockIdentifier){if(lockIdentifier){if(RCTWebViewString==='RCTWebView'){_reactNative.NativeModules.RCTWebView.onShouldStartLoadWithRequestCallback(shouldStart,lockIdentifier);}else{_reactNative.NativeModules.RCTWebView2.onShouldStartLoadWithRequestCallback(shouldStart,lockIdentifier);}}else if(shouldStart){Commands.loadUrl(webViewRef,url);}},[RCTWebViewString]);var _useWebViewLogic=(0,_WebViewShared.useWebViewLogic)({onNavigationStateChange:onNavigationStateChange,onLoad:onLoad,onError:onError,onHttpErrorProp:onHttpErrorProp,onLoadEnd:onLoadEnd,onLoadProgress:onLoadProgress,onLoadStart:onLoadStart,onMessageProp:onMessageProp,startInLoadingState:startInLoadingState,originWhitelist:originWhitelist,deeplinkWhitelist:deeplinkWhitelist,onShouldStartLoadWithRequestProp:onShouldStartLoadWithRequestProp,onShouldStartLoadWithRequestCallback:onShouldStartLoadWithRequestCallback,onOpenWindowProp:onOpenWindowProp,validateMeta:validateMeta,validateData:validateData}),onLoadingStart=_useWebViewLogic.onLoadingStart,onShouldStartLoadWithRequest=_useWebViewLogic.onShouldStartLoadWithRequest,onMessage=_useWebViewLogic.onMessage,viewState=_useWebViewLogic.viewState,setViewState=_useWebViewLogic.setViewState,lastErrorEvent=_useWebViewLogic.lastErrorEvent,onHttpError=_useWebViewLogic.onHttpError,onLoadingError=_useWebViewLogic.onLoadingError,onLoadingFinish=_useWebViewLogic.onLoadingFinish,onLoadingProgress=_useWebViewLogic.onLoadingProgress,onOpenWindow=_useWebViewLogic.onOpenWindow;(0,_react.useImperativeHandle)(ref,function(){return{goForward:function goForward(){return Commands.goForward(webViewRef.current);},goBack:function goBack(){return Commands.goBack(webViewRef.current);},reload:function reload(){setViewState('LOADING');Commands.reload(webViewRef.current);},stopLoading:function stopLoading(){return Commands.stopLoading(webViewRef.current);},postMessage:function postMessage(data){return Commands.postMessage(webViewRef.current,data);},injectJavaScript:function injectJavaScript(data){return Commands.injectJavaScript(webViewRef.current,data);},requestFocus:function requestFocus(){return Commands.requestFocus(webViewRef.current);},clearCache:function clearCache(){return Commands.clearCache(webViewRef.current);},loadUrl:function loadUrl(url){return Commands.loadUrl(webViewRef.current,url);}};},[setViewState,webViewRef]);var otherView=null;if(viewState==='LOADING'){otherView=(renderLoading||_WebViewShared.defaultRenderLoading)();}else if(viewState==='ERROR'){(0,_invariant.default)(lastErrorEvent!=null,'lastErrorEvent expected to be non-null');otherView=(renderError||_WebViewShared.defaultRenderError)(lastErrorEvent.domain,lastErrorEvent.code,lastErrorEvent.description);}else if(viewState!=='IDLE'){console.error(`RNCWebView invalid state encountered: ${viewState}`);}var webViewStyles=[_WebView.default.container,_WebView.default.webView,style];var webViewContainerStyle=[_WebView.default.container,containerStyle];var NativeWebView=useWebView2?_WebViewNativeComponent.RCTWebView2:_WebViewNativeComponent.RCTWebView;var webView=(0,_jsxRuntime.jsx)(NativeWebView,Object.assign({},otherProps,{messagingEnabled:typeof onMessageProp==='function',linkHandlingEnabled:typeof onOpenWindowProp==='function',onLoadingError:onLoadingError,onLoadingFinish:onLoadingFinish,onLoadingProgress:onLoadingProgress,onLoadingStart:onLoadingStart,onHttpError:onHttpError,onMessage:onMessage,onShouldStartLoadWithRequest:onShouldStartLoadWithRequest,onOpenWindow:onOpenWindow,onSourceChanged:onSourceChanged,ref:webViewRef,source:resolveAssetSource(source),style:webViewStyles,cacheEnabled:cacheEnabled},nativeConfig==null?void 0:nativeConfig.props),"webViewKey");return(0,_jsxRuntime.jsxs)(_reactNative.View,{style:webViewContainerStyle,children:[webView,otherView]});});var isFileUploadSupported=function(){var _ref2=(0,_asyncToGenerator2.default)(function*(){return false;});return function isFileUploadSupported(){return _ref2.apply(this,arguments);};}();var WebView=Object.assign(WebViewComponent,{isFileUploadSupported:isFileUploadSupported});var _default=exports.default=WebView;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports,"__esModule",{value:true});exports.RCTWebView2=exports.RCTWebView=void 0;var _reactNative=require("react-native");var RCTWebView=exports.RCTWebView=(0,_reactNative.requireNativeComponent)('RCTWebView');var RCTWebView2=exports.RCTWebView2=(0,_reactNative.requireNativeComponent)('RCTWebView2');
|
package/src/WebView.macos.tsx
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
forwardRef,
|
|
3
|
-
useCallback,
|
|
4
|
-
useImperativeHandle,
|
|
5
|
-
useRef,
|
|
6
|
-
} from 'react';
|
|
7
|
-
import { Image, View, ImageSourcePropType, HostComponent } from 'react-native';
|
|
8
|
-
import invariant from 'invariant';
|
|
9
|
-
import RNCWebView, { Commands, NativeProps } from './RNCWebViewNativeComponent';
|
|
10
|
-
import RNCWebViewModule from './NativeRNCWebViewModule';
|
|
11
|
-
import {
|
|
12
|
-
defaultOriginWhitelist,
|
|
13
|
-
defaultDeeplinkWhitelist,
|
|
14
|
-
defaultRenderError,
|
|
15
|
-
defaultRenderLoading,
|
|
16
|
-
useWebViewLogic,
|
|
17
|
-
} from './WebViewShared';
|
|
18
|
-
import { MacOSWebViewProps, WebViewSourceUri } from './WebViewTypes';
|
|
19
|
-
|
|
20
|
-
import styles from './WebView.styles';
|
|
21
|
-
|
|
22
|
-
const { resolveAssetSource } = Image;
|
|
23
|
-
|
|
24
|
-
const useWarnIfChanges = <T extends unknown>(value: T, name: string) => {
|
|
25
|
-
const ref = useRef(value);
|
|
26
|
-
if (ref.current !== value) {
|
|
27
|
-
console.warn(
|
|
28
|
-
`Changes to property ${name} do nothing after the initial render.`
|
|
29
|
-
);
|
|
30
|
-
ref.current = value;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const WebViewComponent = forwardRef<{}, MacOSWebViewProps>(
|
|
35
|
-
(
|
|
36
|
-
{
|
|
37
|
-
javaScriptEnabled = true,
|
|
38
|
-
cacheEnabled = true,
|
|
39
|
-
originWhitelist = defaultOriginWhitelist,
|
|
40
|
-
deeplinkWhitelist = defaultDeeplinkWhitelist,
|
|
41
|
-
useSharedProcessPool = true,
|
|
42
|
-
injectedJavaScript,
|
|
43
|
-
injectedJavaScriptBeforeContentLoaded,
|
|
44
|
-
startInLoadingState,
|
|
45
|
-
onNavigationStateChange,
|
|
46
|
-
onLoadStart,
|
|
47
|
-
onError,
|
|
48
|
-
onLoad,
|
|
49
|
-
onLoadEnd,
|
|
50
|
-
onLoadProgress,
|
|
51
|
-
onHttpError: onHttpErrorProp,
|
|
52
|
-
onMessage: onMessageProp,
|
|
53
|
-
renderLoading,
|
|
54
|
-
renderError,
|
|
55
|
-
style,
|
|
56
|
-
containerStyle,
|
|
57
|
-
source,
|
|
58
|
-
nativeConfig,
|
|
59
|
-
allowsInlineMediaPlayback,
|
|
60
|
-
allowsPictureInPictureMediaPlayback = true,
|
|
61
|
-
allowsAirPlayForMediaPlayback,
|
|
62
|
-
mediaPlaybackRequiresUserAction,
|
|
63
|
-
incognito,
|
|
64
|
-
onShouldStartLoadWithRequest: onShouldStartLoadWithRequestProp,
|
|
65
|
-
validateMeta,
|
|
66
|
-
validateData,
|
|
67
|
-
...otherProps
|
|
68
|
-
},
|
|
69
|
-
ref
|
|
70
|
-
) => {
|
|
71
|
-
const webViewRef = useRef<React.ComponentRef<
|
|
72
|
-
HostComponent<NativeProps>
|
|
73
|
-
> | null>(null);
|
|
74
|
-
|
|
75
|
-
const onShouldStartLoadWithRequestCallback = useCallback(
|
|
76
|
-
(shouldStart: boolean, _url: string, lockIdentifier = 0) => {
|
|
77
|
-
RNCWebViewModule.shouldStartLoadWithLockIdentifier(
|
|
78
|
-
!!shouldStart,
|
|
79
|
-
lockIdentifier
|
|
80
|
-
);
|
|
81
|
-
},
|
|
82
|
-
[]
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
const {
|
|
86
|
-
onLoadingStart,
|
|
87
|
-
onShouldStartLoadWithRequest,
|
|
88
|
-
onMessage,
|
|
89
|
-
viewState,
|
|
90
|
-
setViewState,
|
|
91
|
-
lastErrorEvent,
|
|
92
|
-
onHttpError,
|
|
93
|
-
onLoadingError,
|
|
94
|
-
onLoadingFinish,
|
|
95
|
-
onLoadingProgress,
|
|
96
|
-
onContentProcessDidTerminate,
|
|
97
|
-
} = useWebViewLogic({
|
|
98
|
-
onNavigationStateChange,
|
|
99
|
-
onLoad,
|
|
100
|
-
onError,
|
|
101
|
-
onHttpErrorProp,
|
|
102
|
-
onLoadEnd,
|
|
103
|
-
onLoadProgress,
|
|
104
|
-
onLoadStart,
|
|
105
|
-
onMessageProp,
|
|
106
|
-
startInLoadingState,
|
|
107
|
-
originWhitelist,
|
|
108
|
-
deeplinkWhitelist,
|
|
109
|
-
onShouldStartLoadWithRequestProp,
|
|
110
|
-
onShouldStartLoadWithRequestCallback,
|
|
111
|
-
validateMeta,
|
|
112
|
-
validateData,
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
useImperativeHandle(
|
|
116
|
-
ref,
|
|
117
|
-
() => ({
|
|
118
|
-
goForward: () =>
|
|
119
|
-
webViewRef.current && Commands.goForward(webViewRef.current),
|
|
120
|
-
goBack: () => webViewRef.current && Commands.goBack(webViewRef.current),
|
|
121
|
-
reload: () => {
|
|
122
|
-
setViewState('LOADING');
|
|
123
|
-
if (webViewRef.current) {
|
|
124
|
-
Commands.reload(webViewRef.current);
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
stopLoading: () =>
|
|
128
|
-
webViewRef.current && Commands.stopLoading(webViewRef.current),
|
|
129
|
-
postMessage: (data: string) =>
|
|
130
|
-
webViewRef.current && Commands.postMessage(webViewRef.current, data),
|
|
131
|
-
injectJavaScript: (data: string) =>
|
|
132
|
-
webViewRef.current &&
|
|
133
|
-
Commands.injectJavaScript(webViewRef.current, data),
|
|
134
|
-
requestFocus: () =>
|
|
135
|
-
webViewRef.current && Commands.requestFocus(webViewRef.current),
|
|
136
|
-
}),
|
|
137
|
-
[setViewState, webViewRef]
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
useWarnIfChanges(allowsInlineMediaPlayback, 'allowsInlineMediaPlayback');
|
|
141
|
-
useWarnIfChanges(
|
|
142
|
-
allowsPictureInPictureMediaPlayback,
|
|
143
|
-
'allowsPictureInPictureMediaPlayback'
|
|
144
|
-
);
|
|
145
|
-
useWarnIfChanges(
|
|
146
|
-
allowsAirPlayForMediaPlayback,
|
|
147
|
-
'allowsAirPlayForMediaPlayback'
|
|
148
|
-
);
|
|
149
|
-
useWarnIfChanges(incognito, 'incognito');
|
|
150
|
-
useWarnIfChanges(
|
|
151
|
-
mediaPlaybackRequiresUserAction,
|
|
152
|
-
'mediaPlaybackRequiresUserAction'
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
let otherView = null;
|
|
156
|
-
if (viewState === 'LOADING') {
|
|
157
|
-
otherView = (renderLoading || defaultRenderLoading)();
|
|
158
|
-
} else if (viewState === 'ERROR') {
|
|
159
|
-
invariant(
|
|
160
|
-
lastErrorEvent != null,
|
|
161
|
-
'lastErrorEvent expected to be non-null'
|
|
162
|
-
);
|
|
163
|
-
otherView = (renderError || defaultRenderError)(
|
|
164
|
-
lastErrorEvent?.domain,
|
|
165
|
-
lastErrorEvent?.code || 0,
|
|
166
|
-
lastErrorEvent?.description ?? ''
|
|
167
|
-
);
|
|
168
|
-
} else if (viewState !== 'IDLE') {
|
|
169
|
-
console.error(`RNCWebView invalid state encountered: ${viewState}`);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const webViewStyles = [styles.container, styles.webView, style];
|
|
173
|
-
const webViewContainerStyle = [styles.container, containerStyle];
|
|
174
|
-
|
|
175
|
-
const NativeWebView =
|
|
176
|
-
(nativeConfig?.component as typeof RNCWebView | undefined) || RNCWebView;
|
|
177
|
-
|
|
178
|
-
const sourceResolved = resolveAssetSource(source as ImageSourcePropType);
|
|
179
|
-
const newSource =
|
|
180
|
-
typeof sourceResolved === 'object'
|
|
181
|
-
? Object.entries(sourceResolved as WebViewSourceUri).reduce(
|
|
182
|
-
(prev, [currKey, currValue]) => {
|
|
183
|
-
return {
|
|
184
|
-
...prev,
|
|
185
|
-
[currKey]:
|
|
186
|
-
currKey === 'headers' &&
|
|
187
|
-
currValue &&
|
|
188
|
-
typeof currValue === 'object'
|
|
189
|
-
? Object.entries(currValue).map(([key, value]) => {
|
|
190
|
-
return {
|
|
191
|
-
name: key,
|
|
192
|
-
value,
|
|
193
|
-
};
|
|
194
|
-
})
|
|
195
|
-
: currValue,
|
|
196
|
-
};
|
|
197
|
-
},
|
|
198
|
-
{}
|
|
199
|
-
)
|
|
200
|
-
: sourceResolved;
|
|
201
|
-
|
|
202
|
-
const webView = (
|
|
203
|
-
<NativeWebView
|
|
204
|
-
key="webViewKey"
|
|
205
|
-
{...otherProps}
|
|
206
|
-
javaScriptEnabled={javaScriptEnabled}
|
|
207
|
-
cacheEnabled={cacheEnabled}
|
|
208
|
-
useSharedProcessPool={useSharedProcessPool}
|
|
209
|
-
messagingEnabled={typeof onMessageProp === 'function'}
|
|
210
|
-
newSource={newSource}
|
|
211
|
-
onLoadingError={onLoadingError}
|
|
212
|
-
onLoadingFinish={onLoadingFinish}
|
|
213
|
-
onLoadingProgress={onLoadingProgress}
|
|
214
|
-
onLoadingStart={onLoadingStart}
|
|
215
|
-
onHttpError={onHttpError}
|
|
216
|
-
onMessage={onMessage}
|
|
217
|
-
onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
|
|
218
|
-
onContentProcessDidTerminate={onContentProcessDidTerminate}
|
|
219
|
-
injectedJavaScript={injectedJavaScript}
|
|
220
|
-
injectedJavaScriptBeforeContentLoaded={
|
|
221
|
-
injectedJavaScriptBeforeContentLoaded
|
|
222
|
-
}
|
|
223
|
-
allowsAirPlayForMediaPlayback={allowsAirPlayForMediaPlayback}
|
|
224
|
-
allowsInlineMediaPlayback={allowsInlineMediaPlayback}
|
|
225
|
-
allowsPictureInPictureMediaPlayback={
|
|
226
|
-
allowsPictureInPictureMediaPlayback
|
|
227
|
-
}
|
|
228
|
-
incognito={incognito}
|
|
229
|
-
mediaPlaybackRequiresUserAction={mediaPlaybackRequiresUserAction}
|
|
230
|
-
ref={webViewRef}
|
|
231
|
-
// @ts-expect-error old arch only
|
|
232
|
-
source={sourceResolved}
|
|
233
|
-
style={webViewStyles}
|
|
234
|
-
{...nativeConfig?.props}
|
|
235
|
-
/>
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
return (
|
|
239
|
-
<View style={webViewContainerStyle}>
|
|
240
|
-
{webView}
|
|
241
|
-
{otherView}
|
|
242
|
-
</View>
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
// no native implementation for macOS, depends only on permissions
|
|
248
|
-
const isFileUploadSupported: () => Promise<boolean> = async () => true;
|
|
249
|
-
|
|
250
|
-
const WebView = Object.assign(WebViewComponent, { isFileUploadSupported });
|
|
251
|
-
|
|
252
|
-
export default WebView;
|