From 89d1f4d70e1cbb96aeb561abb895fff17cd44662 Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Wed, 2 Jul 2025 22:03:03 +0800 Subject: [PATCH 01/12] =?UTF-8?q?web=E7=9E=AC=E5=BC=80har=E5=8C=85?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=9B=9E=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webprerenderlibrary/Index.ets | 1 + webprerenderlibrary/oh-package.json5 | 2 +- webprerenderlibrary/src/main/ets/common/Constants.ets | 5 ----- .../src/main/ets/common/utils/BreakpointSystem.ets | 2 +- .../src/main/ets/common/utils/WindowUtil.ets | 6 +++--- webprerenderlibrary/src/main/ets/pages/WebPage.ets | 2 +- .../src/main/ets/pages/WebPreRenderPage.ets | 10 +++++----- .../src/main/resources/base/media/layered_image.json | 7 +++---- .../src/main/ets/entryability/EntryAbility.ets | 9 ++++----- webprerendersample/src/main/ets/pages/Index.ets | 8 ++++---- webprerendersample/src/main/module.json5 | 2 +- 11 files changed, 24 insertions(+), 30 deletions(-) diff --git a/webprerenderlibrary/Index.ets b/webprerenderlibrary/Index.ets index 6bb0a6b..829ba6b 100644 --- a/webprerenderlibrary/Index.ets +++ b/webprerenderlibrary/Index.ets @@ -1,2 +1,3 @@ export { WebPreRenderPage } from './src/main/ets/pages/WebPreRenderPage'; + export { WindowUtil } from './src/main/ets/common/utils/WindowUtil'; \ No newline at end of file diff --git a/webprerenderlibrary/oh-package.json5 b/webprerenderlibrary/oh-package.json5 index a63e49e..2065db7 100644 --- a/webprerenderlibrary/oh-package.json5 +++ b/webprerenderlibrary/oh-package.json5 @@ -6,4 +6,4 @@ "author": "", "license": "Apache-2.0", "dependencies": {} -} +} \ No newline at end of file diff --git a/webprerenderlibrary/src/main/ets/common/Constants.ets b/webprerenderlibrary/src/main/ets/common/Constants.ets index 23dc95e..a0312c9 100644 --- a/webprerenderlibrary/src/main/ets/common/Constants.ets +++ b/webprerenderlibrary/src/main/ets/common/Constants.ets @@ -18,27 +18,22 @@ export class Constants { * All breakpoints */ public static readonly BREAKPOINTS: string[] = ['sm', 'md', 'lg']; - /** * Full Screen width */ public static readonly FULL_WIDTH: string = '100%'; - /** * Full Screen height */ public static readonly FULL_HEIGHT: string = '100%'; - /** * Index page padding top size. */ public static readonly PADDING_TOP_INDEX: number = 64; - /** * Index page padding bottom size. */ public static readonly PADDING_BOTTOM_INDEX: number = 16; - /** * Set the url whitelist of the current web */ diff --git a/webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem.ets b/webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem.ets index aa7581b..a6cdb94 100644 --- a/webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem.ets +++ b/webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem.ets @@ -84,7 +84,7 @@ export class BreakpointSystem { public updateCurrentBreakpoint(breakpoint: BreakpointTypeEnum): void { if (this.currentBreakpoint !== breakpoint) { this.currentBreakpoint = breakpoint; - AppStorage.setOrCreate('currentBreakpoint', this.currentBreakpoint); + AppStorage.setOrCreate('webPrerenderBreakpoint', this.currentBreakpoint); } } diff --git a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets index 84b20e5..fbd3862 100644 --- a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets +++ b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets @@ -45,7 +45,7 @@ export class WindowUtil { }); } - public static registerBreakPoint(windowStage: window.WindowStage,ability:UIAbility) { + public static registerBreakPoint(windowStage: window.WindowStage, ability: UIAbility) { windowStage.getMainWindow((err: BusinessError, data: window.Window) => { if (err.code) { hilog.error(0x0000, TAG, `Failed to get main window: ${err.message}`); @@ -67,9 +67,9 @@ export class WindowUtil { // Get status bar height and indicator height. public static setAvoidArea(type: window.AvoidAreaType, area: window.AvoidArea) { if (type === window.AvoidAreaType.TYPE_SYSTEM) { - AppStorage.setOrCreate('topRectHeight', px2vp(area.topRect.height)); + AppStorage.setOrCreate('webPrerenderTopRectHeight', px2vp(area.topRect.height)); } else { - AppStorage.setOrCreate('bottomRectHeight', px2vp(area.bottomRect.height)); + AppStorage.setOrCreate('webPrerenderBottomRectHeight', px2vp(area.bottomRect.height)); } } } \ No newline at end of file diff --git a/webprerenderlibrary/src/main/ets/pages/WebPage.ets b/webprerenderlibrary/src/main/ets/pages/WebPage.ets index b0c4c52..4a4cb80 100644 --- a/webprerenderlibrary/src/main/ets/pages/WebPage.ets +++ b/webprerenderlibrary/src/main/ets/pages/WebPage.ets @@ -17,9 +17,9 @@ import { BuilderNode, FrameNode, NodeController, UIContext } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { common } from '@kit.AbilityKit'; import { webview } from '@kit.ArkWeb'; -import { BusinessError } from '@kit.BasicServicesKit'; import { ConfigMapKey, ResourceUtil } from '../common/ResourceUtil'; import { Constants } from '../common/Constants'; +import { BusinessError } from '@kit.BasicServicesKit'; class Data { public url: string = diff --git a/webprerenderlibrary/src/main/ets/pages/WebPreRenderPage.ets b/webprerenderlibrary/src/main/ets/pages/WebPreRenderPage.ets index 72fb1d2..553b043 100644 --- a/webprerenderlibrary/src/main/ets/pages/WebPreRenderPage.ets +++ b/webprerenderlibrary/src/main/ets/pages/WebPreRenderPage.ets @@ -14,18 +14,18 @@ */ import { common } from '@kit.AbilityKit'; -import { Constants } from '../common/Constants'; import { ConfigMapKey, ResourceUtil } from '../common/ResourceUtil'; import { BreakpointType } from '../common/utils/BreakpointSystem'; +import { Constants } from '../common/Constants'; import { getNWeb } from './WebPage'; @Entry @Component export struct WebPreRenderPage { @State isShowSheet: boolean = false; - @StorageProp('currentBreakpoint') curBp: string = Constants.BREAKPOINTS[1]; - @StorageProp('bottomRectHeight') bottomRectHeight: number = 0; - @StorageProp('topRectHeight') topRectHeight: number = 0; + @StorageProp('webPrerenderBreakpoint') curBp: string = Constants.BREAKPOINTS[1]; + @StorageProp('webPrerenderBottomRectHeight') bottomRectHeight: number = 0; + @StorageProp('webPrerenderTopRectHeight') topRectHeight: number = 0; @Builder mySheet() { @@ -66,7 +66,7 @@ export struct WebPreRenderPage { .margin({ top: $r('sys.float.padding_level6') }) .backgroundColor($r('sys.color.comp_background_emphasize')) .bindSheet(this.isShowSheet, this.mySheet(), { - height: new BreakpointType({sm:748, md:560, lg:560}).getValue(this.curBp), + height: new BreakpointType({ sm: 748, md: 560, lg: 560 }).getValue(this.curBp), width: this.curBp === 'sm' ? '100%' : 480, preferType: SheetType.CENTER, backgroundColor: $r('sys.color.comp_background_primary'), diff --git a/webprerenderlibrary/src/main/resources/base/media/layered_image.json b/webprerenderlibrary/src/main/resources/base/media/layered_image.json index fb49920..4f9ad63 100644 --- a/webprerenderlibrary/src/main/resources/base/media/layered_image.json +++ b/webprerenderlibrary/src/main/resources/base/media/layered_image.json @@ -1,7 +1,6 @@ { - "layered-image": - { - "background" : "$media:background", - "foreground" : "$media:foreground" + "layered-image": { + "background": "$media:background", + "foreground": "$media:foreground" } } \ No newline at end of file diff --git a/webprerendersample/src/main/ets/entryability/EntryAbility.ets b/webprerendersample/src/main/ets/entryability/EntryAbility.ets index 9b46fa0..ee97ecf 100644 --- a/webprerendersample/src/main/ets/entryability/EntryAbility.ets +++ b/webprerendersample/src/main/ets/entryability/EntryAbility.ets @@ -14,12 +14,11 @@ */ import { Configuration, ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; -import { window } from '@kit.ArkUI'; +import { window } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { WindowUtil } from 'webprerenderlibrary'; -export default class WebprerendersampleAbility extends UIAbility { - +export default class WebPrerenderSampleAbility extends UIAbility { onCreate(): void { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); AppStorage.setOrCreate('systemColorMode', this.context.config.colorMode); @@ -48,8 +47,8 @@ export default class WebprerendersampleAbility extends UIAbility { return; } hilog.info(0x0000, 'testTag', '%{public}s', `Succeed in loading the content.`); - WindowUtil.requestFullScreen(windowStage) - WindowUtil.registerBreakPoint(windowStage,this) + WindowUtil.requestFullScreen(windowStage); + WindowUtil.registerBreakPoint(windowStage, this); }); } diff --git a/webprerendersample/src/main/ets/pages/Index.ets b/webprerendersample/src/main/ets/pages/Index.ets index 8b0ab46..84e29a8 100644 --- a/webprerendersample/src/main/ets/pages/Index.ets +++ b/webprerendersample/src/main/ets/pages/Index.ets @@ -23,9 +23,9 @@ import { BreakpointType } from 'webprerenderlibrary/src/main/ets/common/utils/Br @Component struct WebPreRender { @State isShowSheet: boolean = false; - @StorageProp('currentBreakpoint') curBp: string = Constants.BREAKPOINTS[1]; - @StorageProp('bottomRectHeight') bottomRectHeight: number = 0; - @StorageProp('topRectHeight') topRectHeight: number = 0; + @StorageProp('webPrerenderBreakpoint') curBp: string = Constants.BREAKPOINTS[1]; + @StorageProp('webPrerenderBottomRectHeight') bottomRectHeight: number = 0; + @StorageProp('webPrerenderTopRectHeight') topRectHeight: number = 0; @Builder mySheet() { @@ -66,7 +66,7 @@ struct WebPreRender { .margin({ top: $r('sys.float.padding_level6') }) .backgroundColor($r('sys.color.comp_background_emphasize')) .bindSheet(this.isShowSheet, this.mySheet(), { - height: new BreakpointType({sm:748, md:560, lg:560}).getValue(this.curBp), + height: new BreakpointType({ sm: 748, md: 560, lg: 560 }).getValue(this.curBp), width: this.curBp === 'sm' ? '100%' : 480, preferType: SheetType.CENTER, backgroundColor: $r('sys.color.comp_background_primary'), diff --git a/webprerendersample/src/main/module.json5 b/webprerendersample/src/main/module.json5 index 77e38e2..caa15cc 100644 --- a/webprerendersample/src/main/module.json5 +++ b/webprerendersample/src/main/module.json5 @@ -21,7 +21,7 @@ "label": "$string:EntryAbility_label", "startWindowIcon": "$media:startIcon", "startWindowBackground": "$color:start_window_background", - "exported": true, + "exported": false, "skills": [ { "entities": [ -- Gitee From 80318a19bbdd60b7c1c7c80b4b09657fd0768003 Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Thu, 3 Jul 2025 16:32:48 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E8=A7=84=E8=8C=83=EF=BC=9Atry-catch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/common/utils/WindowUtil.ets | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets index fbd3862..bfed1c3 100644 --- a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets +++ b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets @@ -52,13 +52,19 @@ export class WindowUtil { return; } BreakpointSystem.getInstance().updateWidthBp(data); - data.on('windowSizeChange', () => BreakpointSystem.getInstance().onWindowSizeChange(data)); - data.on('avoidAreaChange', (avoidAreaOption) => { - if (avoidAreaOption.type === window.AvoidAreaType.TYPE_SYSTEM || - avoidAreaOption.type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { - WindowUtil.setAvoidArea(avoidAreaOption.type, avoidAreaOption.area); - } - }); + try { + data.on('windowSizeChange', () => BreakpointSystem.getInstance().onWindowSizeChange(data)); + data.on('avoidAreaChange', (avoidAreaOption) => { + if (avoidAreaOption.type === window.AvoidAreaType.TYPE_SYSTEM || + avoidAreaOption.type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { + WindowUtil.setAvoidArea(avoidAreaOption.type, avoidAreaOption.area); + } + }); + } catch (e) { + const error = e as BusinessError; + hilog.error(0x0000, TAG, + `Register avoidAreaChange or windowSizeChange failed. code: ${error.code}, message: ${error.message}`); + } createNWeb(ResourceUtil.getRawFileStringByKey(getContext(ability) as common.UIAbilityContext, ConfigMapKey.GALLERY_URL), data.getUIContext()); }) -- Gitee From 12498411f9b80447597bc137b5396970da425a52 Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Fri, 4 Jul 2025 17:47:01 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E9=81=BF=E8=AE=A9=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/common/utils/BreakpointSystem.ets | 1 + .../src/main/ets/common/utils/WindowUtil.ets | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem.ets b/webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem.ets index a6cdb94..b6b395c 100644 --- a/webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem.ets +++ b/webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem.ets @@ -77,6 +77,7 @@ export class BreakpointSystem { public static getInstance(): BreakpointSystem { if (!BreakpointSystem.instance) { BreakpointSystem.instance = new BreakpointSystem(); + AppStorage.setOrCreate('webPrerenderBreakpoint', BreakpointTypeEnum.MD); } return BreakpointSystem.instance; } diff --git a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets index bfed1c3..085981d 100644 --- a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets +++ b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets @@ -51,8 +51,13 @@ export class WindowUtil { hilog.error(0x0000, TAG, `Failed to get main window: ${err.message}`); return; } - BreakpointSystem.getInstance().updateWidthBp(data); try { + BreakpointSystem.getInstance().updateWidthBp(data); + const systemAvoidArea: window.AvoidArea = data.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); + const navIndicatorAvoidArea: window.AvoidArea = + data.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); + WindowUtil.setAvoidArea(window.AvoidAreaType.TYPE_SYSTEM, systemAvoidArea); + WindowUtil.setAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR, navIndicatorAvoidArea); data.on('windowSizeChange', () => BreakpointSystem.getInstance().onWindowSizeChange(data)); data.on('avoidAreaChange', (avoidAreaOption) => { if (avoidAreaOption.type === window.AvoidAreaType.TYPE_SYSTEM || -- Gitee From 0c0b16efd4b508f86d3a6c11fd172485c0234b18 Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Tue, 8 Jul 2025 16:25:29 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BC=80=E6=BA=90?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webprerenderlibrary/CHANGELOG.md | 6 +++ webprerenderlibrary/LICENSE | 78 ++++++++++++++++++++++++++++ webprerenderlibrary/README.md | 42 +++++++++++++++ webprerenderlibrary/oh-package.json5 | 5 +- 4 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 webprerenderlibrary/CHANGELOG.md create mode 100644 webprerenderlibrary/LICENSE create mode 100644 webprerenderlibrary/README.md diff --git a/webprerenderlibrary/CHANGELOG.md b/webprerenderlibrary/CHANGELOG.md new file mode 100644 index 0000000..b525b8c --- /dev/null +++ b/webprerenderlibrary/CHANGELOG.md @@ -0,0 +1,6 @@ +# 版本记录 +## 1.0.0(2025.07.08) + +--- +### Initial +- 初始版本 diff --git a/webprerenderlibrary/LICENSE b/webprerenderlibrary/LICENSE new file mode 100644 index 0000000..338e5b0 --- /dev/null +++ b/webprerenderlibrary/LICENSE @@ -0,0 +1,78 @@ + Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +Apache License, Version 2.0 +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: +1.You must give any other recipients of the Work or Derivative Works a copy of this License; and +2.You must cause any modified files to carry prominent notices stating that You changed the files; and +3.You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and +4.If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + +You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/webprerenderlibrary/README.md b/webprerenderlibrary/README.md new file mode 100644 index 0000000..a0a3083 --- /dev/null +++ b/webprerenderlibrary/README.md @@ -0,0 +1,42 @@ +## web页面瞬开 + +### 介绍 + +本示例基于预渲染技术,实现了点击后Web页面瞬间打开的效果,无需额外加载过程,减少用户等待时长,提高了用户体验。 + +### 下载安装 + +使用ohpm安装依赖 + +``` +ohpm install @ohos_samples/webprerenderlibrary +``` + +或者按需在模块中修改oh-package.json5 + +``` +{ + "dependencies": { + "@ohos_samples/webprerenderlibrary": "^1.0.0" + } +} +``` + +### 使用说明 + +``` +import { WebPreRenderPage, WindowUtil } from '@ohos_samples/webprerenderlibrary'; +``` +按需在文件中使用导出模块即可,其中WebPreRenderPage是整个sample的入口页面。WindowUtil封装了沉浸式、设备断点判断、避让区域计算等窗口能力。示例如下: +``` +// Page.ets +import { WebPreRenderPage } from '@ohos_samples/webprerenderlibrary'; +Stack() { + WebPreRenderPage() +} + +// EntryAbility.ets +import { WindowUtil } from '@ohos_samples/webprerenderlibrary'; +WindowUtil.requestFullScreen(windowStage); +WindowUtil.registerBreakPoint(windowStage); +``` \ No newline at end of file diff --git a/webprerenderlibrary/oh-package.json5 b/webprerenderlibrary/oh-package.json5 index 2065db7..285992c 100644 --- a/webprerenderlibrary/oh-package.json5 +++ b/webprerenderlibrary/oh-package.json5 @@ -1,9 +1,10 @@ { "name": "webprerenderlibrary", "version": "1.0.0", - "description": "Please describe the basic information.", + "description": "This sample shows how to display the web pages in an instant manner by using pre-rendering.", "main": "Index.ets", - "author": "", + "author": "@ohos_samples", "license": "Apache-2.0", + "repository": "https://gitee.com/harmonyos_samples/web-pre-render/tree/br_release_hmos/", "dependencies": {} } \ No newline at end of file -- Gitee From e8b5f3926f8bde5da548f06462e15338594003c1 Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Thu, 10 Jul 2025 12:23:56 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E8=A7=84=E8=8C=83=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 25 ++++++++++----- README.md | 27 ++++++++++------ webprerenderlibrary/CHANGELOG.md | 2 +- webprerenderlibrary/Index.ets | 4 +-- webprerenderlibrary/README.md | 10 +++--- .../src/main/ets/WebPrerenderController.ets | 23 +++++++++++++ .../src/main/ets/common/Constants.ets | 8 +++++ .../ets/common/utils/BreakpointSystem.ets | 3 +- .../src/main/ets/common/utils/WindowUtil.ets | 32 +++++++++++++------ .../main/ets/{pages => component}/WebPage.ets | 0 .../{pages => component}/WebPreRenderPage.ets | 1 - .../main/ets/entryability/EntryAbility.ets | 16 ++-------- .../src/main/ets/pages/Index.ets | 2 +- webprerendersample/src/main/module.json5 | 2 +- 14 files changed, 103 insertions(+), 52 deletions(-) create mode 100644 webprerenderlibrary/src/main/ets/WebPrerenderController.ets rename webprerenderlibrary/src/main/ets/{pages => component}/WebPage.ets (100%) rename webprerenderlibrary/src/main/ets/{pages => component}/WebPreRenderPage.ets (99%) diff --git a/README.en.md b/README.en.md index cd5d037..b5ec7e9 100644 --- a/README.en.md +++ b/README.en.md @@ -13,17 +13,26 @@ Instructions: ### Project Directory ``` -├──entry/src/main/ets/ +webprerenderlibrary +├──src/main/ets/ │ ├──common -│ │ ├──BreakpointType.ets +│ │ ├──utils +│ │ │ ├──BreakpointSystem.ets +│ │ │ └──WindowUtil.ets │ │ ├──Constants.ets // Common constant class │ │ └──ResourceUtil.ets -│ ├──entryability -│ │ └──EntryAbility.ets // Entry ability -│ └──pages -│ └──Index.ets // Home page -│ └──WebPage.ets // Pre-rendering web page -└──entry/src/main/resources // Static resources +│ └──component +│ │ └──WebPage.ets // Home page +│ │ └──WebPreRenderPage.ets // Pre-rendering web page +│ └──WebPrerenderController.ets +└──src/main/resources // Static resources +webprerendersample +├──src/main/ets // Common constant class +│ ├──entryability +│ │ └──EntryAbility.ets +│ └──pages +│ └──Index.ets // entry page +└──src/main/resources // Static resources ``` ### How to Implement diff --git a/README.md b/README.md index 33f006b..fe8d31a 100644 --- a/README.md +++ b/README.md @@ -13,17 +13,26 @@ ### 工程目录 ``` -├──entry/src/main/ets/ +webprerenderlibrary +├──src/main/ets/ │ ├──common -│ │ ├──BreakpointType.ets +│ │ ├──utils +│ │ │ ├──BreakpointSystem.ets // 断点类 +│ │ │ └──WindowUtil.ets // 窗口工具 │ │ ├──Constants.ets // 公共常量类 -│ │ └──ResourceUtil.ets -│ ├──entryability -│ │ └──EntryAbility.ets // 程序入口类 -│ └──pages -│ ├──Index.ets // 首页 -│ └──WebPage.ets // Web预渲染页面 -└──entry/src/main/resources // 应用静态资源目录 +│ │ └──ResourceUtil.ets +│ └──component +│ │ └──WebPage.ets // 首页 +│ │ └──WebPreRenderPage.ets // Web预渲染页面 +│ └──WebPrerenderController.ets +└──src/main/resources // 静态资源 +webprerendersample +├──src/main/ets +│ ├──entryability +│ │ └──EntryAbility.ets +│ └──pages +│ └──Index.ets // 入口页面 +└──src/main/resources // 应用静态资源目录 ``` ### 具体实现 diff --git a/webprerenderlibrary/CHANGELOG.md b/webprerenderlibrary/CHANGELOG.md index b525b8c..addaa8c 100644 --- a/webprerenderlibrary/CHANGELOG.md +++ b/webprerenderlibrary/CHANGELOG.md @@ -1,5 +1,5 @@ # 版本记录 -## 1.0.0(2025.07.08) +## 1.0.0(2025.07.11) --- ### Initial diff --git a/webprerenderlibrary/Index.ets b/webprerenderlibrary/Index.ets index 829ba6b..89c0ca1 100644 --- a/webprerenderlibrary/Index.ets +++ b/webprerenderlibrary/Index.ets @@ -1,3 +1,3 @@ -export { WebPreRenderPage } from './src/main/ets/pages/WebPreRenderPage'; +export { WebPreRenderPage } from './src/main/ets/component/WebPreRenderPage'; -export { WindowUtil } from './src/main/ets/common/utils/WindowUtil'; \ No newline at end of file +export { WebPrerenderController } from './src/main/ets/WebPrerenderController'; \ No newline at end of file diff --git a/webprerenderlibrary/README.md b/webprerenderlibrary/README.md index a0a3083..1b735f7 100644 --- a/webprerenderlibrary/README.md +++ b/webprerenderlibrary/README.md @@ -25,9 +25,9 @@ ohpm install @ohos_samples/webprerenderlibrary ### 使用说明 ``` -import { WebPreRenderPage, WindowUtil } from '@ohos_samples/webprerenderlibrary'; +import { WebPreRenderPage, WebPrerenderController } from '@ohos_samples/webprerenderlibrary'; ``` -按需在文件中使用导出模块即可,其中WebPreRenderPage是整个sample的入口页面。WindowUtil封装了沉浸式、设备断点判断、避让区域计算等窗口能力。示例如下: +按需在文件中使用导出模块即可,其中WebPreRenderPage是整个sample的入口页面。WebPrerenderController初始化沉浸式、设备断点判断、避让区域计算等窗口能力。示例如下: ``` // Page.ets import { WebPreRenderPage } from '@ohos_samples/webprerenderlibrary'; @@ -36,7 +36,7 @@ Stack() { } // EntryAbility.ets -import { WindowUtil } from '@ohos_samples/webprerenderlibrary'; -WindowUtil.requestFullScreen(windowStage); -WindowUtil.registerBreakPoint(windowStage); +import { WebPrerenderController } from '@ohos_samples/webprerenderlibrary'; +// onWindowStageCreate回调里的loadContent方法里初始化 +WebPrerenderController.initWindowConfig(windowStage, this); ``` \ No newline at end of file diff --git a/webprerenderlibrary/src/main/ets/WebPrerenderController.ets b/webprerenderlibrary/src/main/ets/WebPrerenderController.ets new file mode 100644 index 0000000..3fa54c6 --- /dev/null +++ b/webprerenderlibrary/src/main/ets/WebPrerenderController.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { window } from '@kit.ArkUI'; +import { WindowUtil } from './common/utils/WindowUtil'; +import { UIAbility } from '@kit.AbilityKit'; + +export class WebPrerenderController { + public static initWindowConfig(windowStage: window.WindowStage, ability: UIAbility): void { + WindowUtil.initialize(windowStage, ability); + } +} \ No newline at end of file diff --git a/webprerenderlibrary/src/main/ets/common/Constants.ets b/webprerenderlibrary/src/main/ets/common/Constants.ets index a0312c9..cf29954 100644 --- a/webprerenderlibrary/src/main/ets/common/Constants.ets +++ b/webprerenderlibrary/src/main/ets/common/Constants.ets @@ -39,4 +39,12 @@ export class Constants { */ public static readonly URL_TRUST: string = '{\"UrlPermissionList\": [{\"scheme\": \"https\",\"host\": \"developer.huawei.com\"}]}'; + /** + * AppStorage key + */ + public static readonly KEY_PREFIX: string = 'webPrerender'; + public static readonly KEY_BREAKPOINT: string = Constants.KEY_PREFIX + 'BreakPoint'; + public static readonly KEY_TOP_RECT_HEIGHT: string = Constants.KEY_PREFIX + 'TopRectHeight'; + public static readonly KEY_BOTTOM_RECT_HEIGHT: string = Constants.KEY_PREFIX + 'BottomRectHeight'; + public static readonly KEY_UI_CONTEXT: string = Constants.KEY_PREFIX + 'UIContext'; } \ No newline at end of file diff --git a/webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem.ets b/webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem.ets index b6b395c..0957664 100644 --- a/webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem.ets +++ b/webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem.ets @@ -97,7 +97,8 @@ export class BreakpointSystem { try { const mainWindow: window.WindowProperties = window.getWindowProperties(); const windowWidth: number = mainWindow.windowRect.width; - const windowWidthVp = px2vp(windowWidth); + const context: UIContext = window.getUIContext(); + const windowWidthVp = context.px2vp(windowWidth); let widthBp: BreakpointTypeEnum = BreakpointTypeEnum.MD; if (windowWidthVp < 320) { widthBp = BreakpointTypeEnum.XS; diff --git a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets index 085981d..47e279d 100644 --- a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets +++ b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets @@ -17,13 +17,26 @@ import { window } from '@kit.ArkUI'; import type { BusinessError } from '@kit.BasicServicesKit'; import { BreakpointSystem } from './BreakpointSystem'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { createNWeb } from '../../pages/WebPage'; +import { createNWeb } from '../../component/WebPage'; import { ConfigMapKey, ResourceUtil } from '../ResourceUtil'; import { common, UIAbility } from '@kit.AbilityKit'; +import { Constants } from '../Constants'; const TAG: string = '[WindowUtil]'; export class WindowUtil { + public static initialize(windowStage: window.WindowStage, ability: UIAbility) { + try { + const uiContext: UIContext = windowStage.getMainWindowSync()?.getUIContext(); + AppStorage.setOrCreate(Constants.KEY_UI_CONTEXT, uiContext); + WindowUtil.requestFullScreen(windowStage); + WindowUtil.registerBreakPoint(windowStage, ability); + } catch (err) { + const error = err as BusinessError; + hilog.error(0x0000, TAG, `Initialize failed. Cause code: ${error.code}, message: ${error.message}`); + } + } + public static requestFullScreen(windowStage: window.WindowStage): void { windowStage.getMainWindow((err: BusinessError, data: window.Window) => { if (err.code) { @@ -56,17 +69,17 @@ export class WindowUtil { const systemAvoidArea: window.AvoidArea = data.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); const navIndicatorAvoidArea: window.AvoidArea = data.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); - WindowUtil.setAvoidArea(window.AvoidAreaType.TYPE_SYSTEM, systemAvoidArea); - WindowUtil.setAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR, navIndicatorAvoidArea); + WindowUtil.setAvoidArea(data, window.AvoidAreaType.TYPE_SYSTEM, systemAvoidArea); + WindowUtil.setAvoidArea(data, window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR, navIndicatorAvoidArea); data.on('windowSizeChange', () => BreakpointSystem.getInstance().onWindowSizeChange(data)); data.on('avoidAreaChange', (avoidAreaOption) => { if (avoidAreaOption.type === window.AvoidAreaType.TYPE_SYSTEM || avoidAreaOption.type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { - WindowUtil.setAvoidArea(avoidAreaOption.type, avoidAreaOption.area); + WindowUtil.setAvoidArea(data, avoidAreaOption.type, avoidAreaOption.area); } }); - } catch (e) { - const error = e as BusinessError; + } catch (err) { + const error = err as BusinessError; hilog.error(0x0000, TAG, `Register avoidAreaChange or windowSizeChange failed. code: ${error.code}, message: ${error.message}`); } @@ -76,11 +89,12 @@ export class WindowUtil { } // Get status bar height and indicator height. - public static setAvoidArea(type: window.AvoidAreaType, area: window.AvoidArea) { + public static setAvoidArea(data: window.Window, type: window.AvoidAreaType, area: window.AvoidArea) { + const context: UIContext = data.getUIContext(); if (type === window.AvoidAreaType.TYPE_SYSTEM) { - AppStorage.setOrCreate('webPrerenderTopRectHeight', px2vp(area.topRect.height)); + AppStorage.setOrCreate('webPrerenderTopRectHeight', context.px2vp(area.topRect.height)); } else { - AppStorage.setOrCreate('webPrerenderBottomRectHeight', px2vp(area.bottomRect.height)); + AppStorage.setOrCreate('webPrerenderBottomRectHeight', context.px2vp(area.bottomRect.height)); } } } \ No newline at end of file diff --git a/webprerenderlibrary/src/main/ets/pages/WebPage.ets b/webprerenderlibrary/src/main/ets/component/WebPage.ets similarity index 100% rename from webprerenderlibrary/src/main/ets/pages/WebPage.ets rename to webprerenderlibrary/src/main/ets/component/WebPage.ets diff --git a/webprerenderlibrary/src/main/ets/pages/WebPreRenderPage.ets b/webprerenderlibrary/src/main/ets/component/WebPreRenderPage.ets similarity index 99% rename from webprerenderlibrary/src/main/ets/pages/WebPreRenderPage.ets rename to webprerenderlibrary/src/main/ets/component/WebPreRenderPage.ets index 553b043..a193367 100644 --- a/webprerenderlibrary/src/main/ets/pages/WebPreRenderPage.ets +++ b/webprerenderlibrary/src/main/ets/component/WebPreRenderPage.ets @@ -19,7 +19,6 @@ import { BreakpointType } from '../common/utils/BreakpointSystem'; import { Constants } from '../common/Constants'; import { getNWeb } from './WebPage'; -@Entry @Component export struct WebPreRenderPage { @State isShowSheet: boolean = false; diff --git a/webprerendersample/src/main/ets/entryability/EntryAbility.ets b/webprerendersample/src/main/ets/entryability/EntryAbility.ets index ee97ecf..d80e04a 100644 --- a/webprerendersample/src/main/ets/entryability/EntryAbility.ets +++ b/webprerendersample/src/main/ets/entryability/EntryAbility.ets @@ -16,22 +16,11 @@ import { Configuration, ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { WindowUtil } from 'webprerenderlibrary'; +import { WebPrerenderController } from 'webprerenderlibrary'; export default class WebPrerenderSampleAbility extends UIAbility { onCreate(): void { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - AppStorage.setOrCreate('systemColorMode', this.context.config.colorMode); - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); - } - - onConfigurationUpdate(newConfig: Configuration): void { - let newColorMode: ConfigurationConstant.ColorMode = - newConfig.colorMode || ConfigurationConstant.ColorMode.COLOR_MODE_DARK; - let currentColorMode = AppStorage.get('systemColorMode'); - if (newColorMode !== currentColorMode) { - AppStorage.setOrCreate('systemColorMode', newColorMode); - } } onDestroy(): void { @@ -46,9 +35,8 @@ export default class WebPrerenderSampleAbility extends UIAbility { hilog.error(0x0000, 'testTag', '%{public}s', `Failed to load the content. Cause: ${err.code}`); return; } + WebPrerenderController.initWindowConfig(windowStage, this); hilog.info(0x0000, 'testTag', '%{public}s', `Succeed in loading the content.`); - WindowUtil.requestFullScreen(windowStage); - WindowUtil.registerBreakPoint(windowStage, this); }); } diff --git a/webprerendersample/src/main/ets/pages/Index.ets b/webprerendersample/src/main/ets/pages/Index.ets index 84e29a8..70be494 100644 --- a/webprerendersample/src/main/ets/pages/Index.ets +++ b/webprerendersample/src/main/ets/pages/Index.ets @@ -16,7 +16,7 @@ import { common } from '@kit.AbilityKit'; import { ConfigMapKey, ResourceUtil } from 'webprerenderlibrary/src/main/ets/common/ResourceUtil'; import { Constants } from 'webprerenderlibrary/src/main/ets/common/Constants'; -import { getNWeb } from 'webprerenderlibrary/src/main/ets/pages/WebPage'; +import { getNWeb } from 'webprerenderlibrary/src/main/ets/component/WebPage'; import { BreakpointType } from 'webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem'; @Entry diff --git a/webprerendersample/src/main/module.json5 b/webprerendersample/src/main/module.json5 index caa15cc..77e38e2 100644 --- a/webprerendersample/src/main/module.json5 +++ b/webprerendersample/src/main/module.json5 @@ -21,7 +21,7 @@ "label": "$string:EntryAbility_label", "startWindowIcon": "$media:startIcon", "startWindowBackground": "$color:start_window_background", - "exported": false, + "exported": true, "skills": [ { "entities": [ -- Gitee From 6ff0b59315fc74dbbd53f00ba130c64951245922 Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Thu, 10 Jul 2025 14:50:43 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E8=A7=84=E8=8C=83=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webprerenderlibrary/oh-package.json5 | 2 +- webprerendersample/oh-package-lock.json5 | 18 ----- webprerendersample/oh-package.json5 | 2 +- .../main/ets/entryability/EntryAbility.ets | 4 +- .../src/main/ets/pages/Index.ets | 76 +------------------ 5 files changed, 7 insertions(+), 95 deletions(-) delete mode 100644 webprerendersample/oh-package-lock.json5 diff --git a/webprerenderlibrary/oh-package.json5 b/webprerenderlibrary/oh-package.json5 index 285992c..8f5e8a2 100644 --- a/webprerenderlibrary/oh-package.json5 +++ b/webprerenderlibrary/oh-package.json5 @@ -1,5 +1,5 @@ { - "name": "webprerenderlibrary", + "name": "@ohos_samples/webprerenderlibrary", "version": "1.0.0", "description": "This sample shows how to display the web pages in an instant manner by using pre-rendering.", "main": "Index.ets", diff --git a/webprerendersample/oh-package-lock.json5 b/webprerendersample/oh-package-lock.json5 deleted file mode 100644 index c3369b6..0000000 --- a/webprerendersample/oh-package-lock.json5 +++ /dev/null @@ -1,18 +0,0 @@ -{ - "meta": { - "stableOrder": true - }, - "lockfileVersion": 3, - "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", - "specifiers": { - "webprerenderlibrary@../webprerenderlibrary": "webprerenderlibrary@../webprerenderlibrary" - }, - "packages": { - "webprerenderlibrary@../webprerenderlibrary": { - "name": "webprerenderlibrary", - "version": "1.0.0", - "resolved": "../webprerenderlibrary", - "registryType": "local" - } - } -} \ No newline at end of file diff --git a/webprerendersample/oh-package.json5 b/webprerendersample/oh-package.json5 index 2a4c88b..c84bc8b 100644 --- a/webprerendersample/oh-package.json5 +++ b/webprerendersample/oh-package.json5 @@ -6,6 +6,6 @@ "author": "", "license": "", "dependencies": { - "webprerenderlibrary": "file:../webprerenderlibrary" + "@ohos_samples/webprerenderlibrary": "file:../webprerenderlibrary" } } \ No newline at end of file diff --git a/webprerendersample/src/main/ets/entryability/EntryAbility.ets b/webprerendersample/src/main/ets/entryability/EntryAbility.ets index d80e04a..f39bbcb 100644 --- a/webprerendersample/src/main/ets/entryability/EntryAbility.ets +++ b/webprerendersample/src/main/ets/entryability/EntryAbility.ets @@ -13,10 +13,10 @@ * limitations under the License. */ -import { Configuration, ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; +import { UIAbility } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { WebPrerenderController } from 'webprerenderlibrary'; +import { WebPrerenderController } from '@ohos_samples/webprerenderlibrary'; export default class WebPrerenderSampleAbility extends UIAbility { onCreate(): void { diff --git a/webprerendersample/src/main/ets/pages/Index.ets b/webprerendersample/src/main/ets/pages/Index.ets index 70be494..fb38372 100644 --- a/webprerendersample/src/main/ets/pages/Index.ets +++ b/webprerendersample/src/main/ets/pages/Index.ets @@ -13,84 +13,14 @@ * limitations under the License. */ -import { common } from '@kit.AbilityKit'; -import { ConfigMapKey, ResourceUtil } from 'webprerenderlibrary/src/main/ets/common/ResourceUtil'; -import { Constants } from 'webprerenderlibrary/src/main/ets/common/Constants'; -import { getNWeb } from 'webprerenderlibrary/src/main/ets/component/WebPage'; -import { BreakpointType } from 'webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem'; +import { WebPreRenderPage } from '@ohos_samples/webprerenderlibrary'; @Entry @Component -struct WebPreRender { - @State isShowSheet: boolean = false; - @StorageProp('webPrerenderBreakpoint') curBp: string = Constants.BREAKPOINTS[1]; - @StorageProp('webPrerenderBottomRectHeight') bottomRectHeight: number = 0; - @StorageProp('webPrerenderTopRectHeight') topRectHeight: number = 0; - - @Builder - mySheet() { - Column() { - NodeContainer(getNWeb(ResourceUtil.getRawFileStringByKey(getContext(this) as common.UIAbilityContext, - ConfigMapKey.GALLERY_URL))) - .height($r('app.string.full_height_width')) - .width($r('app.string.full_height_width')) - } - .padding({ - top: $r('app.string.index_tab'), - left: $r('sys.float.padding_level8'), - right: $r('sys.float.padding_level8') - }) - .width($r('app.string.full_height_width')) - .height($r('app.string.full_height_width')) - .backgroundColor($r('sys.color.comp_background_primary')) - } - +struct Index { build() { Column() { - Column() { - Text($r('app.string.title')) - .fontWeight(FontWeight.Bold) - .fontColor($r('sys.color.font_primary')) - .fontSize($r('sys.float.Title_L')) - .alignSelf(ItemAlign.Start) - .margin({ - left: this.curBp === 'sm' ? $r('sys.float.padding_level0') : - this.curBp === 'md' ? $r('sys.float.padding_level4') : $r('sys.float.padding_level8') - }) - Column() { - Button($r('app.string.text_name')) - .fontSize($r('sys.float.Subtitle_M')) - .fontColor($r('sys.color.font_on_primary')) - .width(this.curBp === 'sm' ? '100%' : $r('app.float.index_button_width_lg')) - .height($r('app.float.button_height')) - .margin({ top: $r('sys.float.padding_level6') }) - .backgroundColor($r('sys.color.comp_background_emphasize')) - .bindSheet(this.isShowSheet, this.mySheet(), { - height: new BreakpointType({ sm: 748, md: 560, lg: 560 }).getValue(this.curBp), - width: this.curBp === 'sm' ? '100%' : 480, - preferType: SheetType.CENTER, - backgroundColor: $r('sys.color.comp_background_primary'), - onWillDisappear: () => { - this.isShowSheet = !this.isShowSheet; - } - }) - .onClick(() => { - this.isShowSheet = !this.isShowSheet; - }) - } - .width(Constants.FULL_WIDTH) - } - .backgroundColor($r('sys.color.background_secondary')) - .width(Constants.FULL_WIDTH) - .height(Constants.FULL_HEIGHT) - .alignItems(HorizontalAlign.Center) - .justifyContent(FlexAlign.SpaceBetween) - .padding({ - left: $r('sys.float.padding_level8'), - right: $r('sys.float.padding_level8'), - top: Constants.PADDING_TOP_INDEX + this.topRectHeight, - bottom: Constants.PADDING_BOTTOM_INDEX + this.bottomRectHeight - }) + WebPreRenderPage() } .width($r('app.string.full_height_width')) .height($r('app.string.full_height_width')) -- Gitee From c6ec564ea7aa8f0e200fb374769d7522758346f1 Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Thu, 10 Jul 2025 16:28:40 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E8=A7=84=E8=8C=83=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 2 +- README.md | 2 +- webprerenderlibrary/Index.ets | 2 +- webprerenderlibrary/README.md | 6 +++--- .../{WebPreRenderPage.ets => WebPreRenderComponent.ets} | 2 +- webprerendersample/src/main/ets/pages/Index.ets | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) rename webprerenderlibrary/src/main/ets/component/{WebPreRenderPage.ets => WebPreRenderComponent.ets} (99%) diff --git a/README.en.md b/README.en.md index b5ec7e9..20194e8 100644 --- a/README.en.md +++ b/README.en.md @@ -23,7 +23,7 @@ webprerenderlibrary │ │ └──ResourceUtil.ets │ └──component │ │ └──WebPage.ets // Home page -│ │ └──WebPreRenderPage.ets // Pre-rendering web page +│ │ └──WebPreRenderComponent.ets // Pre-rendering web page │ └──WebPrerenderController.ets └──src/main/resources // Static resources webprerendersample diff --git a/README.md b/README.md index fe8d31a..f6ad083 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ webprerenderlibrary │ │ └──ResourceUtil.ets │ └──component │ │ └──WebPage.ets // 首页 -│ │ └──WebPreRenderPage.ets // Web预渲染页面 +│ │ └──WebPreRenderComponent.ets // Web预渲染页面 │ └──WebPrerenderController.ets └──src/main/resources // 静态资源 webprerendersample diff --git a/webprerenderlibrary/Index.ets b/webprerenderlibrary/Index.ets index 89c0ca1..81d1d42 100644 --- a/webprerenderlibrary/Index.ets +++ b/webprerenderlibrary/Index.ets @@ -1,3 +1,3 @@ -export { WebPreRenderPage } from './src/main/ets/component/WebPreRenderPage'; +export { WebPreRenderComponent } from './src/main/ets/component/WebPreRenderComponent'; export { WebPrerenderController } from './src/main/ets/WebPrerenderController'; \ No newline at end of file diff --git a/webprerenderlibrary/README.md b/webprerenderlibrary/README.md index 1b735f7..18da67b 100644 --- a/webprerenderlibrary/README.md +++ b/webprerenderlibrary/README.md @@ -25,12 +25,12 @@ ohpm install @ohos_samples/webprerenderlibrary ### 使用说明 ``` -import { WebPreRenderPage, WebPrerenderController } from '@ohos_samples/webprerenderlibrary'; +import { WebPreRenderComponent, WebPrerenderController } from '@ohos_samples/webprerenderlibrary'; ``` -按需在文件中使用导出模块即可,其中WebPreRenderPage是整个sample的入口页面。WebPrerenderController初始化沉浸式、设备断点判断、避让区域计算等窗口能力。示例如下: +按需在文件中使用导出模块即可,其中WWebPreRenderComponent是整个sample的入口页面组件。WebPrerenderController初始化沉浸式、设备断点判断、避让区域计算等窗口能力。示例如下: ``` // Page.ets -import { WebPreRenderPage } from '@ohos_samples/webprerenderlibrary'; +import { WebPreRenderComponent } from '@ohos_samples/webprerenderlibrary'; Stack() { WebPreRenderPage() } diff --git a/webprerenderlibrary/src/main/ets/component/WebPreRenderPage.ets b/webprerenderlibrary/src/main/ets/component/WebPreRenderComponent.ets similarity index 99% rename from webprerenderlibrary/src/main/ets/component/WebPreRenderPage.ets rename to webprerenderlibrary/src/main/ets/component/WebPreRenderComponent.ets index a193367..5a15da3 100644 --- a/webprerenderlibrary/src/main/ets/component/WebPreRenderPage.ets +++ b/webprerenderlibrary/src/main/ets/component/WebPreRenderComponent.ets @@ -20,7 +20,7 @@ import { Constants } from '../common/Constants'; import { getNWeb } from './WebPage'; @Component -export struct WebPreRenderPage { +export struct WebPreRenderComponent { @State isShowSheet: boolean = false; @StorageProp('webPrerenderBreakpoint') curBp: string = Constants.BREAKPOINTS[1]; @StorageProp('webPrerenderBottomRectHeight') bottomRectHeight: number = 0; diff --git a/webprerendersample/src/main/ets/pages/Index.ets b/webprerendersample/src/main/ets/pages/Index.ets index fb38372..cec612b 100644 --- a/webprerendersample/src/main/ets/pages/Index.ets +++ b/webprerendersample/src/main/ets/pages/Index.ets @@ -13,14 +13,14 @@ * limitations under the License. */ -import { WebPreRenderPage } from '@ohos_samples/webprerenderlibrary'; +import { WebPreRenderComponent } from '@ohos_samples/webprerenderlibrary'; @Entry @Component struct Index { build() { Column() { - WebPreRenderPage() + WebPreRenderComponent() } .width($r('app.string.full_height_width')) .height($r('app.string.full_height_width')) -- Gitee From b0e2af07e8d70f3966f269d6705b1535d236a5f2 Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Mon, 14 Jul 2025 11:39:48 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=95=B4=E6=94=B9?= =?UTF-8?q?=E5=8F=8A=E8=A7=84=E8=8C=83=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 4 ++-- README.md | 4 ++-- webprerenderlibrary/BuildProfile.ets | 17 ----------------- webprerenderlibrary/Index.ets | 2 +- webprerenderlibrary/build-profile.json5 | 2 +- .../src/main/ets/common/Constants.ets | 4 ++-- .../main/ets/common/utils/BreakpointSystem.ets | 5 +++-- .../src/main/ets/common/utils/WindowUtil.ets | 12 ++++++------ .../main/ets/{component => view}/WebPage.ets | 2 +- .../WebPreRenderView.ets} | 8 ++++---- .../main/resources/base/element/string.json | 16 ++-------------- .../main/resources/en_US/element/string.json | 12 ------------ .../main/resources/zh_CN/element/string.json | 12 ------------ .../src/main/resources/base/element/color.json | 8 ++++++++ .../main/resources/base/element/string.json | 16 ++++++++++++++++ .../main/resources/base/media/background.png | Bin .../main/resources/base/media/foreground.png | Bin .../resources/base/media/layered_image.json | 0 .../main/resources/base/media/startIcon.png | Bin .../main/resources/en_US/element/string.json | 16 ++++++++++++++++ .../main/resources/zh_CN/element/string.json | 16 ++++++++++++++++ 21 files changed, 80 insertions(+), 76 deletions(-) delete mode 100644 webprerenderlibrary/BuildProfile.ets rename webprerenderlibrary/src/main/ets/{component => view}/WebPage.ets (100%) rename webprerenderlibrary/src/main/ets/{component/WebPreRenderComponent.ets => view/WebPreRenderView.ets} (93%) create mode 100644 webprerendersample/src/main/resources/base/element/color.json create mode 100644 webprerendersample/src/main/resources/base/element/string.json rename {webprerenderlibrary => webprerendersample}/src/main/resources/base/media/background.png (100%) rename {webprerenderlibrary => webprerendersample}/src/main/resources/base/media/foreground.png (100%) rename {webprerenderlibrary => webprerendersample}/src/main/resources/base/media/layered_image.json (100%) rename {webprerenderlibrary => webprerendersample}/src/main/resources/base/media/startIcon.png (100%) create mode 100644 webprerendersample/src/main/resources/en_US/element/string.json create mode 100644 webprerendersample/src/main/resources/zh_CN/element/string.json diff --git a/README.en.md b/README.en.md index 20194e8..f15ef8a 100644 --- a/README.en.md +++ b/README.en.md @@ -21,9 +21,9 @@ webprerenderlibrary │ │ │ └──WindowUtil.ets │ │ ├──Constants.ets // Common constant class │ │ └──ResourceUtil.ets -│ └──component +│ └──view │ │ └──WebPage.ets // Home page -│ │ └──WebPreRenderComponent.ets // Pre-rendering web page +│ │ └──WebPreRenderView.ets // Pre-rendering web page │ └──WebPrerenderController.ets └──src/main/resources // Static resources webprerendersample diff --git a/README.md b/README.md index f6ad083..4d2825b 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ webprerenderlibrary │ │ │ └──WindowUtil.ets // 窗口工具 │ │ ├──Constants.ets // 公共常量类 │ │ └──ResourceUtil.ets -│ └──component +│ └──view │ │ └──WebPage.ets // 首页 -│ │ └──WebPreRenderComponent.ets // Web预渲染页面 +│ │ └──WebPreRenderView.ets // Web预渲染页面 │ └──WebPrerenderController.ets └──src/main/resources // 静态资源 webprerendersample diff --git a/webprerenderlibrary/BuildProfile.ets b/webprerenderlibrary/BuildProfile.ets deleted file mode 100644 index 3a501e5..0000000 --- a/webprerenderlibrary/BuildProfile.ets +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Use these variables when you tailor your ArkTS code. They must be of the const type. - */ -export const HAR_VERSION = '1.0.0'; -export const BUILD_MODE_NAME = 'debug'; -export const DEBUG = true; -export const TARGET_NAME = 'default'; - -/** - * BuildProfile Class is used only for compatibility purposes. - */ -export default class BuildProfile { - static readonly HAR_VERSION = HAR_VERSION; - static readonly BUILD_MODE_NAME = BUILD_MODE_NAME; - static readonly DEBUG = DEBUG; - static readonly TARGET_NAME = TARGET_NAME; -} \ No newline at end of file diff --git a/webprerenderlibrary/Index.ets b/webprerenderlibrary/Index.ets index 81d1d42..9998f10 100644 --- a/webprerenderlibrary/Index.ets +++ b/webprerenderlibrary/Index.ets @@ -1,3 +1,3 @@ -export { WebPreRenderComponent } from './src/main/ets/component/WebPreRenderComponent'; +export { WebPreRenderView as WebPreRenderComponent } from './src/main/ets/view/WebPreRenderView'; export { WebPrerenderController } from './src/main/ets/WebPrerenderController'; \ No newline at end of file diff --git a/webprerenderlibrary/build-profile.json5 b/webprerenderlibrary/build-profile.json5 index 312d38e..cda3307 100644 --- a/webprerenderlibrary/build-profile.json5 +++ b/webprerenderlibrary/build-profile.json5 @@ -8,7 +8,7 @@ "arkOptions": { "obfuscation": { "ruleOptions": { - "enable": true, + "enable": false, "files": [ "./obfuscation-rules.txt" ] diff --git a/webprerenderlibrary/src/main/ets/common/Constants.ets b/webprerenderlibrary/src/main/ets/common/Constants.ets index cf29954..90e4296 100644 --- a/webprerenderlibrary/src/main/ets/common/Constants.ets +++ b/webprerenderlibrary/src/main/ets/common/Constants.ets @@ -44,7 +44,7 @@ export class Constants { */ public static readonly KEY_PREFIX: string = 'webPrerender'; public static readonly KEY_BREAKPOINT: string = Constants.KEY_PREFIX + 'BreakPoint'; - public static readonly KEY_TOP_RECT_HEIGHT: string = Constants.KEY_PREFIX + 'TopRectHeight'; - public static readonly KEY_BOTTOM_RECT_HEIGHT: string = Constants.KEY_PREFIX + 'BottomRectHeight'; + public static readonly KEY_STATUS_BAR_HEIGHT: string = Constants.KEY_PREFIX + 'StatusBarHeight'; + public static readonly KEY_NAV_INDICATOR_HEIGHT: string = Constants.KEY_PREFIX + 'NavIndicatorHeight'; public static readonly KEY_UI_CONTEXT: string = Constants.KEY_PREFIX + 'UIContext'; } \ No newline at end of file diff --git a/webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem.ets b/webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem.ets index 0957664..26914c1 100644 --- a/webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem.ets +++ b/webprerenderlibrary/src/main/ets/common/utils/BreakpointSystem.ets @@ -16,6 +16,7 @@ import { window } from '@kit.ArkUI'; import type { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; +import { Constants } from '../Constants'; const TAG: string = '[BreakpointSystem]'; @@ -77,7 +78,7 @@ export class BreakpointSystem { public static getInstance(): BreakpointSystem { if (!BreakpointSystem.instance) { BreakpointSystem.instance = new BreakpointSystem(); - AppStorage.setOrCreate('webPrerenderBreakpoint', BreakpointTypeEnum.MD); + AppStorage.setOrCreate(Constants.KEY_BREAKPOINT, BreakpointTypeEnum.MD); } return BreakpointSystem.instance; } @@ -85,7 +86,7 @@ export class BreakpointSystem { public updateCurrentBreakpoint(breakpoint: BreakpointTypeEnum): void { if (this.currentBreakpoint !== breakpoint) { this.currentBreakpoint = breakpoint; - AppStorage.setOrCreate('webPrerenderBreakpoint', this.currentBreakpoint); + AppStorage.setOrCreate(Constants.KEY_BREAKPOINT, this.currentBreakpoint); } } diff --git a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets index 47e279d..a286587 100644 --- a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets +++ b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets @@ -14,12 +14,12 @@ */ import { window } from '@kit.ArkUI'; +import { common, UIAbility } from '@kit.AbilityKit'; import type { BusinessError } from '@kit.BasicServicesKit'; -import { BreakpointSystem } from './BreakpointSystem'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { createNWeb } from '../../component/WebPage'; +import { BreakpointSystem } from './BreakpointSystem'; +import { createNWeb } from '../../view/WebPage'; import { ConfigMapKey, ResourceUtil } from '../ResourceUtil'; -import { common, UIAbility } from '@kit.AbilityKit'; import { Constants } from '../Constants'; const TAG: string = '[WindowUtil]'; @@ -89,12 +89,12 @@ export class WindowUtil { } // Get status bar height and indicator height. - public static setAvoidArea(data: window.Window, type: window.AvoidAreaType, area: window.AvoidArea) { + private static setAvoidArea(data: window.Window, type: window.AvoidAreaType, area: window.AvoidArea) { const context: UIContext = data.getUIContext(); if (type === window.AvoidAreaType.TYPE_SYSTEM) { - AppStorage.setOrCreate('webPrerenderTopRectHeight', context.px2vp(area.topRect.height)); + AppStorage.setOrCreate(Constants.KEY_STATUS_BAR_HEIGHT, context.px2vp(area.topRect.height)); } else { - AppStorage.setOrCreate('webPrerenderBottomRectHeight', context.px2vp(area.bottomRect.height)); + AppStorage.setOrCreate(Constants.KEY_NAV_INDICATOR_HEIGHT, context.px2vp(area.bottomRect.height)); } } } \ No newline at end of file diff --git a/webprerenderlibrary/src/main/ets/component/WebPage.ets b/webprerenderlibrary/src/main/ets/view/WebPage.ets similarity index 100% rename from webprerenderlibrary/src/main/ets/component/WebPage.ets rename to webprerenderlibrary/src/main/ets/view/WebPage.ets index 4a4cb80..b0c4c52 100644 --- a/webprerenderlibrary/src/main/ets/component/WebPage.ets +++ b/webprerenderlibrary/src/main/ets/view/WebPage.ets @@ -17,9 +17,9 @@ import { BuilderNode, FrameNode, NodeController, UIContext } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { common } from '@kit.AbilityKit'; import { webview } from '@kit.ArkWeb'; +import { BusinessError } from '@kit.BasicServicesKit'; import { ConfigMapKey, ResourceUtil } from '../common/ResourceUtil'; import { Constants } from '../common/Constants'; -import { BusinessError } from '@kit.BasicServicesKit'; class Data { public url: string = diff --git a/webprerenderlibrary/src/main/ets/component/WebPreRenderComponent.ets b/webprerenderlibrary/src/main/ets/view/WebPreRenderView.ets similarity index 93% rename from webprerenderlibrary/src/main/ets/component/WebPreRenderComponent.ets rename to webprerenderlibrary/src/main/ets/view/WebPreRenderView.ets index 5a15da3..267d47f 100644 --- a/webprerenderlibrary/src/main/ets/component/WebPreRenderComponent.ets +++ b/webprerenderlibrary/src/main/ets/view/WebPreRenderView.ets @@ -20,11 +20,11 @@ import { Constants } from '../common/Constants'; import { getNWeb } from './WebPage'; @Component -export struct WebPreRenderComponent { +export struct WebPreRenderView { @State isShowSheet: boolean = false; - @StorageProp('webPrerenderBreakpoint') curBp: string = Constants.BREAKPOINTS[1]; - @StorageProp('webPrerenderBottomRectHeight') bottomRectHeight: number = 0; - @StorageProp('webPrerenderTopRectHeight') topRectHeight: number = 0; + @StorageProp(Constants.KEY_BREAKPOINT) curBp: string = Constants.BREAKPOINTS[1]; + @StorageProp(Constants.KEY_NAV_INDICATOR_HEIGHT) bottomRectHeight: number = 0; + @StorageProp(Constants.KEY_STATUS_BAR_HEIGHT) topRectHeight: number = 0; @Builder mySheet() { diff --git a/webprerenderlibrary/src/main/resources/base/element/string.json b/webprerenderlibrary/src/main/resources/base/element/string.json index af7e1aa..ed9c770 100644 --- a/webprerenderlibrary/src/main/resources/base/element/string.json +++ b/webprerenderlibrary/src/main/resources/base/element/string.json @@ -1,24 +1,12 @@ { "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "Web页面瞬开效果实践" - }, { "name": "title", - "value": "Web页面瞬开效果实践" + "value": "Practice of Web Page Instant Open Effect" }, { "name": "text_name", - "value": "点击打开Web页面" + "value": "Click to open the web page." }, { "name": "full_height_width", diff --git a/webprerenderlibrary/src/main/resources/en_US/element/string.json b/webprerenderlibrary/src/main/resources/en_US/element/string.json index 37f8903..ed9c770 100644 --- a/webprerenderlibrary/src/main/resources/en_US/element/string.json +++ b/webprerenderlibrary/src/main/resources/en_US/element/string.json @@ -1,17 +1,5 @@ { "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "Practice of Web Page Instant Open Effect" - }, { "name": "title", "value": "Practice of Web Page Instant Open Effect" diff --git a/webprerenderlibrary/src/main/resources/zh_CN/element/string.json b/webprerenderlibrary/src/main/resources/zh_CN/element/string.json index 4fa1acd..fca880f 100644 --- a/webprerenderlibrary/src/main/resources/zh_CN/element/string.json +++ b/webprerenderlibrary/src/main/resources/zh_CN/element/string.json @@ -1,17 +1,5 @@ { "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "Web页面瞬开效果实践" - }, { "name": "title", "value": "Web页面瞬开效果实践" diff --git a/webprerendersample/src/main/resources/base/element/color.json b/webprerendersample/src/main/resources/base/element/color.json new file mode 100644 index 0000000..3c71296 --- /dev/null +++ b/webprerendersample/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/webprerendersample/src/main/resources/base/element/string.json b/webprerendersample/src/main/resources/base/element/string.json new file mode 100644 index 0000000..0f9af8b --- /dev/null +++ b/webprerendersample/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "Practice of Web Page Instant Open Effect" + } + ] +} \ No newline at end of file diff --git a/webprerenderlibrary/src/main/resources/base/media/background.png b/webprerendersample/src/main/resources/base/media/background.png similarity index 100% rename from webprerenderlibrary/src/main/resources/base/media/background.png rename to webprerendersample/src/main/resources/base/media/background.png diff --git a/webprerenderlibrary/src/main/resources/base/media/foreground.png b/webprerendersample/src/main/resources/base/media/foreground.png similarity index 100% rename from webprerenderlibrary/src/main/resources/base/media/foreground.png rename to webprerendersample/src/main/resources/base/media/foreground.png diff --git a/webprerenderlibrary/src/main/resources/base/media/layered_image.json b/webprerendersample/src/main/resources/base/media/layered_image.json similarity index 100% rename from webprerenderlibrary/src/main/resources/base/media/layered_image.json rename to webprerendersample/src/main/resources/base/media/layered_image.json diff --git a/webprerenderlibrary/src/main/resources/base/media/startIcon.png b/webprerendersample/src/main/resources/base/media/startIcon.png similarity index 100% rename from webprerenderlibrary/src/main/resources/base/media/startIcon.png rename to webprerendersample/src/main/resources/base/media/startIcon.png diff --git a/webprerendersample/src/main/resources/en_US/element/string.json b/webprerendersample/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000..0f9af8b --- /dev/null +++ b/webprerendersample/src/main/resources/en_US/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "Practice of Web Page Instant Open Effect" + } + ] +} \ No newline at end of file diff --git a/webprerendersample/src/main/resources/zh_CN/element/string.json b/webprerendersample/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000..07d905d --- /dev/null +++ b/webprerendersample/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "描述" + }, + { + "name": "EntryAbility_label", + "value": "Web页面瞬开效果实践" + } + ] +} \ No newline at end of file -- Gitee From 148f8259068f4a0adf5fb7ccd36e63df44e9f69c Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Mon, 14 Jul 2025 11:44:55 +0800 Subject: [PATCH 09/12] =?UTF-8?q?readme=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webprerenderlibrary/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webprerenderlibrary/README.md b/webprerenderlibrary/README.md index 18da67b..3417951 100644 --- a/webprerenderlibrary/README.md +++ b/webprerenderlibrary/README.md @@ -32,7 +32,7 @@ import { WebPreRenderComponent, WebPrerenderController } from '@ohos_samples/web // Page.ets import { WebPreRenderComponent } from '@ohos_samples/webprerenderlibrary'; Stack() { - WebPreRenderPage() + WebPreRenderComponent() } // EntryAbility.ets -- Gitee From 73424cfa68c62a5e13bc610336d8578e449ac22b Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Mon, 14 Jul 2025 16:11:51 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webprerenderlibrary/README.md | 2 +- .../src/main/ets/WebPrerenderController.ets | 2 +- .../src/main/ets/common/utils/WindowUtil.ets | 2 +- .../src/main/ets/view/WebPreRenderView.ets | 10 +++++----- .../src/main/resources/base/element/color.json | 8 -------- .../src/main/resources/base/element/float.json | 4 ++++ .../src/main/resources/base/element/string.json | 4 ---- .../src/main/resources/en_US/element/float.json | 8 ++++++++ .../src/main/resources/en_US/element/string.json | 4 ---- .../src/main/resources/zh_CN/element/float.json | 8 ++++++++ .../src/main/resources/zh_CN/element/string.json | 4 ---- 11 files changed, 28 insertions(+), 28 deletions(-) delete mode 100644 webprerenderlibrary/src/main/resources/base/element/color.json create mode 100644 webprerenderlibrary/src/main/resources/en_US/element/float.json create mode 100644 webprerenderlibrary/src/main/resources/zh_CN/element/float.json diff --git a/webprerenderlibrary/README.md b/webprerenderlibrary/README.md index 3417951..bb88b6a 100644 --- a/webprerenderlibrary/README.md +++ b/webprerenderlibrary/README.md @@ -29,7 +29,7 @@ import { WebPreRenderComponent, WebPrerenderController } from '@ohos_samples/web ``` 按需在文件中使用导出模块即可,其中WWebPreRenderComponent是整个sample的入口页面组件。WebPrerenderController初始化沉浸式、设备断点判断、避让区域计算等窗口能力。示例如下: ``` -// Page.ets +// Index.ets import { WebPreRenderComponent } from '@ohos_samples/webprerenderlibrary'; Stack() { WebPreRenderComponent() diff --git a/webprerenderlibrary/src/main/ets/WebPrerenderController.ets b/webprerenderlibrary/src/main/ets/WebPrerenderController.ets index 3fa54c6..720d91e 100644 --- a/webprerenderlibrary/src/main/ets/WebPrerenderController.ets +++ b/webprerenderlibrary/src/main/ets/WebPrerenderController.ets @@ -13,8 +13,8 @@ * limitations under the License. */ import { window } from '@kit.ArkUI'; -import { WindowUtil } from './common/utils/WindowUtil'; import { UIAbility } from '@kit.AbilityKit'; +import { WindowUtil } from './common/utils/WindowUtil'; export class WebPrerenderController { public static initWindowConfig(windowStage: window.WindowStage, ability: UIAbility): void { diff --git a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets index a286587..f2614eb 100644 --- a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets +++ b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets @@ -49,7 +49,7 @@ export class WindowUtil { promise.then(() => { hilog.info(0x0000, TAG, 'Succeeded in setting the window layout to full-screen mode.'); }).catch((err: BusinessError) => { - hilog.info(0x0000, TAG, + hilog.error(0x0000, TAG, `Failed to set the window layout to full-screen mode. Cause: ${err.code}, ${err.message}`); }); } catch { diff --git a/webprerenderlibrary/src/main/ets/view/WebPreRenderView.ets b/webprerenderlibrary/src/main/ets/view/WebPreRenderView.ets index 267d47f..860db27 100644 --- a/webprerenderlibrary/src/main/ets/view/WebPreRenderView.ets +++ b/webprerenderlibrary/src/main/ets/view/WebPreRenderView.ets @@ -23,8 +23,8 @@ import { getNWeb } from './WebPage'; export struct WebPreRenderView { @State isShowSheet: boolean = false; @StorageProp(Constants.KEY_BREAKPOINT) curBp: string = Constants.BREAKPOINTS[1]; - @StorageProp(Constants.KEY_NAV_INDICATOR_HEIGHT) bottomRectHeight: number = 0; - @StorageProp(Constants.KEY_STATUS_BAR_HEIGHT) topRectHeight: number = 0; + @StorageProp(Constants.KEY_NAV_INDICATOR_HEIGHT) navIndicatorHeight: number = 0; + @StorageProp(Constants.KEY_STATUS_BAR_HEIGHT) statusBarHeight: number = 0; @Builder mySheet() { @@ -35,7 +35,7 @@ export struct WebPreRenderView { .width($r('app.string.full_height_width')) } .padding({ - top: $r('app.string.index_tab'), + top: $r('app.float.index_tab'), left: $r('sys.float.padding_level8'), right: $r('sys.float.padding_level8') }) @@ -87,8 +87,8 @@ export struct WebPreRenderView { .padding({ left: $r('sys.float.padding_level8'), right: $r('sys.float.padding_level8'), - top: Constants.PADDING_TOP_INDEX + this.topRectHeight, - bottom: Constants.PADDING_BOTTOM_INDEX + this.bottomRectHeight + top: Constants.PADDING_TOP_INDEX + this.statusBarHeight, + bottom: Constants.PADDING_BOTTOM_INDEX + this.navIndicatorHeight }) } .width($r('app.string.full_height_width')) diff --git a/webprerenderlibrary/src/main/resources/base/element/color.json b/webprerenderlibrary/src/main/resources/base/element/color.json deleted file mode 100644 index 3c71296..0000000 --- a/webprerenderlibrary/src/main/resources/base/element/color.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "color": [ - { - "name": "start_window_background", - "value": "#FFFFFF" - } - ] -} \ No newline at end of file diff --git a/webprerenderlibrary/src/main/resources/base/element/float.json b/webprerenderlibrary/src/main/resources/base/element/float.json index 6d2c7b4..6d2544e 100644 --- a/webprerenderlibrary/src/main/resources/base/element/float.json +++ b/webprerenderlibrary/src/main/resources/base/element/float.json @@ -7,6 +7,10 @@ { "name": "button_height", "value": "40vp" + }, + { + "name": "index_tab", + "value": "56vp" } ] } \ No newline at end of file diff --git a/webprerenderlibrary/src/main/resources/base/element/string.json b/webprerenderlibrary/src/main/resources/base/element/string.json index ed9c770..76fb5b2 100644 --- a/webprerenderlibrary/src/main/resources/base/element/string.json +++ b/webprerenderlibrary/src/main/resources/base/element/string.json @@ -12,10 +12,6 @@ "name": "full_height_width", "value": "100%" }, - { - "name": "index_tab", - "value": "56vp" - }, { "name": "reason_internet", "value": "Used for instant page loading effects in web scenarios" diff --git a/webprerenderlibrary/src/main/resources/en_US/element/float.json b/webprerenderlibrary/src/main/resources/en_US/element/float.json new file mode 100644 index 0000000..4d5aa4a --- /dev/null +++ b/webprerenderlibrary/src/main/resources/en_US/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "index_tab", + "value": "56vp" + } + ] +} \ No newline at end of file diff --git a/webprerenderlibrary/src/main/resources/en_US/element/string.json b/webprerenderlibrary/src/main/resources/en_US/element/string.json index ed9c770..76fb5b2 100644 --- a/webprerenderlibrary/src/main/resources/en_US/element/string.json +++ b/webprerenderlibrary/src/main/resources/en_US/element/string.json @@ -12,10 +12,6 @@ "name": "full_height_width", "value": "100%" }, - { - "name": "index_tab", - "value": "56vp" - }, { "name": "reason_internet", "value": "Used for instant page loading effects in web scenarios" diff --git a/webprerenderlibrary/src/main/resources/zh_CN/element/float.json b/webprerenderlibrary/src/main/resources/zh_CN/element/float.json new file mode 100644 index 0000000..c36779f --- /dev/null +++ b/webprerenderlibrary/src/main/resources/zh_CN/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "index_tab", + "value": "72vp" + } + ] +} \ No newline at end of file diff --git a/webprerenderlibrary/src/main/resources/zh_CN/element/string.json b/webprerenderlibrary/src/main/resources/zh_CN/element/string.json index fca880f..0f76872 100644 --- a/webprerenderlibrary/src/main/resources/zh_CN/element/string.json +++ b/webprerenderlibrary/src/main/resources/zh_CN/element/string.json @@ -12,10 +12,6 @@ "name": "full_height_width", "value": "100%" }, - { - "name": "index_tab", - "value": "72vp" - }, { "name": "reason_internet", "value": "用于Web页面的瞬开效果场景" -- Gitee From 402e0c396381e20f0c0b7e5ca4936d19464ae181 Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Tue, 15 Jul 2025 14:09:34 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=EF=BC=9Aimport=E9=A1=BA=E5=BA=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webprerenderlibrary/src/main/ets/WebPrerenderController.ets | 2 +- webprerenderlibrary/src/main/ets/common/ResourceUtil.ets | 2 +- .../src/main/ets/common/utils/WindowUtil.ets | 6 +++--- webprerenderlibrary/src/main/ets/view/WebPage.ets | 6 +++--- webprerenderlibrary/src/main/ets/view/WebPreRenderView.ets | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/webprerenderlibrary/src/main/ets/WebPrerenderController.ets b/webprerenderlibrary/src/main/ets/WebPrerenderController.ets index 720d91e..2ef7bac 100644 --- a/webprerenderlibrary/src/main/ets/WebPrerenderController.ets +++ b/webprerenderlibrary/src/main/ets/WebPrerenderController.ets @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { window } from '@kit.ArkUI'; import { UIAbility } from '@kit.AbilityKit'; +import { window } from '@kit.ArkUI'; import { WindowUtil } from './common/utils/WindowUtil'; export class WebPrerenderController { diff --git a/webprerenderlibrary/src/main/ets/common/ResourceUtil.ets b/webprerenderlibrary/src/main/ets/common/ResourceUtil.ets index f26f38e..99a7edf 100644 --- a/webprerenderlibrary/src/main/ets/common/ResourceUtil.ets +++ b/webprerenderlibrary/src/main/ets/common/ResourceUtil.ets @@ -13,9 +13,9 @@ * limitations under the License. */ -import { hilog } from '@kit.PerformanceAnalysisKit'; import { JSON, util } from '@kit.ArkTS'; import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; export class ResourceUtil { /** diff --git a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets index f2614eb..8f7f858 100644 --- a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets +++ b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets @@ -13,14 +13,14 @@ * limitations under the License. */ -import { window } from '@kit.ArkUI'; import { common, UIAbility } from '@kit.AbilityKit'; +import { window } from '@kit.ArkUI'; import type { BusinessError } from '@kit.BasicServicesKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { BreakpointSystem } from './BreakpointSystem'; import { createNWeb } from '../../view/WebPage'; -import { ConfigMapKey, ResourceUtil } from '../ResourceUtil'; import { Constants } from '../Constants'; +import { ConfigMapKey, ResourceUtil } from '../ResourceUtil'; +import { BreakpointSystem } from './BreakpointSystem'; const TAG: string = '[WindowUtil]'; diff --git a/webprerenderlibrary/src/main/ets/view/WebPage.ets b/webprerenderlibrary/src/main/ets/view/WebPage.ets index b0c4c52..b4df6c2 100644 --- a/webprerenderlibrary/src/main/ets/view/WebPage.ets +++ b/webprerenderlibrary/src/main/ets/view/WebPage.ets @@ -13,13 +13,13 @@ * limitations under the License. */ -import { BuilderNode, FrameNode, NodeController, UIContext } from '@kit.ArkUI'; -import { hilog } from '@kit.PerformanceAnalysisKit'; import { common } from '@kit.AbilityKit'; +import { BuilderNode, FrameNode, NodeController, UIContext } from '@kit.ArkUI'; import { webview } from '@kit.ArkWeb'; import { BusinessError } from '@kit.BasicServicesKit'; -import { ConfigMapKey, ResourceUtil } from '../common/ResourceUtil'; +import { hilog } from '@kit.PerformanceAnalysisKit'; import { Constants } from '../common/Constants'; +import { ConfigMapKey, ResourceUtil } from '../common/ResourceUtil'; class Data { public url: string = diff --git a/webprerenderlibrary/src/main/ets/view/WebPreRenderView.ets b/webprerenderlibrary/src/main/ets/view/WebPreRenderView.ets index 860db27..c20c653 100644 --- a/webprerenderlibrary/src/main/ets/view/WebPreRenderView.ets +++ b/webprerenderlibrary/src/main/ets/view/WebPreRenderView.ets @@ -14,9 +14,9 @@ */ import { common } from '@kit.AbilityKit'; +import { Constants } from '../common/Constants'; import { ConfigMapKey, ResourceUtil } from '../common/ResourceUtil'; import { BreakpointType } from '../common/utils/BreakpointSystem'; -import { Constants } from '../common/Constants'; import { getNWeb } from './WebPage'; @Component -- Gitee From 41d42b24a05236cab6b0f1c5cc29b0b2f59eb30f Mon Sep 17 00:00:00 2001 From: EasyGuohf <163991322+EasyGuohf@users.noreply.github.com> Date: Tue, 15 Jul 2025 21:47:45 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/common/utils/WindowUtil.ets | 92 +++++++++---------- .../src/main/ets/view/WebPreRenderView.ets | 20 ++-- .../main/resources/base/element/float.json | 12 +++ .../main/ets/entryability/EntryAbility.ets | 3 +- 4 files changed, 69 insertions(+), 58 deletions(-) diff --git a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets index 8f7f858..e9f3267 100644 --- a/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets +++ b/webprerenderlibrary/src/main/ets/common/utils/WindowUtil.ets @@ -25,67 +25,57 @@ import { BreakpointSystem } from './BreakpointSystem'; const TAG: string = '[WindowUtil]'; export class WindowUtil { + private static windowClass: window.Window; + public static initialize(windowStage: window.WindowStage, ability: UIAbility) { try { - const uiContext: UIContext = windowStage.getMainWindowSync()?.getUIContext(); + WindowUtil.windowClass = windowStage.getMainWindowSync(); + const uiContext: UIContext = WindowUtil.windowClass.getUIContext(); AppStorage.setOrCreate(Constants.KEY_UI_CONTEXT, uiContext); - WindowUtil.requestFullScreen(windowStage); - WindowUtil.registerBreakPoint(windowStage, ability); + WindowUtil.requestFullScreen(WindowUtil.windowClass); + WindowUtil.registerBreakPoint(WindowUtil.windowClass, ability); } catch (err) { const error = err as BusinessError; hilog.error(0x0000, TAG, `Initialize failed. Cause code: ${error.code}, message: ${error.message}`); } } - public static requestFullScreen(windowStage: window.WindowStage): void { - windowStage.getMainWindow((err: BusinessError, data: window.Window) => { - if (err.code) { - return; - } - const windowClass: window.Window = data; - // Realize the immersive effect. - try { - const promise: Promise = windowClass.setWindowLayoutFullScreen(true); - promise.then(() => { - hilog.info(0x0000, TAG, 'Succeeded in setting the window layout to full-screen mode.'); - }).catch((err: BusinessError) => { - hilog.error(0x0000, TAG, - `Failed to set the window layout to full-screen mode. Cause: ${err.code}, ${err.message}`); - }); - } catch { - hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. '); - } - }); + public static requestFullScreen(windowClass: window.Window): void { + // Realize the immersive effect. + try { + const promise: Promise = windowClass.setWindowLayoutFullScreen(true); + promise.then(() => { + hilog.info(0x0000, TAG, 'Succeeded in setting the window layout to full-screen mode.'); + }).catch((err: BusinessError) => { + hilog.error(0x0000, TAG, + `Failed to set the window layout to full-screen mode. Cause: ${err.code}, ${err.message}`); + }); + } catch { + hilog.error(0x0000, TAG, 'Failed to set the window layout to full-screen mode. '); + } + } - public static registerBreakPoint(windowStage: window.WindowStage, ability: UIAbility) { - windowStage.getMainWindow((err: BusinessError, data: window.Window) => { - if (err.code) { - hilog.error(0x0000, TAG, `Failed to get main window: ${err.message}`); - return; - } - try { - BreakpointSystem.getInstance().updateWidthBp(data); - const systemAvoidArea: window.AvoidArea = data.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); - const navIndicatorAvoidArea: window.AvoidArea = - data.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); - WindowUtil.setAvoidArea(data, window.AvoidAreaType.TYPE_SYSTEM, systemAvoidArea); - WindowUtil.setAvoidArea(data, window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR, navIndicatorAvoidArea); - data.on('windowSizeChange', () => BreakpointSystem.getInstance().onWindowSizeChange(data)); - data.on('avoidAreaChange', (avoidAreaOption) => { - if (avoidAreaOption.type === window.AvoidAreaType.TYPE_SYSTEM || - avoidAreaOption.type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { - WindowUtil.setAvoidArea(data, avoidAreaOption.type, avoidAreaOption.area); - } - }); - } catch (err) { - const error = err as BusinessError; - hilog.error(0x0000, TAG, - `Register avoidAreaChange or windowSizeChange failed. code: ${error.code}, message: ${error.message}`); - } - createNWeb(ResourceUtil.getRawFileStringByKey(getContext(ability) as common.UIAbilityContext, - ConfigMapKey.GALLERY_URL), data.getUIContext()); - }) + public static registerBreakPoint(data: window.Window, ability: UIAbility) { + + try { + BreakpointSystem.getInstance().updateWidthBp(data); + const systemAvoidArea: window.AvoidArea = data.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); + const navIndicatorAvoidArea: window.AvoidArea = + data.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR); + WindowUtil.setAvoidArea(data, window.AvoidAreaType.TYPE_SYSTEM, systemAvoidArea); + WindowUtil.setAvoidArea(data, window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR, navIndicatorAvoidArea); + data.on('windowSizeChange', () => BreakpointSystem.getInstance().onWindowSizeChange(data)); + data.on('avoidAreaChange', (avoidAreaOption) => { + WindowUtil.setAvoidArea(data, avoidAreaOption.type, avoidAreaOption.area); + }); + } catch (err) { + const error = err as BusinessError; + hilog.error(0x0000, TAG, + `Register avoidAreaChange or windowSizeChange failed. code: ${error.code}, message: ${error.message}`); + } + createNWeb(ResourceUtil.getRawFileStringByKey(getContext(ability) as common.UIAbilityContext, + ConfigMapKey.GALLERY_URL), data.getUIContext()); } // Get status bar height and indicator height. @@ -93,7 +83,7 @@ export class WindowUtil { const context: UIContext = data.getUIContext(); if (type === window.AvoidAreaType.TYPE_SYSTEM) { AppStorage.setOrCreate(Constants.KEY_STATUS_BAR_HEIGHT, context.px2vp(area.topRect.height)); - } else { + } else if (type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { AppStorage.setOrCreate(Constants.KEY_NAV_INDICATOR_HEIGHT, context.px2vp(area.bottomRect.height)); } } diff --git a/webprerenderlibrary/src/main/ets/view/WebPreRenderView.ets b/webprerenderlibrary/src/main/ets/view/WebPreRenderView.ets index c20c653..7ff8413 100644 --- a/webprerenderlibrary/src/main/ets/view/WebPreRenderView.ets +++ b/webprerenderlibrary/src/main/ets/view/WebPreRenderView.ets @@ -16,7 +16,7 @@ import { common } from '@kit.AbilityKit'; import { Constants } from '../common/Constants'; import { ConfigMapKey, ResourceUtil } from '../common/ResourceUtil'; -import { BreakpointType } from '../common/utils/BreakpointSystem'; +import { BreakpointType, BreakpointTypeEnum } from '../common/utils/BreakpointSystem'; import { getNWeb } from './WebPage'; @Component @@ -53,20 +53,28 @@ export struct WebPreRenderView { .fontSize($r('sys.float.Title_L')) .alignSelf(ItemAlign.Start) .margin({ - left: this.curBp === 'sm' ? $r('sys.float.padding_level0') : - this.curBp === 'md' ? $r('sys.float.padding_level4') : $r('sys.float.padding_level8') + left: new BreakpointType({ + sm: $r('sys.float.padding_level0'), + md: $r('sys.float.padding_level4'), + lg: $r('sys.float.padding_level8'), + xl: $r('sys.float.padding_level8') + }).getValue(this.curBp) }) Column() { Button($r('app.string.text_name')) .fontSize($r('sys.float.Subtitle_M')) .fontColor($r('sys.color.font_on_primary')) - .width(this.curBp === 'sm' ? '100%' : $r('app.float.index_button_width_lg')) + .width(this.curBp === BreakpointTypeEnum.SM ? '100%' : $r('app.float.index_button_width_lg')) .height($r('app.float.button_height')) .margin({ top: $r('sys.float.padding_level6') }) .backgroundColor($r('sys.color.comp_background_emphasize')) .bindSheet(this.isShowSheet, this.mySheet(), { - height: new BreakpointType({ sm: 748, md: 560, lg: 560 }).getValue(this.curBp), - width: this.curBp === 'sm' ? '100%' : 480, + height: new BreakpointType({ + sm: $r('app.float.bind_sheet_height_sm'), + md: $r('app.float.bind_sheet_height_non_sm'), + lg: $r('app.float.bind_sheet_height_non_sm') + }).getValue(this.curBp), + width: this.curBp === BreakpointTypeEnum.SM ? '100%' : $r('app.float.bind_sheet_width'), preferType: SheetType.CENTER, backgroundColor: $r('sys.color.comp_background_primary'), onWillDisappear: () => { diff --git a/webprerenderlibrary/src/main/resources/base/element/float.json b/webprerenderlibrary/src/main/resources/base/element/float.json index 6d2544e..b3bd07e 100644 --- a/webprerenderlibrary/src/main/resources/base/element/float.json +++ b/webprerenderlibrary/src/main/resources/base/element/float.json @@ -11,6 +11,18 @@ { "name": "index_tab", "value": "56vp" + }, + { + "name": "bind_sheet_height_sm", + "value": "748vp" + }, + { + "name": "bind_sheet_height_non_sm", + "value": "560vp" + }, + { + "name": "bind_sheet_width", + "value": "480vp" } ] } \ No newline at end of file diff --git a/webprerendersample/src/main/ets/entryability/EntryAbility.ets b/webprerendersample/src/main/ets/entryability/EntryAbility.ets index f39bbcb..d3b08d2 100644 --- a/webprerendersample/src/main/ets/entryability/EntryAbility.ets +++ b/webprerendersample/src/main/ets/entryability/EntryAbility.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { UIAbility } from '@kit.AbilityKit'; +import { ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { WebPrerenderController } from '@ohos_samples/webprerenderlibrary'; @@ -21,6 +21,7 @@ import { WebPrerenderController } from '@ohos_samples/webprerenderlibrary'; export default class WebPrerenderSampleAbility extends UIAbility { onCreate(): void { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); } onDestroy(): void { -- Gitee