@react-native-ohos/react-native-webview 13.10.6-beta.3 → 13.10.6

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 (62) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +21 -21
  3. package/README.md +385 -393
  4. package/harmony/rn_webview/.gitignore +6 -0
  5. package/harmony/rn_webview/BuildProfile.ets +1 -1
  6. package/harmony/rn_webview/LICENSE +21 -21
  7. package/harmony/rn_webview/NOTICE +33 -33
  8. package/harmony/rn_webview/OAT.xml +44 -44
  9. package/harmony/rn_webview/README.OpenSource +10 -10
  10. package/harmony/rn_webview/build-profile.json5 +28 -28
  11. package/harmony/rn_webview/index.ets +33 -33
  12. package/harmony/rn_webview/obfuscation-rules.txt +17 -17
  13. package/harmony/rn_webview/oh-package-lock.json5 +18 -18
  14. package/harmony/rn_webview/oh-package.json5 +13 -13
  15. package/harmony/rn_webview/src/main/cpp/CMakeLists.txt +9 -9
  16. package/harmony/rn_webview/src/main/cpp/WebViewPackage.h +36 -36
  17. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/BaseReactNativeWebviewPackage.h +94 -94
  18. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/components/RNCWebViewJSIBinder.h +129 -128
  19. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCWebView.cpp +20 -20
  20. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCWebView.h +16 -16
  21. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCWebViewModule.cpp +19 -19
  22. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCWebViewModule.h +16 -16
  23. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/ComponentDescriptors.h +22 -22
  24. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/EventEmitters.cpp +240 -240
  25. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/EventEmitters.h +285 -285
  26. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/Props.cpp +156 -155
  27. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/Props.h +340 -339
  28. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/ShadowNodes.cpp +19 -19
  29. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/ShadowNodes.h +34 -34
  30. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/States.cpp +16 -16
  31. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/States.h +19 -19
  32. package/harmony/rn_webview/src/main/ets/CutomReference.ts +49 -49
  33. package/harmony/rn_webview/src/main/ets/Logger.ts +63 -63
  34. package/harmony/rn_webview/src/main/ets/Magic.ets +223 -221
  35. package/harmony/rn_webview/src/main/ets/RNCWebView.ets +1098 -903
  36. package/harmony/rn_webview/src/main/ets/RNCWebViewPackage.ets +65 -65
  37. package/harmony/rn_webview/src/main/ets/ShouldRequestUrl.ts +67 -67
  38. package/harmony/rn_webview/src/main/ets/WebViewBaseOperate.ets +490 -490
  39. package/harmony/rn_webview/src/main/ets/WebViewTurboModule.ets +81 -81
  40. package/harmony/rn_webview/src/main/ets/generated/components/RNCWebView.ts +516 -511
  41. package/harmony/rn_webview/src/main/ets/generated/components/ts.ts +5 -5
  42. package/harmony/rn_webview/src/main/ets/generated/index.ets +5 -5
  43. package/harmony/rn_webview/src/main/ets/generated/ts.ts +6 -6
  44. package/harmony/rn_webview/src/main/ets/generated/turboModules/RNCWebView.ts +18 -18
  45. package/harmony/rn_webview/src/main/ets/generated/turboModules/RNCWebViewModule.ts +16 -16
  46. package/harmony/rn_webview/src/main/ets/generated/turboModules/ts.ts +6 -6
  47. package/harmony/rn_webview/src/main/module.json5 +10 -10
  48. package/harmony/rn_webview/src/main/resources/base/element/string.json +39 -39
  49. package/harmony/rn_webview/src/main/resources/en_US/element/string.json +39 -39
  50. package/harmony/rn_webview/src/main/resources/zh_CN/element/string.json +39 -39
  51. package/harmony/rn_webview/src/test/List.test.ets +4 -4
  52. package/harmony/rn_webview/src/test/LocalUnit.test.ets +32 -32
  53. package/harmony/rn_webview/ts.ets +28 -28
  54. package/harmony/rn_webview.har +0 -0
  55. package/package.json +105 -104
  56. package/src/NativeRNCWebView.ts +15 -15
  57. package/src/NativeRNCWebViewModule.ts +17 -17
  58. package/src/RNCWebViewNativeComponent.ts +289 -288
  59. package/src/WebView.harmony.tsx +331 -331
  60. package/src/WebView.tsx +4 -4
  61. package/src/codegenUtils.ts +8 -8
  62. package/src/index.ts +4 -4
