@react-native-ohos/react-native-webview 13.10.6-beta.6 → 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.
- package/CHANGELOG.md +14 -23
- package/README.md +102 -113
- package/harmony/rn_webview/BuildProfile.ets +1 -1
- package/harmony/rn_webview/oh-package.json5 +1 -1
- package/harmony/rn_webview/src/main/ets/Magic.ets +1 -0
- package/harmony/rn_webview/src/main/ets/RNCWebView.ets +200 -9
- package/harmony/rn_webview.har +0 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
- update: 更新har包
|
|
1
|
+
# Changelog
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
## [13.10.6] - 2026-08-18
|
|
4
|
+
### Added
|
|
5
|
+
- add landscape/portrait switching for video ([#121](https://gitcode.com/CPF-RN/rntpc_react-native-webview/pull/121))
|
|
6
|
+
- react-native-webview适配嵌套滚动
|
|
7
|
+
- react-native-webview新增renderMode属性
|
|
8
|
+
- react-native-webview适配文本长按禁用选择框
|
|
9
|
+
- react-native-webview适配mediaCapturePermissionGrantType属性
|
|
10
|
+
### Fixed
|
|
11
|
+
- 修改forceDarkOn属性颜色设置错误的问题([#101](https://gitcode.com/CPF-RN/rntpc_react-native-webview/issues/101))
|
|
12
|
+
- 修改web链接校验方案
|
|
6
13
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
# v13.10.6-rc.3
|
|
11
|
-
## 更新内容
|
|
12
|
-
* fix: 修改web链接校验方案
|
|
13
|
-
* chore: 补充example工程
|
|
14
|
-
|
|
15
|
-
# v13.10.6-rc.2
|
|
16
|
-
## 更新内容
|
|
17
|
-
* feat:react-native-webview适配适配文本长按禁用选择框
|
|
18
|
-
|
|
19
|
-
# v13.10.6-rc.1
|
|
20
|
-
## 更新内容
|
|
21
|
-
* feat:react-native-webview适配mediaCapturePermissionGrantType属性
|
|
22
|
-
|
|
23
|
-
# v13.10.5
|
|
24
|
-
## 更新内容
|
|
25
|
-
* 适配autolink
|
|
14
|
+
## v13.10.5
|
|
15
|
+
### Added
|
|
16
|
+
- 适配autolink
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
> 模板版本:v0.4.
|
|
1
|
+
> 模板版本:v0.4.1
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
4
|
<h1 align="center"> <code>react-native-webview</code> </h1>
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
</a>
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
本项目基于 [react-native-webview](https://github.com/react-native-webview/react-native-webview)开发。
|
|
16
16
|
|
|
17
17
|
## 安装与使用
|
|
18
18
|
|
|
@@ -20,12 +20,10 @@
|
|
|
20
20
|
|
|
21
21
|
| 三方库名称 | 三方库版本 | 发布信息 | 支持RN版本 | Autolink | 编译API版本 | 社区基线版本 | npm地址
|
|
22
22
|
| ------------ |---------|---------------------------------------------------------------------------------------------|----------------------|--------------------|-------------------|----------------------------|----------------------------------|
|
|
23
|
-
|@react-native-ohos/react-native-webview| ~13.
|
|
24
|
-
|@react-native-ohos/react-native-webview| ~13.15.1 | [Gitcode Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-webview/releases) | 0.77.* | 否 | API20+ | 13.15.0 | [Npm Address](https://www.npmjs.com/package/@react-native-ohos/react-native-webview)|
|
|
25
|
-
|@react-native-ohos/react-native-webview| ~13.10.5 | [Gitcode Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-webview/releases) | 0.72.* | 是 |API20+ | 13.10.2 | [Npm Address](https://www.npmjs.com/package/@react-native-ohos/react-native-webview)|
|
|
23
|
+
|@react-native-ohos/react-native-webview| ~13.10.5 | [Gitcode Releases](https://gitcode.com/CPF-RN/rntpc_react-native-webview/releases) | 0.72.* | 是 |API20+ | 13.10.2 | [Npm Address](https://www.npmjs.com/package/@react-native-ohos/react-native-webview)|
|
|
26
24
|
|@react-native-oh-tpl/react-native-webview| <=13.10.4@deprecated | [Github Releases(deprecated)](https://github.com/react-native-oh-library/react-native-webview/releases) | 0.72.* | 否 | API12+ | 13.10.2 | [Npm Address](https://www.npmjs.com/package/@react-native-oh-tpl/react-native-webview) |
|
|
27
25
|
|
|
28
|
-
对于未发布到npm的旧版本,请参考[安装指南](/tgz-usage.md)安装tgz包。
|
|
26
|
+
对于未发布到npm的旧版本,请参考[安装指南](https://gitcode.com/CPF-RN/usage-docs/blob/master/zh-cn/tgz-usage.md)安装tgz包。
|
|
29
27
|
|
|
30
28
|
进入到工程目录并输入以下命令:
|
|
31
29
|
|
|
@@ -62,14 +60,12 @@ export default function WebViewDemo() {
|
|
|
62
60
|
|
|
63
61
|
## Link
|
|
64
62
|
|
|
65
|
-
| |
|
|
63
|
+
| | 是否支持 Autolink | 支持的 RN 版本 |
|
|
66
64
|
|--------------------------------------|-----------------------|----------------------|
|
|
67
|
-
| ~13.
|
|
68
|
-
|
|
|
69
|
-
| ~13.10.5 | Yes | 0.72 |
|
|
70
|
-
| <= 13.10.4@deprecated | No | 0.72 |
|
|
65
|
+
| ~13.10.5 | 是 | 0.72 |
|
|
66
|
+
| <= 13.10.4@deprecated | 否 | 0.72 |
|
|
71
67
|
|
|
72
|
-
使用AutoLink的工程需要根据该文档配置,Autolink框架指导文档:https://gitcode.com/
|
|
68
|
+
使用AutoLink的工程需要根据该文档配置,Autolink框架指导文档:https://gitcode.com/CPF-RN/ohos_react_native/blob/master/docs/zh-cn/Autolinking.md
|
|
73
69
|
|
|
74
70
|
如您使用的版本支持 Autolink,并且工程已接入 Autolink,可跳过ManualLink配置。
|
|
75
71
|
<details>
|
|
@@ -120,7 +116,7 @@ ohpm install
|
|
|
120
116
|
|
|
121
117
|
方法二:直接链接源码
|
|
122
118
|
|
|
123
|
-
> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/link-source-code.md)
|
|
119
|
+
> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](https://gitcode.com/CPF-RN/usage-docs/blob/master/zh-cn/link-source-code.md)
|
|
124
120
|
|
|
125
121
|
### 3.配置 CMakeLists 和引入 WebViewPackage
|
|
126
122
|
|
|
@@ -255,8 +251,6 @@ ohpm install
|
|
|
255
251
|
|
|
256
252
|
1. RNOH: 0.72.96; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112;
|
|
257
253
|
2. RNOH: 0.72.33; SDK: HarmonyOS NEXT B1; IDE: DevEco Studio: 5.0.3.900; ROM: Next.0.0.71;
|
|
258
|
-
3. RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112;
|
|
259
|
-
4. RNOH: 0.82.1; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112;
|
|
260
254
|
|
|
261
255
|
## 属性
|
|
262
256
|
> [!WARNING]ignoreSilentHardwareSwitch需要设置true网页播放才有声音
|
|
@@ -267,76 +261,72 @@ ohpm install
|
|
|
267
261
|
|
|
268
262
|
详情请查看[webview 官方文档](https://github.com/react-native-webview/react-native-webview/blob/master/docs/Reference.md)
|
|
269
263
|
|
|
270
|
-
|
|
|
264
|
+
| 名称 | 描述 | 类型 | 必填 | 平台 | 鸿蒙支持 |
|
|
271
265
|
|----------------------------------------------------------| ------------------------------------------------------------ | -------- |----------|---------------------|------------------------------------------------------------------------------------|
|
|
272
|
-
| `source` |
|
|
273
|
-
| `ref` |
|
|
274
|
-
| `injectedJavaScript?` |
|
|
275
|
-
| `originWhitelist?` |
|
|
276
|
-
| `scalesPageToFit?` |
|
|
277
|
-
| `startInLoadingState?` |
|
|
278
|
-
| `style?` |
|
|
279
|
-
| `domStorageEnabled?` |
|
|
280
|
-
| `javaScriptEnabled?` |
|
|
281
|
-
| `showsHorizontalScrollIndicator?` |
|
|
282
|
-
| `showsVerticalScrollIndicator` |
|
|
283
|
-
| `ignoreSilentHardwareSwitch` |
|
|
284
|
-
| `cacheEnabled?` |
|
|
285
|
-
| `cacheMode?` |
|
|
286
|
-
| `textZoom?` |
|
|
287
|
-
| `incognito?` |
|
|
288
|
-
| `mediaPlaybackRequiresUserAction?` |
|
|
289
|
-
| `geolocationEnabled?` |
|
|
290
|
-
| `fraudulentWebsiteWarningEnabled?` |
|
|
291
|
-
| `userAgent?` |
|
|
292
|
-
| `minimumFontSize?` | Android
|
|
293
|
-
| `forceDarkOn?` |
|
|
294
|
-
| `injectedJavaScriptBeforeContentLoaded?` |
|
|
295
|
-
| `automaticallyAdjustContentInsets?` |
|
|
296
|
-
| `automaticallyAdjustsScrollIndicatorInsets?` |
|
|
297
|
-
| `injectedJavaScriptBeforeContentLoadedForMainFrameOnly?` |
|
|
298
|
-
| `nativeConfig?` |
|
|
299
|
-
| `decelerationRate?` |
|
|
300
|
-
| `javaScriptCanOpenWindowsAutomatically?` |
|
|
301
|
-
| `AndroidLayerType?` |
|
|
302
|
-
| `mixedContentMode?`
|
|
303
|
-
| `allowsFullscreenVideo?` |
|
|
304
|
-
| `allowsInlineMediaPlayback?` |
|
|
305
|
-
| `allowsAirPlayForMediaPlayback?` |
|
|
306
|
-
| `contentInset?` |
|
|
307
|
-
| `contentInsetAdjustmentBehavior?` |
|
|
308
|
-
| `contentMode?` |
|
|
309
|
-
| `dataDetectorTypes?` |
|
|
310
|
-
| `setBuiltInZoomControls?` |
|
|
311
|
-
| `setDisplayZoomControls?` |
|
|
312
|
-
| `directionalLockEnabled?` |
|
|
313
|
-
| `allowFileAccessFromFileURLs?` |
|
|
314
|
-
| `allowUniversalAccessFromFileURLs?` | boolean |
|
|
315
|
-
| `allowingReadAccessToURL` |
|
|
316
|
-
| `keyboardDisplayRequiresUserAction?` |
|
|
317
|
-
| `hideKeyboardAccessoryView?` |
|
|
318
|
-
| `allowsBackForwardNavigationGestures?` |
|
|
319
|
-
| `allowFileAccess?` |
|
|
320
|
-
| `saveFormDataDisabled?` |
|
|
321
|
-
| `pagingEnabled?` |
|
|
322
|
-
| `allowsLinkPreview?` |
|
|
323
|
-
| `sharedCookiesEnabled?` |
|
|
324
|
-
| `limitsNavigationsToAppBoundDomains?` |
|
|
325
|
-
| `textInteractionEnabled?` |
|
|
326
|
-
| `suppressMenuItems?` |
|
|
327
|
-
| `mediaCapturePermissionGrantType?` |
|
|
328
|
-
| `autoManageStatusBarEnabled?` |
|
|
329
|
-
| `basicAuthCredential`? |
|
|
330
|
-
| `useWebView2?` |
|
|
331
|
-
| `applicationNameForUserAgent?` |
|
|
332
|
-
| `thirdPartyCookiesEnabled?` |
|
|
333
|
-
| `menuItems?` |
|
|
334
|
-
| `
|
|
335
|
-
| `
|
|
336
|
-
| `refreshControlLightMode<sup>13.15.1+</sup>` | (ios only) Boolean value that determines whether the refresh control color is white or not.The default value is `false`. | boolean | No | iOS | No |
|
|
337
|
-
| `indicatorStyle <sup>13.15.1+</sup>` | The colorstyle of the scroll indicator. | string | No | iOS, Android | No |
|
|
338
|
-
| `renderMode` | This property is used to control the rendering mode of web components and is a property unique to OpenHarmony. enum: `SYNC_RENDER`(default), `ASYNC_RENDER` | string | No | - | Yes |
|
|
339
|
-
| `scrollEnabled` | Boolean value that determines whether scrolling is enabled in the WebView. The default value is true. Setting this to false will prevent the webview from moving the document body when the keyboard appears over an input. The default value is `false`. | boolean | No | iOS and macOS | Yes |
|
|
266
|
+
| `source` | 在 WebView 中加载静态 HTML 或 URI(可选附带 headers) | object | 是 | All | 部分支持(仅支持:**加载 URI:** uri headers **静态 HTML:** html baseUrl) |
|
|
267
|
+
| `ref` | 用于获取组件实例的引用 | object | 是 | All | 是 |
|
|
268
|
+
| `injectedJavaScript?` | 设置在页面文档加载完成后注入到网页中的 JavaScript 代码 | string | 否 | All | 是 |
|
|
269
|
+
| `originWhitelist?` | 允许导航到的来源字符串列表。 | string[] | 否 | iOS,Android,macOS | 否 |
|
|
270
|
+
| `scalesPageToFit?` | 布尔值,控制网页内容是否缩放以适应视图,并允许用户改变缩放比例。 | boolean | 否 | Android | 是 |
|
|
271
|
+
| `startInLoadingState?` | 布尔值,强制 WebView 在首次加载时显示加载视图。 | boolean | 否 | iOS,Android,macOS | 否 |
|
|
272
|
+
| `style?` | 样式对象,用于自定义 WebView 的样式。 | Style | 否 | ALL | 是 |
|
|
273
|
+
| `domStorageEnabled?` | 布尔值,控制是否启用 DOM Storage。仅在 Android 和鸿蒙上使用。 | boolean | 否 | Android | 是 |
|
|
274
|
+
| `javaScriptEnabled?` | 布尔值,控制是否在 WebView 中启用 JavaScript。 | boolean | 否 | All | 是 |
|
|
275
|
+
| `showsHorizontalScrollIndicator?` | 布尔值,控制是否在 WebView 中显示水平滚动指示器。 | boolean | 否 | iOS,Android,macOS | 是 |
|
|
276
|
+
| `showsVerticalScrollIndicator` | 布尔值,控制是否在 WebView 中显示垂直滚动指示器。 | boolean | 否 | iOS,Android,macOS | 是 |
|
|
277
|
+
| `ignoreSilentHardwareSwitch` | 布尔值,设置为 true 时将忽略硬件静音开关。 | boolean | 否 | iOS | 是 |
|
|
278
|
+
| `cacheEnabled?` | 设置 WebView 是否使用浏览器缓存。 | boolean | 否 | iOS,Android,macOS | 是 |
|
|
279
|
+
| `cacheMode?` | 覆盖缓存的使用方式。 | string | 否 | Android | 是 |
|
|
280
|
+
| `textZoom?` | 如果用户在 Android 和鸿蒙系统中设置了自定义字体大小,WebView 中的网页界面会发生不必要的缩放。 | number | 否 | Android | 是 |
|
|
281
|
+
| `incognito?` | 在 WebView 的生命周期内不存储任何数据。 | boolean | 否 | All | 是 |
|
|
282
|
+
| `mediaPlaybackRequiresUserAction?` | 布尔值,决定 HTML5 音视频是否需要用户点击后才能开始播放。默认值为 `true`。(Android API 最低版本 17)。 | boolean | 否 | iOS,Android,macOS | 是 |
|
|
283
|
+
| `geolocationEnabled?` | 设置是否在 `WebView` 中启用地理位置功能。默认值为 `false`。仅在 Android 上使用。 | boolean | 否 | Android | 是 |
|
|
284
|
+
| `fraudulentWebsiteWarningEnabled?` | 布尔值,指示 Web 视图是否对可疑欺诈内容(如恶意软件或钓鱼攻击)显示警告。默认值为 `true`。(iOS 13+) | boolean | 否 | iOS | 是(该接口不生效,调用不会产生任何实际效果,非法和欺诈网站是强制启用的,鸿蒙 OS 当前实现如此。) |
|
|
285
|
+
| `userAgent?` | 为 `WebView` 设置 User-Agent。 | string | 否 | iOS,Android,macOS | 是 |
|
|
286
|
+
| `minimumFontSize?` | Android 根据此值强制设置最小字体大小。取值为 1 到 72 之间的非负整数。超出范围的值将被限定。默认值为 8。如果使用较小的字体大小且无法将整个窗口适配到一屏,尝试将此值设为更小的值。 | number | 否 | Android | 是 |
|
|
287
|
+
| `forceDarkOn?` | 配置深色主题 | boolean | 否 | Android | 是(依赖系统开启深色模式) |
|
|
288
|
+
| `injectedJavaScriptBeforeContentLoaded?` | 设置在文档元素创建后、其他子资源完成加载前注入到网页中的 JavaScript 代码。 | string | 否 | iOS,Android,macOS | 是 |
|
|
289
|
+
| `automaticallyAdjustContentInsets?` | 控制是否为放置在导航栏、标签栏或工具栏后面的 Web 视图调整内容间距。默认值为 `true` | boolean | 否 | iOS | 否 |
|
|
290
|
+
| `automaticallyAdjustsScrollIndicatorInsets?` | 控制是否为放置在导航栏、标签栏或工具栏后面的 Web 视图调整滚动指示器间距。默认值为 `false`。(iOS 13+) | boolean | 否 | iOS | 否 |
|
|
291
|
+
| `injectedJavaScriptBeforeContentLoadedForMainFrameOnly?` | 如果为 `true`(默认值;Android 下为必填),仅在主框架中加载 `injectedJavaScriptBeforeContentLoaded`。 | boolean | 否 | iOS | 否 |
|
|
292
|
+
| `nativeConfig?` | 覆盖用于渲染 WebView 的原生组件。允许使用与原 WebView 相同 JavaScript 的自定义原生 WebView。 | object | 否 | iOS, Android, macOS | 否 |
|
|
293
|
+
| `decelerationRate?` | 浮点数,决定用户抬起手指后滚动视图减速的速度。也可使用字符串快捷方式 `"normal"` 和 `"fast"`,对应 iOS 底层实现。 | number | 否 | iOS | 否 |
|
|
294
|
+
| `javaScriptCanOpenWindowsAutomatically?` | 布尔值,指示 JavaScript 是否可以在没有用户交互的情况下打开窗口。默认值为 `false`。 | boolean | 否 | iOS, Android, macOS | 否 |
|
|
295
|
+
| `AndroidLayerType?` | 指定图层类型。 | string | 否 | Android | 否 |
|
|
296
|
+
| `mixedContentMode?` |指定混合内容模式。即 WebView 是否允许安全来源加载来自任何其他来源的内容。 | string | 否 | Android | 否 |
|
|
297
|
+
| `allowsFullscreenVideo?` | 布尔值,决定是否允许视频全屏播放。默认值为 false。 | boolean | 否 | Android | 否 |
|
|
298
|
+
| `allowsInlineMediaPlayback?` | 布尔值,决定 HTML5 视频是内联播放还是使用原生全屏控制器。默认值为 `false`。 | boolean | 否 | iOS | 否 |
|
|
299
|
+
| `allowsAirPlayForMediaPlayback?` | 布尔值,指示是否允许 AirPlay。默认值为 `false`。 | boolean | 否 | iOS and macOS | 否 |
|
|
300
|
+
| `contentInset?` | Web 视图内容与滚动视图边缘的间距量。默认为 {top: 0, left: 0, bottom: 0, right: 0}。 | object | 否 | iOS | 否 |
|
|
301
|
+
| `contentInsetAdjustmentBehavior?` | 此属性指定如何使用安全区域间距来修改滚动视图的内容区域。此属性的默认值为 "never"。iOS 11 及以上可用。默认为 `never`。 | string | 否 | iOS | 否 |
|
|
302
|
+
| `contentMode?` | 控制加载的内容类型。iOS 13 及以上可用。默认为 `recommended`,即在 iPhone 和 iPad Mini 上加载移动端内容,在更大的 iPad 上加载桌面端内容。 | string | 否 | iOS | 否 |
|
|
303
|
+
| `dataDetectorTypes?` | 决定 Web 视图内容中哪些类型的数据被转换为可点击的 URL。默认仅检测电话号码。 | string, or array | 否 | ios | 否 |
|
|
304
|
+
| `setBuiltInZoomControls?` | 设置 WebView 是否使用其内置缩放机制。默认值为 `true`。设置为 `false` 将阻止使用捏合手势控制缩放。 | boolean | 否 | Android | 否 |
|
|
305
|
+
| `setDisplayZoomControls?` | 设置使用内置缩放机制时 WebView 是否显示屏幕缩放控件(参见 `setBuiltInZoomControls`)。默认值为 `false`。 | boolean | 否 | Android | 否 |
|
|
306
|
+
| `directionalLockEnabled?` | 布尔值,决定是否在特定方向上禁用滚动。默认值为 `true`。 | boolean | 否 | iOS | 否 |
|
|
307
|
+
| `allowFileAccessFromFileURLs?` | 布尔值,设置在 file 协议 URL 上下文中运行的 JavaScript 是否允许访问其他 file 协议 URL 的内容。默认值为 `false`。 | boolean | 否 | iOS, Android, macOS | 否 |
|
|
308
|
+
| `allowUniversalAccessFromFileURLs?` | boolean | 否 | 否 | iOS, Android, macOS | 否 |
|
|
309
|
+
| `allowingReadAccessToURL` | 字符串值,指示 WebView 的文件可以在脚本、AJAX 请求和 CSS 导入中引用哪些 URL。仅适用于通过 `source.uri` 设置为 `'file://'` URL 加载的 WebView。如未提供,默认仅允许对 `source.uri` 中提供的 URL 进行读取访问。 | string | 否 | iOS and macOS | 否 |
|
|
310
|
+
| `keyboardDisplayRequiresUserAction?` | 如果为 `false`,网页内容可以通过编程方式显示键盘。默认值为 `true`。 | boolean | 否 | iOS and macOS | 否 |
|
|
311
|
+
| `hideKeyboardAccessoryView?` | 如果为 `true`,将隐藏键盘附件视图(< > 和 Done)。 | boolean | 否 | iOS | 否 |
|
|
312
|
+
| `allowsBackForwardNavigationGestures?` | 如果为 `true`,将支持水平滑动手势。默认值为 `false`。 | boolean | 否 | iOS | 否 |
|
|
313
|
+
| `allowFileAccess?` | 如果为 `true`,将允许通过 `file://` URI 访问文件系统。默认值为 `false`。 | boolean | 否 | Android | 否 |
|
|
314
|
+
| `saveFormDataDisabled?` | 设置 WebView 是否禁用保存表单数据。默认值为 `false`。从 Android API 26 级开始此功能不再有效,因为有自动填充功能来存储表单数据。 | boolean | 否 | Android | 否 |
|
|
315
|
+
| `pagingEnabled?` | 如果此属性值为 `true`,滚动视图在用户滚动时会停在滚动视图边界的倍数位置。默认值为 `false`。 | boolean | 否 | iOS | 否 |
|
|
316
|
+
| `allowsLinkPreview?` | 布尔值,决定点击链接时是否显示链接目标的预览。在 iOS 中,此属性在支持 3D Touch 的设备上可用。iOS 10 及以上默认值为 `true`;之前默认值为 `false`。 | boolean | 否 | iOS and macOS | 否 |
|
|
317
|
+
| `sharedCookiesEnabled?` | 如果为 `true`,每次 WebView 加载请求时将使用 `[NSHTTPCookieStorage sharedHTTPCookieStorage]` 中的共享 Cookie。默认值为 `false`。更多关于 Cookie 的信息,请阅读 [指南](https://github.com/react-native-webview/react-native-webview/blob/master/docs/Guide.md#Managing-Cookies) | boolean | 否 | iOS and macOS | 否 |
|
|
318
|
+
| `limitsNavigationsToAppBoundDomains?` | 如果为 `true`,向 WebKit 表明 WKWebView 将仅在应用绑定的域中导航。仅适用于 iOS 14 或更高版本。 | boolean | 否 | iOS | 否 |
|
|
319
|
+
| `textInteractionEnabled?` | 如果为 false,向 WebKit 表明 WKWebView 不会与文本交互,因此不显示文本选择循环。仅适用于 iOS 14.5 或更高版本。 | boolean | 否 | iOS | 否 |
|
|
320
|
+
| `suppressMenuItems?` | 允许从默认上下文菜单中隐藏菜单项。 | array of strings | 否 | iOS | 否 |
|
|
321
|
+
| `mediaCapturePermissionGrantType?` | 此属性指定如何处理媒体捕获权限请求。默认为 `prompt`,即反复提示用户。iOS 15 及以上可用。 | string | 否 | iOS | 是 |
|
|
322
|
+
| `autoManageStatusBarEnabled?` | 如果设置为 `true`,WebView 将自动隐藏/显示状态栏,特别是在观看全屏视频时。如果为 `false`,WebView 将完全不管理状态栏。默认值为 `true`。 | boolean | 否 | iOS | 否 |
|
|
323
|
+
| `basicAuthCredential`? | 对象,指定用于基本身份验证的用户凭据。 | object | 否 | iOS, Android | 否 |
|
|
324
|
+
| `useWebView2?` | 使用 WinUI WebView2 控件代替 WebView 控件作为原生 Web 视图。WebView2 控件是使用 Microsoft Edge (Chromium) 渲染引擎渲染网页内容的 WinUI 控件。可在运行时切换并支持 Fast Refresh。 | boolean | 否 | Windows | 否 |
|
|
325
|
+
| `applicationNameForUserAgent?` | 追加到现有的 User-Agent。设置 `userAgent` 将覆盖此项。 | string | 否 | All | 是 |
|
|
326
|
+
| `thirdPartyCookiesEnabled?` | 布尔值,在 `WebView` 中启用第三方 Cookie。仅在 Android Lollipop 及以上使用,因为 Android Kitkat 及以下和 iOS 上默认启用第三方 Cookie。默认值为 `true`。 | boolean | 否 | All | 是 |
|
|
327
|
+
| `menuItems?` | 自定义菜单项对象数组,在选择文本时显示。空数组将隐藏菜单 | array of objects | 否 | iOS,Android | 是 |
|
|
328
|
+
| `renderMode` | 此属性用于控制 Web 组件的渲染模式,是 OpenHarmony 特有属性。枚举值:`SYNC_RENDER`(默认)、`ASYNC_RENDER` | string | 否 | - | 是 |
|
|
329
|
+
| `scrollEnabled` | 布尔值,决定 WebView 中是否启用滚动。默认值为 true。设置为 false 将阻止键盘出现在输入框上方时 webview 移动文档正文。默认值为 `false`。 | boolean | 否 | iOS and macOS | 是 |
|
|
340
330
|
|
|
341
331
|
|
|
342
332
|
## 事件回调
|
|
@@ -345,47 +335,46 @@ ohpm install
|
|
|
345
335
|
|
|
346
336
|
> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
|
|
347
337
|
|
|
348
|
-
|
|
|
338
|
+
| 名称 | 描述 | 类型 | 必填 | 平台 | 鸿蒙支持 |
|
|
349
339
|
|---------------------------------------------------------------| ------------------------------------------------------------ | -------- | -------- | ----------------------- |-------------------|
|
|
350
|
-
| `onScroll?: (event) => void` |
|
|
351
|
-
| `onHttpError?: (event) => void` |
|
|
352
|
-
| `onLoadStart?: (event) => void` |
|
|
353
|
-
| `onLoad?: (event) => void` |
|
|
354
|
-
| `onOpenWindow?` |
|
|
355
|
-
| `onLoadEnd?: (event) => void` |
|
|
356
|
-
| `onLoadProgress?: (event) => void` |
|
|
357
|
-
| `onMessage?: (event) => void` |
|
|
358
|
-
| `onShouldStartLoadWithRequest?: (event) => void` |
|
|
359
|
-
| `onContentProcessDidTerminate: (event) => void` |
|
|
360
|
-
| `renderLoading?` |
|
|
361
|
-
| `onCustomMenuSelection?` |
|
|
362
|
-
| `onNavigationStateChange?: (event) => void` |
|
|
363
|
-
| `onError: (event) => void` |
|
|
364
|
-
| `onLoadSubResourceError: (event) => void <sup>13.16.1+</sup>` | Function that is sub resource SSL error handling. | function | NO | Android | yes |
|
|
340
|
+
| `onScroll?: (event) => void` | 当 `WebView` 中触发滚动事件时调用的函数。 | function | 否 | iOS and macOS | 是 |
|
|
341
|
+
| `onHttpError?: (event) => void` | 当 `WebView` 收到 HTTP 错误时调用的函数。 | function | 否 | 是 | 是 |
|
|
342
|
+
| `onLoadStart?: (event) => void` | 当 `WebView` 开始加载时调用的函数。 | function | 否 | All | 是 |
|
|
343
|
+
| `onLoad?: (event) => void` | 当 `WebView` 完成加载时调用的函数。 | function | 否 | All | 是 |
|
|
344
|
+
| `onOpenWindow?` | 当 `WebView` 需要打开新窗口时调用的函数。 | function | 否 | iOS, Android, macOS | 否 |
|
|
345
|
+
| `onLoadEnd?: (event) => void` | 当 WebView 加载成功或失败时调用的函数。 | function | 否 | All | 是 |
|
|
346
|
+
| `onLoadProgress?: (event) => void` | 当 WebView 正在加载时调用的函数。 | function | 否 | All | 是 |
|
|
347
|
+
| `onMessage?: (event) => void` | 当 webview 调用 window.ReactNativeWebView.postMessage 时调用的函数。 | function | 否 | iOS,Android,macOS | 是 |
|
|
348
|
+
| `onShouldStartLoadWithRequest?: (event) => void` | 允许自定义处理任何 Web 视图请求的函数。此功能需要与 worker 线程结合使用,相关配置可参考 [worker 线程](https://gitcode.com/CPF-RN/ohos_react_native/blob/master/docs/zh-cn/TurboModule.md#%E8%AE%BE%E7%BD%AE%E8%87%AA%E5%AE%9A%E4%B9%89turbomodule%E8%BF%90%E8%A1%8C%E5%9C%A8worker%E7%BA%BF%E7%A8%8B)的第三步。| function | 否 | iOS,Android,macOS | 是 |
|
|
349
|
+
| `onContentProcessDidTerminate: (event) => void` | 当 `WebView` 内容进程终止时调用的函数。 | function | 否 | iOS and macOS WKWebView | 否 |
|
|
350
|
+
| `renderLoading?` | 返回加载指示器的函数。必须将 `startInLoadingState` 属性设置为 `true` 才能使用此属性。 | function | 否 | iOS, Android, macOS | 否 |
|
|
351
|
+
| `onCustomMenuSelection?` | 当选择自定义菜单项时调用的函数。接收一个 Native 事件,包含三个自定义键:`label`、`key` 和 `selectedText`。 | function | 否 | iOS, Android | 是 |
|
|
352
|
+
| `onNavigationStateChange?: (event) => void` | 当 WebView 开始或结束加载时调用的函数。 | function | 否 | iOS, Android | 是 |
|
|
353
|
+
| `onError: (event) => void` | 处理加载错误的回调函数。 | function | 否 | iOS,Android | 是 |
|
|
365
354
|
## 静态方法
|
|
366
355
|
|
|
367
356
|
> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。
|
|
368
357
|
|
|
369
358
|
> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
|
|
370
359
|
|
|
371
|
-
|
|
|
360
|
+
| 名称 | 描述 | 类型 | 必填 | 平台 | 鸿蒙支持 |
|
|
372
361
|
| ---------------------------------- | ------------------------------------------------------------ | -------- | -------- | -------- | ----------------- |
|
|
373
|
-
| `goForward()` |
|
|
374
|
-
| `goBack()` |
|
|
375
|
-
| `reload()` |
|
|
376
|
-
| `stopLoading()` |
|
|
377
|
-
| `injectJavaScript(script: string)` |
|
|
378
|
-
| `requestFocus()` |
|
|
379
|
-
| `postMessage(data:string)` |
|
|
380
|
-
| `clearFormData()` |
|
|
381
|
-
| `clearCache(status:boolean)` |
|
|
382
|
-
| `clearHistory()` |
|
|
362
|
+
| `goForward()` | 在 Web 视图的历史记录中前进一页。 | function | 否 | All | 是 |
|
|
363
|
+
| `goBack()` | 在 Web 视图的历史记录中后退一页。 | function | 否 | All | 是 |
|
|
364
|
+
| `reload()` | 重新加载当前页面。 | function | 否 | All | 是 |
|
|
365
|
+
| `stopLoading()` | 停止加载当前页面。 | function | 否 | All | 是 |
|
|
366
|
+
| `injectJavaScript(script: string)` | 向 WebView 注入 JavaScript 代码。重要提示:此函数必须在调用 onRestoreUserInterfaceForPictureInPictureStop 之后调用。 | function | 否 | All | 是 |
|
|
367
|
+
| `requestFocus()` | 请求 WebView 获取焦点。(开发 TV 应用的用户可能需要关注此项!) | function | 否 | All | 是 |
|
|
368
|
+
| `postMessage(data:string)` | 向 WebView 发送消息,由 `onMessage` 处理。 | function | 否 | All | 是 |
|
|
369
|
+
| `clearFormData()` | 移除当前焦点表单字段上的自动填充弹窗(如果存在)。 | function | 否 | Android | 否 |
|
|
370
|
+
| `clearCache(status:boolean)` | 清除资源缓存。注意缓存是应用级别的,因此会清除所有使用的 WebView 的缓存。 | function | 否 | All | 是 |
|
|
371
|
+
| `clearHistory()` | 通知此 WebView 清除其内部的前进/后退列表。 | function | 否 | Android | 是 |
|
|
383
372
|
|
|
384
373
|
## 遗留问题
|
|
385
374
|
|
|
386
|
-
- [ ] webview 部分属性未实现 HarmonyOS 化[issue#17](https://gitcode.com/
|
|
375
|
+
- [ ] webview 部分属性未实现 HarmonyOS 化[issue#17](https://gitcode.com/CPF-RN/rntpc_react-native-webview/issues/17)
|
|
387
376
|
- [ ] webview 部分属性未实现 HarmonyOS 化[issue#200](https://github.com/react-native-oh-library/react-native-webview/issues/200)
|
|
388
|
-
- [ ] V13.15.1 新增属性未实现 HarmonyOS 化[issue#2](https://gitcode.com/
|
|
377
|
+
- [ ] V13.15.1 新增属性未实现 HarmonyOS 化[issue#2](https://gitcode.com/CPF-RN/rntpc_react-native-webview/issues/2)
|
|
389
378
|
- [X] 中文乱码[issue#18](https://github.com/react-native-oh-library/react-native-webview/issues/18)
|
|
390
379
|
|
|
391
380
|
## 其他
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Use these variables when you tailor your ArkTS code. They must be of the const type.
|
|
3
3
|
*/
|
|
4
|
-
export const HAR_VERSION = '13.10.6
|
|
4
|
+
export const HAR_VERSION = '13.10.6';
|
|
5
5
|
export const BUILD_MODE_NAME = 'debug';
|
|
6
6
|
export const DEBUG = true;
|
|
7
7
|
export const TARGET_NAME = 'default';
|
|
@@ -89,6 +89,7 @@ export interface WebViewProps extends ViewRawProps {
|
|
|
89
89
|
renderMode: "SYNC_RENDER" | "ASYNC_RENDER",
|
|
90
90
|
mediaCapturePermissionGrantType?: 'prompt' | 'grant' | 'deny' | 'grantIfSameHostElsePrompt' | 'grantIfSameHostElseDeny'
|
|
91
91
|
menuItems?: Array<MenuItem> | undefined;
|
|
92
|
+
allowsFullscreenVideo?: boolean;
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
export interface MenuItem {
|
|
@@ -53,6 +53,7 @@ import { abilityAccessCtrl, bundleManager, Permissions } from '@kit.AbilityKit';
|
|
|
53
53
|
import { WebViewTurboModule, ShouldStartParams, ShouldOverrideCallbackState } from './WebViewTurboModule';
|
|
54
54
|
import { AnyThreadRNInstance, WorkerTaskRunnable } from '@rnoh/react-native-openharmony/src/main/ets/RNOH';
|
|
55
55
|
import buffer from '@ohos.buffer';
|
|
56
|
+
import { window } from '@kit.ArkUI';
|
|
56
57
|
|
|
57
58
|
export const TAG = "WebView"
|
|
58
59
|
|
|
@@ -106,6 +107,7 @@ export struct RNCWebView {
|
|
|
106
107
|
@State webviewWidth: number = ZERO
|
|
107
108
|
@State webviewHeight: number = ZERO
|
|
108
109
|
@State isRefreshing: boolean = false
|
|
110
|
+
@State isFullScreen: boolean = false
|
|
109
111
|
@State mode: MixedMode = MixedMode.All;
|
|
110
112
|
private unregisterDescriptorChangesListener?: () => void = undefined
|
|
111
113
|
private cleanupCommandCallback?: () => void = undefined
|
|
@@ -119,10 +121,15 @@ export struct RNCWebView {
|
|
|
119
121
|
private debounceTimer: number = -1
|
|
120
122
|
static readonly DEBOUNCE_TIME: number = 100
|
|
121
123
|
private isFirstDebounce: boolean = true
|
|
124
|
+
private initialOrientation: window.Orientation = window.Orientation.PORTRAIT
|
|
125
|
+
private isOrientationSaved: boolean = false
|
|
126
|
+
private cachedWindow: window.Window | null = null
|
|
127
|
+
private allowsFullscreenVideo: boolean = false
|
|
122
128
|
|
|
123
129
|
aboutToAppear() {
|
|
124
130
|
try {
|
|
125
131
|
this.initVariable()
|
|
132
|
+
this.saveInitialOrientation()
|
|
126
133
|
this.getBundleName()
|
|
127
134
|
this.url = this.source.uri as string;
|
|
128
135
|
this.onDescriptorWrapperChange(this.descriptorWrapper)
|
|
@@ -159,6 +166,20 @@ export struct RNCWebView {
|
|
|
159
166
|
}
|
|
160
167
|
|
|
161
168
|
aboutToDisappear() {
|
|
169
|
+
// 恢复初始屏幕方向和沉浸式状态,防止全屏状态下组件销毁后状态残留
|
|
170
|
+
// 无论是否在全屏状态,都尝试恢复窗口状态(handleFullScreenEnter 异步操作可能在组件销毁后才完成)
|
|
171
|
+
if (this.cachedWindow) {
|
|
172
|
+
try {
|
|
173
|
+
this.cachedWindow.setPreferredOrientation(this.initialOrientation);
|
|
174
|
+
this.cachedWindow.setWindowLayoutFullScreen(false);
|
|
175
|
+
this.cachedWindow.setWindowSystemBarEnable(['status', 'navigation']);
|
|
176
|
+
Logger.debug(TAG, '[WebViewFullScreen] Restored window state in aboutToDisappear');
|
|
177
|
+
} catch (error) {
|
|
178
|
+
Logger.error(TAG, `[WebViewFullScreen] Failed to restore in aboutToDisappear: ${error.code}`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
this.isFullScreen = false;
|
|
182
|
+
this.cachedWindow = null;
|
|
162
183
|
this.getUIContext().getFocusController().clearFocus()
|
|
163
184
|
this.cleanupCommandCallback?.()
|
|
164
185
|
this.unregisterDescriptorChangesListener?.()
|
|
@@ -532,6 +553,151 @@ export struct RNCWebView {
|
|
|
532
553
|
await atManager.requestPermissionsFromUser(this.ctx.uiAbilityContext, permissionList);
|
|
533
554
|
}
|
|
534
555
|
|
|
556
|
+
private async getWindow(): Promise<window.Window | null> {
|
|
557
|
+
try {
|
|
558
|
+
const win = await window.getLastWindow(getContext(this));
|
|
559
|
+
if (win) {
|
|
560
|
+
this.cachedWindow = win;
|
|
561
|
+
}
|
|
562
|
+
return win;
|
|
563
|
+
} catch (error) {
|
|
564
|
+
console.error(TAG, `[WebViewFullScreenTest] getWindow Errorcode: ${error.code}`);
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
private async saveInitialOrientation() {
|
|
570
|
+
const win = await this.getWindow();
|
|
571
|
+
if (win) {
|
|
572
|
+
try {
|
|
573
|
+
const orientation = win.getPreferredOrientation();
|
|
574
|
+
this.initialOrientation = orientation;
|
|
575
|
+
this.isOrientationSaved = true;
|
|
576
|
+
console.debug(TAG, `[WebViewFullScreenTest] Saved initial orientation: ${orientation}`);
|
|
577
|
+
} catch (error) {
|
|
578
|
+
console.error(TAG, `[WebViewFullScreenTest] saveInitialOrientation Errorcode: ${error.code}`);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
private async setOrientation(orientation: window.Orientation): Promise<boolean> {
|
|
584
|
+
const win = await this.getWindow();
|
|
585
|
+
if (win) {
|
|
586
|
+
try {
|
|
587
|
+
await win.setPreferredOrientation(orientation);
|
|
588
|
+
console.debug(TAG, `[WebViewFullScreenTest] Set orientation to: ${orientation}`);
|
|
589
|
+
return true;
|
|
590
|
+
} catch (error) {
|
|
591
|
+
console.error(TAG, `[WebViewFullScreenTest] setOrientation Errorcode: ${error.code}`);
|
|
592
|
+
return false;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// 处理全屏进入(带状态保护和异步串行)
|
|
599
|
+
private async handleFullScreenEnter() {
|
|
600
|
+
if (this.isFullScreen) {
|
|
601
|
+
Logger.debug(TAG, '[WebViewFullScreen] Already in full screen, skipping');
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
if (!this.isOrientationSaved) {
|
|
605
|
+
Logger.warn(TAG, '[WebViewFullScreen] Initial orientation not saved yet, skipping full screen enter');
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
try {
|
|
609
|
+
// 阶段1:设置方向
|
|
610
|
+
const orientationResult = await this.setOrientation(window.Orientation.AUTO_ROTATION);
|
|
611
|
+
if (!orientationResult) {
|
|
612
|
+
Logger.error(TAG, '[WebViewFullScreen] Failed to set orientation, aborting full screen enter');
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
// 阶段2:设置沉浸式模式
|
|
616
|
+
const immersiveResult = await this.enterImmersiveMode();
|
|
617
|
+
if (!immersiveResult) {
|
|
618
|
+
Logger.error(TAG, '[WebViewFullScreen] Failed to enter immersive mode, rolling back');
|
|
619
|
+
// 回滚沉浸式模式(即使部分失败也要尝试恢复)
|
|
620
|
+
await this.exitImmersiveMode();
|
|
621
|
+
// 回滚方向设置
|
|
622
|
+
await this.setOrientation(this.initialOrientation);
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
// 阶段3:所有操作成功,设置状态
|
|
626
|
+
this.isFullScreen = true;
|
|
627
|
+
} catch (error) {
|
|
628
|
+
Logger.error(TAG, `[WebViewFullScreen] Enter full screen failed: ${error}`);
|
|
629
|
+
// 异常时回滚所有操作
|
|
630
|
+
await this.exitImmersiveMode();
|
|
631
|
+
await this.setOrientation(this.initialOrientation);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// 处理全屏退出(带状态保护和异步串行)
|
|
636
|
+
private async handleFullScreenExit() {
|
|
637
|
+
if (!this.isFullScreen) {
|
|
638
|
+
Logger.debug(TAG, '[WebViewFullScreen] Not in full screen, skipping');
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
try {
|
|
642
|
+
// 阶段1:恢复方向
|
|
643
|
+
const orientationResult = await this.setOrientation(this.initialOrientation);
|
|
644
|
+
if (!orientationResult) {
|
|
645
|
+
Logger.error(TAG, '[WebViewFullScreen] Failed to restore orientation, keeping full screen state');
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
// 方向已恢复,清除 isFullScreen 让 UI 恢复原始布局
|
|
649
|
+
this.isFullScreen = false;
|
|
650
|
+
// 阶段2:退出沉浸式模式
|
|
651
|
+
const immersiveResult = await this.exitImmersiveMode();
|
|
652
|
+
if (!immersiveResult) {
|
|
653
|
+
Logger.error(TAG, '[WebViewFullScreen] Failed to exit immersive mode after restoring orientation');
|
|
654
|
+
// 沉浸式模式退出失败,但方向已恢复,isFullScreen 已清除,避免重复触发循环
|
|
655
|
+
}
|
|
656
|
+
} catch (error) {
|
|
657
|
+
Logger.error(TAG, `[WebViewFullScreen] Exit full screen failed: ${error}`);
|
|
658
|
+
// 异常时也应清除状态,避免卡死
|
|
659
|
+
this.isFullScreen = false;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// 进入沉浸式全屏模式(隐藏系统栏)
|
|
664
|
+
private async enterImmersiveMode(): Promise<boolean> {
|
|
665
|
+
const win = await this.getWindow();
|
|
666
|
+
if (win) {
|
|
667
|
+
try {
|
|
668
|
+
// 设置窗口为全屏布局模式,内容延伸到系统栏下方
|
|
669
|
+
await win.setWindowLayoutFullScreen(true);
|
|
670
|
+
// 隐藏系统导航栏和状态栏
|
|
671
|
+
await win.setWindowSystemBarEnable([]);
|
|
672
|
+
Logger.debug(TAG, '[WebViewFullScreen] Entered immersive mode');
|
|
673
|
+
return true;
|
|
674
|
+
} catch (error) {
|
|
675
|
+
console.error(TAG, `[WebViewFullScreen] enterImmersiveMode Errorcode: ${error.code}`);
|
|
676
|
+
return false;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return false;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// 退出沉浸式全屏模式(恢复系统栏)
|
|
683
|
+
private async exitImmersiveMode(): Promise<boolean> {
|
|
684
|
+
const win = await this.getWindow();
|
|
685
|
+
if (win) {
|
|
686
|
+
try {
|
|
687
|
+
// 关闭全屏布局模式
|
|
688
|
+
await win.setWindowLayoutFullScreen(false);
|
|
689
|
+
// 恢复显示系统导航栏和状态栏(默认显示所有系统栏)
|
|
690
|
+
await win.setWindowSystemBarEnable(['status', 'navigation']);
|
|
691
|
+
Logger.debug(TAG, '[WebViewFullScreen] Exited immersive mode');
|
|
692
|
+
return true;
|
|
693
|
+
} catch (error) {
|
|
694
|
+
console.error(TAG, `[WebViewFullScreen] exitImmersiveMode Errorcode: ${error.code}`);
|
|
695
|
+
return false;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
return false;
|
|
699
|
+
}
|
|
700
|
+
|
|
535
701
|
build() {
|
|
536
702
|
Stack() {
|
|
537
703
|
if ( deviceInfo.sdkApiVersion >= 20) {
|
|
@@ -584,8 +750,8 @@ export struct RNCWebView {
|
|
|
584
750
|
}
|
|
585
751
|
}
|
|
586
752
|
})
|
|
587
|
-
.width(this.webviewWidth)
|
|
588
|
-
.height(this.webviewHeight)
|
|
753
|
+
.width(this.isFullScreen ? "100%" : this.webviewWidth)
|
|
754
|
+
.height(this.isFullScreen ? "100%" : this.webviewHeight)
|
|
589
755
|
.fileAccess(this.allowFileAccess)
|
|
590
756
|
.constraintSize({ minHeight: MINHEIGHT })
|
|
591
757
|
.overScrollMode(this.overScrollMode)
|
|
@@ -596,7 +762,7 @@ export struct RNCWebView {
|
|
|
596
762
|
.overviewModeAccess(this.descriptorWrapper.rawProps.scalesPageToFit)
|
|
597
763
|
.textZoomRatio(this.descriptorWrapper.rawProps.textZoom)
|
|
598
764
|
.backgroundColor(BaseOperate.getColorMode(this.ctx.uiAbilityContext,
|
|
599
|
-
this.descriptorWrapper.rawProps.forceDarkOn) === WebDarkMode.On ? Color.
|
|
765
|
+
this.descriptorWrapper.rawProps.forceDarkOn) === WebDarkMode.On ? Color.Black : Color.Transparent)
|
|
600
766
|
.darkMode(BaseOperate.getColorMode(this.ctx.uiAbilityContext, this.descriptorWrapper.rawProps.forceDarkOn))
|
|
601
767
|
.forceDarkAccess(this.forceDark)
|
|
602
768
|
.cacheMode(this.cacheMode)
|
|
@@ -629,6 +795,18 @@ export struct RNCWebView {
|
|
|
629
795
|
.onRenderExited((event: OnRenderExitedEvent) => this.webViewBaseOperate?.onRenderExited(event))
|
|
630
796
|
.onLoadIntercept((event: OnLoadInterceptEvent) => this.onLoadIntercept(event))
|
|
631
797
|
.onTitleReceive((event: OnTitleReceiveEvent) => this.webViewBaseOperate?.onTitleReceive(event))
|
|
798
|
+
.onFullScreenEnter(async () => {
|
|
799
|
+
Logger.debug(TAG, '[WebViewFullScreen] onFullScreenEnter called');
|
|
800
|
+
if (this.allowsFullscreenVideo) {
|
|
801
|
+
await this.handleFullScreenEnter();
|
|
802
|
+
} else {
|
|
803
|
+
Logger.debug(TAG, '[WebViewFullScreen] Fullscreen video disabled by allowsFullscreenVideo');
|
|
804
|
+
}
|
|
805
|
+
})
|
|
806
|
+
.onFullScreenExit(async () => {
|
|
807
|
+
Logger.debug(TAG, '[WebViewFullScreen] onFullScreenExit called');
|
|
808
|
+
await this.handleFullScreenExit();
|
|
809
|
+
})
|
|
632
810
|
.editMenuOptions({
|
|
633
811
|
onCreateMenu: this.onCreateMenu.bind(this),
|
|
634
812
|
onMenuItemClick: this.onMenuItemClick.bind(this),
|
|
@@ -684,8 +862,8 @@ export struct RNCWebView {
|
|
|
684
862
|
}
|
|
685
863
|
})
|
|
686
864
|
|
|
687
|
-
.width(this.webviewWidth)
|
|
688
|
-
.height(this.webviewHeight)
|
|
865
|
+
.width(this.isFullScreen ? "100%" : this.webviewWidth)
|
|
866
|
+
.height(this.isFullScreen ? "100%" : this.webviewHeight)
|
|
689
867
|
.fileAccess(this.allowFileAccess)
|
|
690
868
|
.constraintSize({ minHeight: MINHEIGHT })
|
|
691
869
|
.overScrollMode(this.overScrollMode)
|
|
@@ -696,7 +874,7 @@ export struct RNCWebView {
|
|
|
696
874
|
.overviewModeAccess(this.descriptorWrapper.rawProps.scalesPageToFit)
|
|
697
875
|
.textZoomRatio(this.descriptorWrapper.rawProps.textZoom)
|
|
698
876
|
.backgroundColor(BaseOperate.getColorMode(this.ctx.uiAbilityContext,
|
|
699
|
-
this.descriptorWrapper.rawProps.forceDarkOn) === WebDarkMode.On ? Color.
|
|
877
|
+
this.descriptorWrapper.rawProps.forceDarkOn) === WebDarkMode.On ? Color.Black : Color.Transparent)
|
|
700
878
|
.darkMode(BaseOperate.getColorMode(this.ctx.uiAbilityContext, this.descriptorWrapper.rawProps.forceDarkOn))
|
|
701
879
|
.forceDarkAccess(this.forceDark)
|
|
702
880
|
.cacheMode(this.cacheMode)
|
|
@@ -728,15 +906,27 @@ export struct RNCWebView {
|
|
|
728
906
|
.onRenderExited((event: OnRenderExitedEvent) => this.webViewBaseOperate?.onRenderExited(event))
|
|
729
907
|
.onLoadIntercept((event: OnLoadInterceptEvent) => this.onLoadIntercept(event))
|
|
730
908
|
.onTitleReceive((event: OnTitleReceiveEvent) => this.webViewBaseOperate?.onTitleReceive(event))
|
|
909
|
+
.onFullScreenEnter(async () => {
|
|
910
|
+
Logger.debug(TAG, '[WebViewFullScreen] onFullScreenEnter called');
|
|
911
|
+
if (this.allowsFullscreenVideo) {
|
|
912
|
+
await this.handleFullScreenEnter();
|
|
913
|
+
} else {
|
|
914
|
+
Logger.debug(TAG, '[WebViewFullScreen] Fullscreen video disabled by allowsFullscreenVideo');
|
|
915
|
+
}
|
|
916
|
+
})
|
|
917
|
+
.onFullScreenExit(async () => {
|
|
918
|
+
Logger.debug(TAG, '[WebViewFullScreen] onFullScreenExit called');
|
|
919
|
+
await this.handleFullScreenExit();
|
|
920
|
+
})
|
|
731
921
|
.editMenuOptions({
|
|
732
922
|
onCreateMenu: this.onCreateMenu.bind(this),
|
|
733
923
|
onMenuItemClick: this.onMenuItemClick.bind(this),
|
|
734
924
|
})
|
|
735
925
|
}
|
|
736
926
|
}
|
|
737
|
-
.width(this.webviewWidth)
|
|
738
|
-
.height(this.webviewHeight)
|
|
739
|
-
.position({
|
|
927
|
+
.width(this.isFullScreen ? "100%" : this.webviewWidth)
|
|
928
|
+
.height(this.isFullScreen ? "100%" : this.webviewHeight)
|
|
929
|
+
.position(this.isFullScreen ? undefined : {
|
|
740
930
|
x: this.descriptorWrapper.layoutMetrics.frame.origin.x,
|
|
741
931
|
y: this.descriptorWrapper.layoutMetrics.frame.origin.y
|
|
742
932
|
})
|
|
@@ -843,6 +1033,7 @@ export struct RNCWebView {
|
|
|
843
1033
|
|
|
844
1034
|
const renderModeStr = this.descriptorWrapper.rawProps.renderMode || "SYNC_RENDER"
|
|
845
1035
|
this.renderMode = (renderModeStr === "ASYNC_RENDER") ? RenderMode.ASYNC_RENDER : RenderMode.SYNC_RENDER
|
|
1036
|
+
this.allowsFullscreenVideo = this.descriptorWrapper.rawProps.allowsFullscreenVideo ?? false;
|
|
846
1037
|
|
|
847
1038
|
}
|
|
848
1039
|
|
package/harmony/rn_webview.har
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"Thibault Malbranche <malbranche.thibault@gmail.com>"
|
|
10
10
|
],
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "13.10.6
|
|
12
|
+
"version": "13.10.6",
|
|
13
13
|
"homepage": "https://gitcode.com/openharmony-sig/rntpc_react-native-webview#readme",
|
|
14
14
|
"scripts": {
|
|
15
15
|
"pack": "npm pack --ignore-scripts",
|