@react-native-ohos/react-native-webview 13.10.5-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -0
  3. package/harmony/rn_webview/BuildProfile.ets +41 -0
  4. package/harmony/rn_webview/LICENSE +21 -0
  5. package/harmony/rn_webview/NOTICE +33 -0
  6. package/harmony/rn_webview/OAT.xml +45 -0
  7. package/harmony/rn_webview/README.OpenSource +11 -0
  8. package/harmony/rn_webview/build-profile.json5 +28 -0
  9. package/harmony/rn_webview/consumer-rules.txt +0 -0
  10. package/harmony/rn_webview/hvigorfile.ts +1 -0
  11. package/harmony/rn_webview/index.ets +34 -0
  12. package/harmony/rn_webview/obfuscation-rules.txt +18 -0
  13. package/harmony/rn_webview/oh-package.json5 +13 -0
  14. package/harmony/rn_webview/src/main/cpp/CMakeLists.txt +9 -0
  15. package/harmony/rn_webview/src/main/cpp/WebViewPackage.h +37 -0
  16. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/BaseReactNativeWebviewPackage.h +95 -0
  17. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/components/RNCWebViewJSIBinder.h +126 -0
  18. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCWebView.cpp +20 -0
  19. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCWebView.h +16 -0
  20. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCWebViewModule.cpp +19 -0
  21. package/harmony/rn_webview/src/main/cpp/generated/RNOH/generated/turbo_modules/RNCWebViewModule.h +16 -0
  22. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/ComponentDescriptors.h +22 -0
  23. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/EventEmitters.cpp +240 -0
  24. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/EventEmitters.h +285 -0
  25. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/Props.cpp +151 -0
  26. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/Props.h +337 -0
  27. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/ShadowNodes.cpp +19 -0
  28. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/ShadowNodes.h +34 -0
  29. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/States.cpp +16 -0
  30. package/harmony/rn_webview/src/main/cpp/generated/react/renderer/components/react_native_webview/States.h +20 -0
  31. package/harmony/rn_webview/src/main/ets/CutomReference.ts +50 -0
  32. package/harmony/rn_webview/src/main/ets/Logger.ts +64 -0
  33. package/harmony/rn_webview/src/main/ets/Magic.ets +205 -0
  34. package/harmony/rn_webview/src/main/ets/RNCWebView.ets +607 -0
  35. package/harmony/rn_webview/src/main/ets/RNCWebViewPackage.ets +66 -0
  36. package/harmony/rn_webview/src/main/ets/ShouldRequestUrl.ts +68 -0
  37. package/harmony/rn_webview/src/main/ets/WebViewBaseOperate.ets +463 -0
  38. package/harmony/rn_webview/src/main/ets/WebViewTurboModule.ets +78 -0
  39. package/harmony/rn_webview/src/main/ets/generated/components/RNCWebView.ts +509 -0
  40. package/harmony/rn_webview/src/main/ets/generated/components/ts.ts +5 -0
  41. package/harmony/rn_webview/src/main/ets/generated/index.ets +5 -0
  42. package/harmony/rn_webview/src/main/ets/generated/ts.ts +6 -0
  43. package/harmony/rn_webview/src/main/ets/generated/turboModules/RNCWebView.ts +18 -0
  44. package/harmony/rn_webview/src/main/ets/generated/turboModules/RNCWebViewModule.ts +16 -0
  45. package/harmony/rn_webview/src/main/ets/generated/turboModules/ts.ts +6 -0
  46. package/harmony/rn_webview/src/main/module.json5 +11 -0
  47. package/harmony/rn_webview/src/main/resources/base/element/string.json +40 -0
  48. package/harmony/rn_webview/src/main/resources/en_US/element/string.json +40 -0
  49. package/harmony/rn_webview/src/main/resources/zh_CN/element/string.json +40 -0
  50. package/harmony/rn_webview/src/test/List.test.ets +5 -0
  51. package/harmony/rn_webview/src/test/LocalUnit.test.ets +33 -0
  52. package/harmony/rn_webview/ts.ets +29 -0
  53. package/harmony/rn_webview.har +0 -0
  54. package/package.json +107 -0
  55. package/src/NativeRNCWebView.ts +16 -0
  56. package/src/NativeRNCWebViewModule.ts +17 -0
  57. package/src/RNCWebViewNativeComponent.ts +286 -0
  58. package/src/WebView.harmony.tsx +330 -0
  59. package/src/WebView.tsx +4 -0
  60. package/src/codegenUtils.ts +9 -0
  61. package/src/index.ts +4 -0
