@react-native-ohos/react-native-webview 13.15.3 → 13.15.4-beta.3

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