@@ -1,332 +1,332 @@
1
- // Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
2
- // Use of this source code is governed by a Apache-2.0 license that can be
3
- // found in the LICENSE file.
4
-
5
- import React, {
6
- forwardRef,
7
- useCallback,
8
- useImperativeHandle,
9
- useRef
10
- } from 'react';
11
- import { Image, View, ImageSourcePropType, HostComponent } from 'react-native';
12
- import invariant from 'invariant';
13
-
14
- import RNCWebView, { Commands, NativeProps } from './RNCWebViewNativeComponent';
15
- import RNCWebViewModule from './NativeRNCWebViewModule';
16
-
17
- import {
18
- defaultOriginWhitelist,
19
- defaultRenderError,
20
- defaultRenderLoading,
21
- useWebViewLogic,
22
- } from 'react-native-webview/src/WebViewShared';
23
- import {
24
- IOSWebViewProps,
25
- DecelerationRateConstant,
26
- WebViewSourceUri,
27
- } from 'react-native-webview/src/WebViewTypes';
28
-
29
- import styles from 'react-native-webview/src/WebView.styles';
30
- const { resolveAssetSource } = Image;
31
- const processDecelerationRate = (
32
- decelerationRate: DecelerationRateConstant | number | undefined
33
- ) => {
34
- let newDecelerationRate = decelerationRate;
35
- if (newDecelerationRate === 'normal') {
36
- newDecelerationRate = 0.998;
37
- } else if (newDecelerationRate === 'fast') {
38
- newDecelerationRate = 0.99;
39
- }
40
- return newDecelerationRate;
41
- };
42
-
43
- const useWarnIfChanges = <T extends unknown>(value: T, name: string) => {
44
- const ref = useRef(value);
45
- if (ref.current !== value) {
46
- console.warn(
47
- `Changes to property ${name} do nothing after the initial render.`
48
- );
49
- ref.current = value;
50
- }
51
- };
52
-
53
- const WebViewComponent = forwardRef<{}, IOSWebViewProps & { scalesPageToFit: boolean, minimumFontSize: number, thirdPartyCookiesEnabled: boolean, geolocationEnabled: boolean }>(
54
- (
55
- {
56
- fraudulentWebsiteWarningEnabled = true,
57
- javaScriptEnabled = true,
58
- cacheEnabled = true,
59
- originWhitelist = defaultOriginWhitelist,
60
- applicationNameForUserAgent,
61
- ignoreSilentHardwareSwitch,
62
- minimumFontSize,
63
- useSharedProcessPool = true,
64
- textInteractionEnabled = true,
65
- injectedJavaScript,
66
- injectedJavaScriptBeforeContentLoaded,
67
- menuItems,
68
- injectedJavaScriptForMainFrameOnly = true,
69
- injectedJavaScriptBeforeContentLoadedForMainFrameOnly = true,
70
- thirdPartyCookiesEnabled = false,
71
- geolocationEnabled = false,
72
- webviewDebuggingEnabled = false,
73
- injectedJavaScriptObject,
74
- startInLoadingState,
75
- onNavigationStateChange,
76
- onLoadStart,
77
- onCustomMenuSelection,
78
- onError,
79
- onLoad,
80
- onLoadEnd,
81
- onLoadProgress,
82
- onScroll,
83
- onContentProcessDidTerminate: onContentProcessDidTerminateProp,
84
- onFileDownload,
85
- onHttpError: onHttpErrorProp,
86
- onMessage: onMessageProp,
87
- onOpenWindow: onOpenWindowProp,
88
- renderLoading,
89
- renderError,
90
- style,
91
- containerStyle,
92
- source,
93
- nativeConfig,
94
- allowsInlineMediaPlayback,
95
- allowsAirPlayForMediaPlayback,
96
- mediaPlaybackRequiresUserAction=true,
97
- dataDetectorTypes,
98
- incognito,
99
- decelerationRate: decelerationRateProp,
100
- onShouldStartLoadWithRequest: onShouldStartLoadWithRequestProp,
101
- onStartShouldSetResponder,
102
- onMoveShouldSetResponderCapture,
103
- pullToRefreshEnabled=false,
104
- onResponderMove,
105
- ...otherProps
106
- },
107
- ref
108
- ) => {
109
- const webViewRef = useRef<React.ComponentRef<
110
- HostComponent<NativeProps>
111
- > | null>(null);
112
-
113
- const onShouldStartLoadWithRequestCallback = useCallback(
114
- (shouldStart: boolean, _url: string, lockIdentifier = 0) => {
115
- RNCWebViewModule.shouldStartLoadWithLockIdentifier(
116
- shouldStart,
117
- lockIdentifier
118
- );
119
- },
120
- []
121
- );
122
-
123
- const {
124
- onLoadingStart,
125
- onShouldStartLoadWithRequest,
126
- onMessage,
127
- viewState,
128
- setViewState,
129
- lastErrorEvent,
130
- onHttpError,
131
- onLoadingError,
132
- onLoadingFinish,
133
- onLoadingProgress,
134
- onOpenWindow,
135
- onContentProcessDidTerminate,
136
- } = useWebViewLogic({
137
- onNavigationStateChange,
138
- onLoad,
139
- onError,
140
- onHttpErrorProp,
141
- onLoadEnd,
142
- onLoadProgress,
143
- // @ts-expect-error old arch only
144
- onScroll,
145
- onLoadStart,
146
- onMessageProp,
147
- onOpenWindowProp,
148
- startInLoadingState,
149
- originWhitelist,
150
- ignoreSilentHardwareSwitch,
151
- minimumFontSize,
152
- onShouldStartLoadWithRequestProp,
153
- onShouldStartLoadWithRequestCallback,
154
- onContentProcessDidTerminateProp,
155
- });
156
-
157
- useImperativeHandle(
158
- ref,
159
- () => ({
160
- goForward: () =>
161
- webViewRef.current && Commands.goForward(webViewRef.current),
162
- goBack: () => webViewRef.current && Commands.goBack(webViewRef.current),
163
- reload: () => {
164
- setViewState('LOADING');
165
- if (webViewRef.current) {
166
- Commands.reload(webViewRef.current);
167
- }
168
- },
169
- stopLoading: () =>
170
- webViewRef.current && Commands.stopLoading(webViewRef.current),
171
- postMessage: (data: string) =>
172
- webViewRef.current && Commands.postMessage(webViewRef.current, data),
173
- injectJavaScript: (data: string) =>
174
- webViewRef.current &&
175
- Commands.injectJavaScript(webViewRef.current, data),
176
- requestFocus: () =>
177
- webViewRef.current && Commands.requestFocus(webViewRef.current),
178
- clearCache: (includeDiskFiles: boolean) =>
179
- webViewRef.current &&
180
- Commands.clearCache(webViewRef.current, includeDiskFiles),
181
- clearHistory: () => webViewRef.current && Commands.clearHistory(webViewRef.current),
182
- loadUrl: (data: string) => webViewRef.current && Commands.loadUrl(webViewRef.current, data),
183
- }),
184
- [setViewState, webViewRef]
185
- );
186
-
187
- useWarnIfChanges(allowsInlineMediaPlayback, 'allowsInlineMediaPlayback');
188
- useWarnIfChanges(
189
- allowsAirPlayForMediaPlayback,
190
- 'allowsAirPlayForMediaPlayback'
191
- );
192
- useWarnIfChanges(incognito, 'incognito');
193
- useWarnIfChanges(
194
- mediaPlaybackRequiresUserAction,
195
- 'mediaPlaybackRequiresUserAction'
196
- );
197
- useWarnIfChanges(dataDetectorTypes, 'dataDetectorTypes');
198
-
199
- let otherView = null;
200
- if (viewState === 'LOADING') {
201
- otherView = (renderLoading || defaultRenderLoading)();
202
- } else if (viewState === 'ERROR') {
203
- invariant(
204
- lastErrorEvent != null,
205
- 'lastErrorEvent expected to be non-null'
206
- );
207
- otherView = (renderError || defaultRenderError)(
208
- lastErrorEvent?.domain,
209
- lastErrorEvent?.code ?? 0,
210
- lastErrorEvent?.description ?? ''
211
- );
212
- } else if (viewState !== 'IDLE') {
213
- console.error(`RNCWebView invalid state encountered: ${viewState}`);
214
- }
215
-
216
- const webViewStyles = [styles.container, styles.webView, style];
217
- const webViewContainerStyle = [styles.container, containerStyle];
218
-
219
- const decelerationRate = processDecelerationRate(decelerationRateProp);
220
-
221
- const NativeWebView =
222
- (nativeConfig?.component as typeof RNCWebView | undefined) || RNCWebView;
223
-
224
- const sourceResolved = resolveAssetSource(source as ImageSourcePropType);
225
- const newSource =
226
- typeof sourceResolved === 'object'
227
- ? Object.entries(sourceResolved as WebViewSourceUri).reduce(
228
- (prev, [currKey, currValue]) => {
229
- return {
230
- ...prev,
231
- [currKey]:
232
- currKey === 'headers' &&
233
- currValue &&
234
- typeof currValue === 'object'
235
- ? Object.entries(currValue).map(([key, value]) => {
236
- return {
237
- name: key,
238
- value,
239
- };
240
- })
241
- : currValue,
242
- };
243
- },
244
- {}
245
- )
246
- : sourceResolved;
247
-
248
- const webView = (
249
- <NativeWebView
250
- key="webViewKey"
251
- {...otherProps}
252
- scrollEnabled={otherProps.scrollEnabled ?? true}
253
- ignoreSilentHardwareSwitch={ignoreSilentHardwareSwitch}
254
- minimumFontSize={minimumFontSize}
255
- scalesPageToFit={otherProps.scalesPageToFit ?? true}
256
- fraudulentWebsiteWarningEnabled={fraudulentWebsiteWarningEnabled}
257
- javaScriptEnabled={javaScriptEnabled}
258
- onCustomMenuSelection={onCustomMenuSelection}
259
- applicationNameForUserAgent={applicationNameForUserAgent}
260
- cacheEnabled={cacheEnabled}
261
- useSharedProcessPool={useSharedProcessPool}
262
- textInteractionEnabled={textInteractionEnabled}
263
- geolocationEnabled={geolocationEnabled}
264
- decelerationRate={decelerationRate}
265
- messagingEnabled={typeof onMessageProp === 'function'}
266
- messagingModuleName="" // android ONLY
267
- onLoadingError={onLoadingError}
268
- onLoadingFinish={onLoadingFinish}
269
- onLoadingProgress={onLoadingProgress}
270
- onScroll={onScroll}
271
- onFileDownload={onFileDownload}
272
- onLoadingStart={onLoadingStart}
273
- onHttpError={onHttpError}
274
- onMessage={onMessage}
275
- onOpenWindow={onOpenWindowProp && onOpenWindow}
276
- hasOnOpenWindowEvent={onOpenWindowProp !== undefined}
277
- onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
278
- originWhitelist={originWhitelist}
279
- hasOnShouldStartLoadWithRequestEvent={onShouldStartLoadWithRequestProp !== undefined}
280
- onContentProcessDidTerminate={onContentProcessDidTerminate}
281
- thirdPartyCookiesEnabled={thirdPartyCookiesEnabled}
282
- pullToRefreshEnabled={pullToRefreshEnabled}
283
- injectedJavaScript={injectedJavaScript}
284
- injectedJavaScriptBeforeContentLoaded={
285
- injectedJavaScriptBeforeContentLoaded
286
- }
287
- injectedJavaScriptForMainFrameOnly={injectedJavaScriptForMainFrameOnly}
288
- injectedJavaScriptBeforeContentLoadedForMainFrameOnly={
289
- injectedJavaScriptBeforeContentLoadedForMainFrameOnly
290
- }
291
- injectedJavaScriptObject={JSON.stringify(injectedJavaScriptObject)}
292
- dataDetectorTypes={
293
- !dataDetectorTypes || Array.isArray(dataDetectorTypes)
294
- ? dataDetectorTypes
295
- : [dataDetectorTypes]
296
- }
297
- allowsAirPlayForMediaPlayback={allowsAirPlayForMediaPlayback}
298
- allowsInlineMediaPlayback={allowsInlineMediaPlayback}
299
- incognito={incognito}
300
- mediaPlaybackRequiresUserAction={mediaPlaybackRequiresUserAction}
301
- menuItems={menuItems}
302
- newSource={newSource}
303
- style={webViewStyles}
304
- webviewDebuggingEnabled={webviewDebuggingEnabled}
305
- hasOnFileDownload={!!onFileDownload}
306
- ref={webViewRef}
307
- // @ts-expect-error old arch only
308
- source={sourceResolved}
309
- {...nativeConfig?.props}
310
- />
311
- );
312
-
313
- return (
314
- <View
315
- style={webViewContainerStyle}
316
- onStartShouldSetResponder={(e) => onStartShouldSetResponder ? onStartShouldSetResponder(e) : false}
317
- onMoveShouldSetResponderCapture={(e) => onMoveShouldSetResponderCapture ? onMoveShouldSetResponderCapture(e) : false}
318
- onResponderMove={(e) => onResponderMove ? onResponderMove(e) : null}
319
- >
320
- {webView}
321
- {otherView}
322
- </View>
323
- );
324
- }
325
- );
326
-
327
- // no native implementation for iOS, depends only on permissions
328
- const isFileUploadSupported: () => Promise<boolean> = async () => true;
329
-
330
- const WebView = Object.assign(WebViewComponent, { isFileUploadSupported });
331
-
1
+ // Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
2
+ // Use of this source code is governed by a Apache-2.0 license that can be
3
+ // found in the LICENSE file.
4
+
5
+ import React, {
6
+ forwardRef,
7
+ useCallback,
8
+ useImperativeHandle,
9
+ useRef
10
+ } from 'react';
11
+ import { Image, View, ImageSourcePropType, HostComponent } from 'react-native';
12
+ import invariant from 'invariant';
13
+
14
+ import RNCWebView, { Commands, NativeProps } from './RNCWebViewNativeComponent';
15
+ import RNCWebViewModule from './NativeRNCWebViewModule';
16
+
17
+ import {
18
+ defaultOriginWhitelist,
19
+ defaultRenderError,
20
+ defaultRenderLoading,
21
+ useWebViewLogic,
22
+ } from 'react-native-webview/src/WebViewShared';
23
+ import {
24
+ IOSWebViewProps,
25
+ DecelerationRateConstant,
26
+ WebViewSourceUri,
27
+ } from 'react-native-webview/src/WebViewTypes';
28
+
29
+ import styles from 'react-native-webview/src/WebView.styles';
30
+ const { resolveAssetSource } = Image;
31
+ const processDecelerationRate = (
32
+ decelerationRate: DecelerationRateConstant | number | undefined
33
+ ) => {
34
+ let newDecelerationRate = decelerationRate;
35
+ if (newDecelerationRate === 'normal') {
36
+ newDecelerationRate = 0.998;
37
+ } else if (newDecelerationRate === 'fast') {
38
+ newDecelerationRate = 0.99;
39
+ }
40
+ return newDecelerationRate;
41
+ };
42
+
43
+ const useWarnIfChanges = <T extends unknown>(value: T, name: string) => {
44
+ const ref = useRef(value);
45
+ if (ref.current !== value) {
46
+ console.warn(
47
+ `Changes to property ${name} do nothing after the initial render.`
48
+ );
49
+ ref.current = value;
50
+ }
51
+ };
52
+
53
+ const WebViewComponent = forwardRef<{}, IOSWebViewProps & { scalesPageToFit: boolean, minimumFontSize: number, thirdPartyCookiesEnabled: boolean, geolocationEnabled: boolean, renderMode: "SYNC_RENDER" | "ASYNC_RENDER" }>(
54
+ (
55
+ {
56
+ fraudulentWebsiteWarningEnabled = true,
57
+ javaScriptEnabled = true,
58
+ cacheEnabled = true,
59
+ originWhitelist = defaultOriginWhitelist,
60
+ applicationNameForUserAgent,
61
+ ignoreSilentHardwareSwitch,
62
+ minimumFontSize,
63
+ useSharedProcessPool = true,
64
+ textInteractionEnabled = true,
65
+ injectedJavaScript,
66
+ injectedJavaScriptBeforeContentLoaded,
67
+ menuItems,
68
+ injectedJavaScriptForMainFrameOnly = true,
69
+ injectedJavaScriptBeforeContentLoadedForMainFrameOnly = true,
70
+ thirdPartyCookiesEnabled = false,
71
+ geolocationEnabled = false,
72
+ webviewDebuggingEnabled = false,
73
+ injectedJavaScriptObject,
74
+ startInLoadingState,
75
+ onNavigationStateChange,
76
+ onLoadStart,
77
+ onCustomMenuSelection,
78
+ onError,
79
+ onLoad,
80
+ onLoadEnd,
81
+ onLoadProgress,
82
+ onScroll,
83
+ onContentProcessDidTerminate: onContentProcessDidTerminateProp,
84
+ onFileDownload,
85
+ onHttpError: onHttpErrorProp,
86
+ onMessage: onMessageProp,
87
+ onOpenWindow: onOpenWindowProp,
88
+ renderLoading,
89
+ renderError,
90
+ style,
91
+ containerStyle,
92
+ source,
93
+ nativeConfig,
94
+ allowsInlineMediaPlayback,
95
+ allowsAirPlayForMediaPlayback,
96
+ mediaPlaybackRequiresUserAction=true,
97
+ dataDetectorTypes,
98
+ incognito,
99
+ decelerationRate: decelerationRateProp,
100
+ onShouldStartLoadWithRequest: onShouldStartLoadWithRequestProp,
101
+ onStartShouldSetResponder,
102
+ onMoveShouldSetResponderCapture,
103
+ pullToRefreshEnabled=false,
104
+ onResponderMove,
105
+ ...otherProps
106
+ },
107
+ ref
108
+ ) => {
109
+ const webViewRef = useRef<React.ComponentRef<
110
+ HostComponent<NativeProps>
111
+ > | null>(null);
112
+
113
+ const onShouldStartLoadWithRequestCallback = useCallback(
114
+ (shouldStart: boolean, _url: string, lockIdentifier = 0) => {
115
+ RNCWebViewModule.shouldStartLoadWithLockIdentifier(
116
+ shouldStart,
117
+ lockIdentifier
118
+ );
119
+ },
120
+ []
121
+ );
122
+
123
+ const {
124
+ onLoadingStart,
125
+ onShouldStartLoadWithRequest,
126
+ onMessage,
127
+ viewState,
128
+ setViewState,
129
+ lastErrorEvent,
130
+ onHttpError,
131
+ onLoadingError,
132
+ onLoadingFinish,
133
+ onLoadingProgress,
134
+ onOpenWindow,
135
+ onContentProcessDidTerminate,
136
+ } = useWebViewLogic({
137
+ onNavigationStateChange,
138
+ onLoad,
139
+ onError,
140
+ onHttpErrorProp,
141
+ onLoadEnd,
142
+ onLoadProgress,
143
+ // @ts-expect-error old arch only
144
+ onScroll,
145
+ onLoadStart,
146
+ onMessageProp,
147
+ onOpenWindowProp,
148
+ startInLoadingState,
149
+ originWhitelist,
150
+ ignoreSilentHardwareSwitch,
151
+ minimumFontSize,
152
+ onShouldStartLoadWithRequestProp,
153
+ onShouldStartLoadWithRequestCallback,
154
+ onContentProcessDidTerminateProp,
155
+ });
156
+
157
+ useImperativeHandle(
158
+ ref,
159
+ () => ({
160
+ goForward: () =>
161
+ webViewRef.current && Commands.goForward(webViewRef.current),
162
+ goBack: () => webViewRef.current && Commands.goBack(webViewRef.current),
163
+ reload: () => {
164
+ setViewState('LOADING');
165
+ if (webViewRef.current) {
166
+ Commands.reload(webViewRef.current);
167
+ }
168
+ },
169
+ stopLoading: () =>
170
+ webViewRef.current && Commands.stopLoading(webViewRef.current),
171
+ postMessage: (data: string) =>
172
+ webViewRef.current && Commands.postMessage(webViewRef.current, data),
173
+ injectJavaScript: (data: string) =>
174
+ webViewRef.current &&
175
+ Commands.injectJavaScript(webViewRef.current, data),
176
+ requestFocus: () =>
177
+ webViewRef.current && Commands.requestFocus(webViewRef.current),
178
+ clearCache: (includeDiskFiles: boolean) =>
179
+ webViewRef.current &&
180
+ Commands.clearCache(webViewRef.current, includeDiskFiles),
181
+ clearHistory: () => webViewRef.current && Commands.clearHistory(webViewRef.current),
182
+ loadUrl: (data: string) => webViewRef.current && Commands.loadUrl(webViewRef.current, data),
183
+ }),
184
+ [setViewState, webViewRef]
185
+ );
186
+
187
+ useWarnIfChanges(allowsInlineMediaPlayback, 'allowsInlineMediaPlayback');
188
+ useWarnIfChanges(
189
+ allowsAirPlayForMediaPlayback,
190
+ 'allowsAirPlayForMediaPlayback'
191
+ );
192
+ useWarnIfChanges(incognito, 'incognito');
193
+ useWarnIfChanges(
194
+ mediaPlaybackRequiresUserAction,
195
+ 'mediaPlaybackRequiresUserAction'
196
+ );
197
+ useWarnIfChanges(dataDetectorTypes, 'dataDetectorTypes');
198
+
199
+ let otherView = null;
200
+ if (viewState === 'LOADING') {
201
+ otherView = (renderLoading || defaultRenderLoading)();
202
+ } else if (viewState === 'ERROR') {
203
+ invariant(
204
+ lastErrorEvent != null,
205
+ 'lastErrorEvent expected to be non-null'
206
+ );
207
+ otherView = (renderError || defaultRenderError)(
208
+ lastErrorEvent?.domain,
209
+ lastErrorEvent?.code ?? 0,
210
+ lastErrorEvent?.description ?? ''
211
+ );
212
+ } else if (viewState !== 'IDLE') {
213
+ console.error(`RNCWebView invalid state encountered: ${viewState}`);
214
+ }
215
+
216
+ const webViewStyles = [styles.container, styles.webView, style];
217
+ const webViewContainerStyle = [styles.container, containerStyle];
218
+
219
+ const decelerationRate = processDecelerationRate(decelerationRateProp);
220
+
221
+ const NativeWebView =
222
+ (nativeConfig?.component as typeof RNCWebView | undefined) || RNCWebView;
223
+
224
+ const sourceResolved = resolveAssetSource(source as ImageSourcePropType);
225
+ const newSource =
226
+ typeof sourceResolved === 'object'
227
+ ? Object.entries(sourceResolved as WebViewSourceUri).reduce(
228
+ (prev, [currKey, currValue]) => {
229
+ return {
230
+ ...prev,
231
+ [currKey]:
232
+ currKey === 'headers' &&
233
+ currValue &&
234
+ typeof currValue === 'object'
235
+ ? Object.entries(currValue).map(([key, value]) => {
236
+ return {
237
+ name: key,
238
+ value,
239
+ };
240
+ })
241
+ : currValue,
242
+ };
243
+ },
244
+ {}
245
+ )
246
+ : sourceResolved;
247
+
248
+ const webView = (
249
+ <NativeWebView
250
+ key="webViewKey"
251
+ {...otherProps}
252
+ scrollEnabled={otherProps.scrollEnabled ?? true}
253
+ ignoreSilentHardwareSwitch={ignoreSilentHardwareSwitch}
254
+ minimumFontSize={minimumFontSize}
255
+ scalesPageToFit={otherProps.scalesPageToFit ?? true}
256
+ fraudulentWebsiteWarningEnabled={fraudulentWebsiteWarningEnabled}
257
+ javaScriptEnabled={javaScriptEnabled}
258
+ onCustomMenuSelection={onCustomMenuSelection}
259
+ applicationNameForUserAgent={applicationNameForUserAgent}
260
+ cacheEnabled={cacheEnabled}
261
+ useSharedProcessPool={useSharedProcessPool}
262
+ textInteractionEnabled={textInteractionEnabled}
263
+ geolocationEnabled={geolocationEnabled}
264
+ decelerationRate={decelerationRate}
265
+ messagingEnabled={typeof onMessageProp === 'function'}
266
+ messagingModuleName="" // android ONLY
267
+ onLoadingError={onLoadingError}
268
+ onLoadingFinish={onLoadingFinish}
269
+ onLoadingProgress={onLoadingProgress}
270
+ onScroll={onScroll}
271
+ onFileDownload={onFileDownload}
272
+ onLoadingStart={onLoadingStart}
273
+ onHttpError={onHttpError}
274
+ onMessage={onMessage}
275
+ onOpenWindow={onOpenWindowProp && onOpenWindow}
276
+ hasOnOpenWindowEvent={onOpenWindowProp !== undefined}
277
+ onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
278
+ originWhitelist={originWhitelist}
279
+ hasOnShouldStartLoadWithRequestEvent={onShouldStartLoadWithRequestProp !== undefined}
280
+ onContentProcessDidTerminate={onContentProcessDidTerminate}
281
+ thirdPartyCookiesEnabled={thirdPartyCookiesEnabled}
282
+ pullToRefreshEnabled={pullToRefreshEnabled}
283
+ injectedJavaScript={injectedJavaScript}
284
+ injectedJavaScriptBeforeContentLoaded={
285
+ injectedJavaScriptBeforeContentLoaded
286
+ }
287
+ injectedJavaScriptForMainFrameOnly={injectedJavaScriptForMainFrameOnly}
288
+ injectedJavaScriptBeforeContentLoadedForMainFrameOnly={
289
+ injectedJavaScriptBeforeContentLoadedForMainFrameOnly
290
+ }
291
+ injectedJavaScriptObject={JSON.stringify(injectedJavaScriptObject)}
292
+ dataDetectorTypes={
293
+ !dataDetectorTypes || Array.isArray(dataDetectorTypes)
294
+ ? dataDetectorTypes
295
+ : [dataDetectorTypes]
296
+ }
297
+ allowsAirPlayForMediaPlayback={allowsAirPlayForMediaPlayback}
298
+ allowsInlineMediaPlayback={allowsInlineMediaPlayback}
299
+ incognito={incognito}
300
+ mediaPlaybackRequiresUserAction={mediaPlaybackRequiresUserAction}
301
+ menuItems={menuItems}
302
+ newSource={newSource}
303
+ style={webViewStyles}
304
+ webviewDebuggingEnabled={webviewDebuggingEnabled}
305
+ hasOnFileDownload={!!onFileDownload}
306
+ ref={webViewRef}
307
+ // @ts-expect-error old arch only
308
+ source={sourceResolved}
309
+ {...nativeConfig?.props}
310
+ />
311
+ );
312
+
313
+ return (
314
+ <View
315
+ style={webViewContainerStyle}
316
+ onStartShouldSetResponder={(e) => onStartShouldSetResponder ? onStartShouldSetResponder(e) : false}
317
+ onMoveShouldSetResponderCapture={(e) => onMoveShouldSetResponderCapture ? onMoveShouldSetResponderCapture(e) : false}
318
+ onResponderMove={(e) => onResponderMove ? onResponderMove(e) : null}
319
+ >
320
+ {webView}
321
+ {otherView}
322
+ </View>
323
+ );
324
+ }
325
+ );
326
+
327
+ // no native implementation for iOS, depends only on permissions
328
+ const isFileUploadSupported: () => Promise<boolean> = async () => true;
329
+
330
+ const WebView = Object.assign(WebViewComponent, { isFileUploadSupported });
331
+
332
332
  export default WebView;
package/src/WebView.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import {WebView} from 'react-native-webview';
2
-
3
- export { WebView };
4
- export default WebView;
1
+ import {WebView} from 'react-native-webview';
2
+
3
+ export { WebView };
4
+ export default WebView;