@@ -0,0 +1,330 @@
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
+ onContentProcessDidTerminate={onContentProcessDidTerminate}
279
+ thirdPartyCookiesEnabled={thirdPartyCookiesEnabled}
280
+ pullToRefreshEnabled={pullToRefreshEnabled}
281
+ injectedJavaScript={injectedJavaScript}
282
+ injectedJavaScriptBeforeContentLoaded={
283
+ injectedJavaScriptBeforeContentLoaded
284
+ }
285
+ injectedJavaScriptForMainFrameOnly={injectedJavaScriptForMainFrameOnly}
286
+ injectedJavaScriptBeforeContentLoadedForMainFrameOnly={
287
+ injectedJavaScriptBeforeContentLoadedForMainFrameOnly
288
+ }
289
+ injectedJavaScriptObject={JSON.stringify(injectedJavaScriptObject)}
290
+ dataDetectorTypes={
291
+ !dataDetectorTypes || Array.isArray(dataDetectorTypes)
292
+ ? dataDetectorTypes
293
+ : [dataDetectorTypes]
294
+ }
295
+ allowsAirPlayForMediaPlayback={allowsAirPlayForMediaPlayback}
296
+ allowsInlineMediaPlayback={allowsInlineMediaPlayback}
297
+ incognito={incognito}
298
+ mediaPlaybackRequiresUserAction={mediaPlaybackRequiresUserAction}
299
+ menuItems={menuItems}
300
+ newSource={newSource}
301
+ style={webViewStyles}
302
+ webviewDebuggingEnabled={webviewDebuggingEnabled}
303
+ hasOnFileDownload={!!onFileDownload}
304
+ ref={webViewRef}
305
+ // @ts-expect-error old arch only
306
+ source={sourceResolved}
307
+ {...nativeConfig?.props}
308
+ />
309
+ );
310
+
311
+ return (
312
+ <View
313
+ style={webViewContainerStyle}
314
+ onStartShouldSetResponder={(e) => onStartShouldSetResponder ? onStartShouldSetResponder(e) : false}
315
+ onMoveShouldSetResponderCapture={(e) => onMoveShouldSetResponderCapture ? onMoveShouldSetResponderCapture(e) : false}
316
+ onResponderMove={(e) => onResponderMove ? onResponderMove(e) : null}
317
+ >
318
+ {webView}
319
+ {otherView}
320
+ </View>
321
+ );
322
+ }
323
+ );
324
+
325
+ // no native implementation for iOS, depends only on permissions
326
+ const isFileUploadSupported: () => Promise<boolean> = async () => true;
327
+
328
+ const WebView = Object.assign(WebViewComponent, { isFileUploadSupported });
329
+
330
+ export default WebView;
@@ -0,0 +1,4 @@
1
+ import {WebView} from 'react-native-webview';
2
+
3
+ export { WebView };
4
+ export default WebView;
@@ -0,0 +1,9 @@
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
+ export type UnsafeMixed<T> = T;
6
+
7
+ // Fabric doesn't support optional props, so we need to use UnsafeMixed
8
+ // https://github.com/rnmapbox/maps/pull/3082#discussion_r1339858750
9
+ export type OptionalProp<T> = UnsafeMixed<T>;
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ import WebView from './WebView';
2
+
3
+ export { WebView };
4
+ export default WebView;