From ab1576dd6b9a806128adb8f740f96701c40e574d Mon Sep 17 00:00:00 2001 From: WX1377357 Date: Thu, 29 May 2025 10:16:30 +0800 Subject: [PATCH] =?UTF-8?q?=E9=B8=BF=E8=92=99=E4=B8=96=E7=95=8C=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build-profile.json5 | 8 +- componentstacklibrary/.gitignore | 6 + componentstacklibrary/Index.ets | 2 + componentstacklibrary/build-profile.json5 | 31 +++++ componentstacklibrary/consumer-rules.txt | 0 componentstacklibrary/hvigorfile.ts | 6 + componentstacklibrary/obfuscation-rules.txt | 23 ++++ .../oh-package.json5 | 7 +- .../src/main/ets/constant/StackConstant.ets | 0 .../src/main/ets/model/IconModel.ets | 0 .../src/main/ets/pages/ComponentStackPage.ets | 5 +- .../src/main/ets/utils/BreakpointSystem.ets | 118 ++++++++++++++++++ .../src/main/ets/utils/WindowUtil.ets | 80 ++++++++++++ .../src/main/ets/view/IconView.ets | 0 .../src/main/ets/view/ProductList.ets | 0 .../src/main/ets/viewmodel/DataSource.ets | 0 .../src/main/ets/viewmodel/IconViewModel.ets | 0 componentstacklibrary/src/main/module.json5 | 11 ++ .../main/resources/base/element/color.json | 0 .../main/resources/base/element/integer.json | 0 .../main/resources/base/element/string.json | 0 .../main/resources/base/media/background.png | Bin .../main/resources/base/media/foreground.png | Bin .../base/media/ic_contacts_birthday.svg | 0 .../base/media/ic_device_matebook_filled.svg | 0 .../media/ic_device_smartscreen_filled.svg | 0 .../base/media/ic_device_sound_x_filled.svg | 0 .../base/media/ic_device_vr_glass_filled.svg | 0 .../base/media/ic_device_watch_filled.svg | 0 .../base/media/ic_gallery_puzzle.svg | 0 .../resources/base/media/ic_public_car.svg | 0 .../resources/base/media/ic_public_cards.svg | 0 .../media/ic_public_devices_phone_filled.svg | 0 .../base/media/ic_public_highlight.svg | 0 .../resources/base/media/layered_image.json | 0 .../main/resources/base/media/product00.png | Bin .../main/resources/base/media/product01.png | Bin .../main/resources/base/media/product02.png | Bin .../main/resources/base/media/product03.png | Bin .../main/resources/base/media/product04.png | Bin .../main/resources/base/media/startIcon.png | Bin .../resources/base/profile/main_pages.json | 5 + .../main/resources/en_US/element/string.json | 0 .../main/resources/zh_CN/element/string.json | 0 .../build-profile.json5 | 0 {entry => componentstacksample}/hvigorfile.ts | 0 .../obfuscation-rules.txt | 0 componentstacksample/oh-package.json5 | 11 ++ .../main/ets/entryability/EntryAbility.ets | 92 +------------- .../src/main/ets/pages/Index.ets | 26 ++++ .../src/main/module.json5 | 6 +- .../resources/base/profile/main_pages.json | 0 52 files changed, 338 insertions(+), 99 deletions(-) create mode 100644 componentstacklibrary/.gitignore create mode 100644 componentstacklibrary/Index.ets create mode 100644 componentstacklibrary/build-profile.json5 create mode 100644 componentstacklibrary/consumer-rules.txt create mode 100644 componentstacklibrary/hvigorfile.ts create mode 100644 componentstacklibrary/obfuscation-rules.txt rename {entry => componentstacklibrary}/oh-package.json5 (58%) rename {entry => componentstacklibrary}/src/main/ets/constant/StackConstant.ets (100%) rename {entry => componentstacklibrary}/src/main/ets/model/IconModel.ets (100%) rename entry/src/main/ets/pages/Index.ets => componentstacklibrary/src/main/ets/pages/ComponentStackPage.ets (99%) create mode 100644 componentstacklibrary/src/main/ets/utils/BreakpointSystem.ets create mode 100644 componentstacklibrary/src/main/ets/utils/WindowUtil.ets rename {entry => componentstacklibrary}/src/main/ets/view/IconView.ets (100%) rename {entry => componentstacklibrary}/src/main/ets/view/ProductList.ets (100%) rename {entry => componentstacklibrary}/src/main/ets/viewmodel/DataSource.ets (100%) rename {entry => componentstacklibrary}/src/main/ets/viewmodel/IconViewModel.ets (100%) create mode 100644 componentstacklibrary/src/main/module.json5 rename {entry => componentstacklibrary}/src/main/resources/base/element/color.json (100%) rename {entry => componentstacklibrary}/src/main/resources/base/element/integer.json (100%) rename {entry => componentstacklibrary}/src/main/resources/base/element/string.json (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/background.png (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/foreground.png (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/ic_contacts_birthday.svg (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/ic_device_matebook_filled.svg (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/ic_device_smartscreen_filled.svg (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/ic_device_sound_x_filled.svg (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/ic_device_vr_glass_filled.svg (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/ic_device_watch_filled.svg (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/ic_gallery_puzzle.svg (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/ic_public_car.svg (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/ic_public_cards.svg (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/ic_public_devices_phone_filled.svg (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/ic_public_highlight.svg (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/layered_image.json (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/product00.png (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/product01.png (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/product02.png (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/product03.png (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/product04.png (100%) rename {entry => componentstacklibrary}/src/main/resources/base/media/startIcon.png (100%) create mode 100644 componentstacklibrary/src/main/resources/base/profile/main_pages.json rename {entry => componentstacklibrary}/src/main/resources/en_US/element/string.json (100%) rename {entry => componentstacklibrary}/src/main/resources/zh_CN/element/string.json (100%) rename {entry => componentstacksample}/build-profile.json5 (100%) rename {entry => componentstacksample}/hvigorfile.ts (100%) rename {entry => componentstacksample}/obfuscation-rules.txt (100%) create mode 100644 componentstacksample/oh-package.json5 rename {entry => componentstacksample}/src/main/ets/entryability/EntryAbility.ets (36%) create mode 100644 componentstacksample/src/main/ets/pages/Index.ets rename {entry => componentstacksample}/src/main/module.json5 (88%) rename {entry => componentstacksample}/src/main/resources/base/profile/main_pages.json (100%) diff --git a/build-profile.json5 b/build-profile.json5 index c033ce4..468b2e7 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -20,8 +20,8 @@ }, "modules": [ { - "name": "entry", - "srcPath": "./entry", + "name": "componentstacksample", + "srcPath": "./componentstacksample", "targets": [ { "name": "default", @@ -30,6 +30,10 @@ ] } ] + }, + { + "name": "componentstacklibrary", + "srcPath": "./componentstacklibrary", } ] } \ No newline at end of file diff --git a/componentstacklibrary/.gitignore b/componentstacklibrary/.gitignore new file mode 100644 index 0000000..e2713a2 --- /dev/null +++ b/componentstacklibrary/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/componentstacklibrary/Index.ets b/componentstacklibrary/Index.ets new file mode 100644 index 0000000..8f9d01b --- /dev/null +++ b/componentstacklibrary/Index.ets @@ -0,0 +1,2 @@ +export { ComponentStackPage} from './src/main/ets/pages/ComponentStackPage' +export { WindowUtil } from './src/main/ets/utils/WindowUtil'; \ No newline at end of file diff --git a/componentstacklibrary/build-profile.json5 b/componentstacklibrary/build-profile.json5 new file mode 100644 index 0000000..e6773f9 --- /dev/null +++ b/componentstacklibrary/build-profile.json5 @@ -0,0 +1,31 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + }, + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest" + } + ] +} diff --git a/componentstacklibrary/consumer-rules.txt b/componentstacklibrary/consumer-rules.txt new file mode 100644 index 0000000..e69de29 diff --git a/componentstacklibrary/hvigorfile.ts b/componentstacklibrary/hvigorfile.ts new file mode 100644 index 0000000..4218707 --- /dev/null +++ b/componentstacklibrary/hvigorfile.ts @@ -0,0 +1,6 @@ +import { harTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/componentstacklibrary/obfuscation-rules.txt b/componentstacklibrary/obfuscation-rules.txt new file mode 100644 index 0000000..272efb6 --- /dev/null +++ b/componentstacklibrary/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/entry/oh-package.json5 b/componentstacklibrary/oh-package.json5 similarity index 58% rename from entry/oh-package.json5 rename to componentstacklibrary/oh-package.json5 index 248c3b7..04e52f5 100644 --- a/entry/oh-package.json5 +++ b/componentstacklibrary/oh-package.json5 @@ -1,10 +1,9 @@ { - "name": "entry", + "name": "componentstacklibrary", "version": "1.0.0", "description": "Please describe the basic information.", - "main": "", + "main": "Index.ets", "author": "", - "license": "", + "license": "Apache-2.0", "dependencies": {} } - diff --git a/entry/src/main/ets/constant/StackConstant.ets b/componentstacklibrary/src/main/ets/constant/StackConstant.ets similarity index 100% rename from entry/src/main/ets/constant/StackConstant.ets rename to componentstacklibrary/src/main/ets/constant/StackConstant.ets diff --git a/entry/src/main/ets/model/IconModel.ets b/componentstacklibrary/src/main/ets/model/IconModel.ets similarity index 100% rename from entry/src/main/ets/model/IconModel.ets rename to componentstacklibrary/src/main/ets/model/IconModel.ets diff --git a/entry/src/main/ets/pages/Index.ets b/componentstacklibrary/src/main/ets/pages/ComponentStackPage.ets similarity index 99% rename from entry/src/main/ets/pages/Index.ets rename to componentstacklibrary/src/main/ets/pages/ComponentStackPage.ets index aab8950..3eae197 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/componentstacklibrary/src/main/ets/pages/ComponentStackPage.ets @@ -18,9 +18,8 @@ import { IconList1, IconList2, IconList3 } from '../view/IconView'; import { StackConstant } from '../constant/StackConstant'; import { ProductList } from '../view/ProductList'; -@Entry @Component -struct Index { +export struct ComponentStackPage { @State searchHeight: number = StackConstant.SEARCH_HEIGHT_RAW; @State opacityList: number = 1; @State opacityList2: number = 1; @@ -166,7 +165,7 @@ struct Index { .layoutWeight(1) .backgroundColor($r('sys.color.background_secondary')) .padding({ - top: px2vp(this.statusHeight), + top: this.statusHeight, left: this.curBp === 'sm' ? $r('sys.float.padding_level8') : this.curBp === 'md' ? $r('sys.float.padding_level12') : $r('sys.float.padding_level16'), right: this.curBp === 'sm' ? $r('sys.float.padding_level8') : diff --git a/componentstacklibrary/src/main/ets/utils/BreakpointSystem.ets b/componentstacklibrary/src/main/ets/utils/BreakpointSystem.ets new file mode 100644 index 0000000..aa7581b --- /dev/null +++ b/componentstacklibrary/src/main/ets/utils/BreakpointSystem.ets @@ -0,0 +1,118 @@ +/* + * 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 type { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + +const TAG: string = '[BreakpointSystem]'; + +export enum BreakpointTypeEnum { + XS = 'xs', + SM = 'sm', + MD = 'md', + LG = 'lg', + XL = 'xl', +} + +export interface BreakpointTypes { + xs?: T; + sm: T; + md: T; + lg: T; + xl?: T; +} + +export class BreakpointType { + private xs: T; + private sm: T; + private md: T; + private lg: T; + private xl: T; + + public constructor(param: BreakpointTypes) { + this.xs = param.xs || param.sm; + this.sm = param.sm; + this.md = param.md; + this.lg = param.lg; + this.xl = param.xl || param.lg; + } + + public getValue(currentBreakpoint: string): T { + if (currentBreakpoint === BreakpointTypeEnum.XS) { + return this.xs; + } + if (currentBreakpoint === BreakpointTypeEnum.SM) { + return this.sm; + } + if (currentBreakpoint === BreakpointTypeEnum.MD) { + return this.md; + } + if (currentBreakpoint === BreakpointTypeEnum.XL) { + return this.xl; + } + return this.lg; + } +} + +export class BreakpointSystem { + private static instance: BreakpointSystem; + private currentBreakpoint: BreakpointTypeEnum = BreakpointTypeEnum.MD; + + private constructor() { + } + + public static getInstance(): BreakpointSystem { + if (!BreakpointSystem.instance) { + BreakpointSystem.instance = new BreakpointSystem(); + } + return BreakpointSystem.instance; + } + + public updateCurrentBreakpoint(breakpoint: BreakpointTypeEnum): void { + if (this.currentBreakpoint !== breakpoint) { + this.currentBreakpoint = breakpoint; + AppStorage.setOrCreate('currentBreakpoint', this.currentBreakpoint); + } + } + + public onWindowSizeChange(window: window.Window): void { + this.updateWidthBp(window); + } + + public updateWidthBp(window: window.Window): void { + try { + const mainWindow: window.WindowProperties = window.getWindowProperties(); + const windowWidth: number = mainWindow.windowRect.width; + const windowWidthVp = px2vp(windowWidth); + let widthBp: BreakpointTypeEnum = BreakpointTypeEnum.MD; + if (windowWidthVp < 320) { + widthBp = BreakpointTypeEnum.XS; + } else if (windowWidthVp >= 320 && windowWidthVp < 600) { + widthBp = BreakpointTypeEnum.SM; + } else if (windowWidthVp >= 600 && windowWidthVp < 840) { + widthBp = BreakpointTypeEnum.MD; + } else if (windowWidthVp >= 840 && windowWidthVp < 1440) { + widthBp = BreakpointTypeEnum.LG; + } else { + widthBp = BreakpointTypeEnum.XL; + } + this.updateCurrentBreakpoint(widthBp); + } catch (error) { + const err: BusinessError = error as BusinessError; + hilog.error(0x0000, TAG, `UpdateBreakpoint fail, error code: ${err.code}, message: ${err.message}`); + } + } +} \ No newline at end of file diff --git a/componentstacklibrary/src/main/ets/utils/WindowUtil.ets b/componentstacklibrary/src/main/ets/utils/WindowUtil.ets new file mode 100644 index 0000000..75b2e80 --- /dev/null +++ b/componentstacklibrary/src/main/ets/utils/WindowUtil.ets @@ -0,0 +1,80 @@ +/* + * 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 type { BusinessError } from '@kit.BasicServicesKit'; +import { BreakpointSystem } from './BreakpointSystem'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { Configuration, ConfigurationConstant } from '@kit.AbilityKit'; + +const TAG: string = '[WindowUtil]'; + +export class WindowUtil { + 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.info(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) { + windowStage.getMainWindow((err: BusinessError, data: window.Window) => { + if (err.code) { + hilog.error(0x0000, TAG, `Failed to get main window: ${err.message}`); + 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); + } + }); + }) + } + + // Get status bar height and indicator height. + public static setAvoidArea(type: window.AvoidAreaType, area: window.AvoidArea) { + if (type === window.AvoidAreaType.TYPE_SYSTEM) { + AppStorage.setOrCreate('statusHeight', px2vp(area.topRect.height)); + } else { + AppStorage.setOrCreate('bottomHeight', px2vp(area.bottomRect.height)); + } + } + + public static updatedColorMode(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); + } + } +} \ No newline at end of file diff --git a/entry/src/main/ets/view/IconView.ets b/componentstacklibrary/src/main/ets/view/IconView.ets similarity index 100% rename from entry/src/main/ets/view/IconView.ets rename to componentstacklibrary/src/main/ets/view/IconView.ets diff --git a/entry/src/main/ets/view/ProductList.ets b/componentstacklibrary/src/main/ets/view/ProductList.ets similarity index 100% rename from entry/src/main/ets/view/ProductList.ets rename to componentstacklibrary/src/main/ets/view/ProductList.ets diff --git a/entry/src/main/ets/viewmodel/DataSource.ets b/componentstacklibrary/src/main/ets/viewmodel/DataSource.ets similarity index 100% rename from entry/src/main/ets/viewmodel/DataSource.ets rename to componentstacklibrary/src/main/ets/viewmodel/DataSource.ets diff --git a/entry/src/main/ets/viewmodel/IconViewModel.ets b/componentstacklibrary/src/main/ets/viewmodel/IconViewModel.ets similarity index 100% rename from entry/src/main/ets/viewmodel/IconViewModel.ets rename to componentstacklibrary/src/main/ets/viewmodel/IconViewModel.ets diff --git a/componentstacklibrary/src/main/module.json5 b/componentstacklibrary/src/main/module.json5 new file mode 100644 index 0000000..a3029a9 --- /dev/null +++ b/componentstacklibrary/src/main/module.json5 @@ -0,0 +1,11 @@ +{ + "module": { + "name": "componentstacklibrary", + "type": "har", + "deviceTypes": [ + "default", + "tablet", + "2in1" + ] + } +} diff --git a/entry/src/main/resources/base/element/color.json b/componentstacklibrary/src/main/resources/base/element/color.json similarity index 100% rename from entry/src/main/resources/base/element/color.json rename to componentstacklibrary/src/main/resources/base/element/color.json diff --git a/entry/src/main/resources/base/element/integer.json b/componentstacklibrary/src/main/resources/base/element/integer.json similarity index 100% rename from entry/src/main/resources/base/element/integer.json rename to componentstacklibrary/src/main/resources/base/element/integer.json diff --git a/entry/src/main/resources/base/element/string.json b/componentstacklibrary/src/main/resources/base/element/string.json similarity index 100% rename from entry/src/main/resources/base/element/string.json rename to componentstacklibrary/src/main/resources/base/element/string.json diff --git a/entry/src/main/resources/base/media/background.png b/componentstacklibrary/src/main/resources/base/media/background.png similarity index 100% rename from entry/src/main/resources/base/media/background.png rename to componentstacklibrary/src/main/resources/base/media/background.png diff --git a/entry/src/main/resources/base/media/foreground.png b/componentstacklibrary/src/main/resources/base/media/foreground.png similarity index 100% rename from entry/src/main/resources/base/media/foreground.png rename to componentstacklibrary/src/main/resources/base/media/foreground.png diff --git a/entry/src/main/resources/base/media/ic_contacts_birthday.svg b/componentstacklibrary/src/main/resources/base/media/ic_contacts_birthday.svg similarity index 100% rename from entry/src/main/resources/base/media/ic_contacts_birthday.svg rename to componentstacklibrary/src/main/resources/base/media/ic_contacts_birthday.svg diff --git a/entry/src/main/resources/base/media/ic_device_matebook_filled.svg b/componentstacklibrary/src/main/resources/base/media/ic_device_matebook_filled.svg similarity index 100% rename from entry/src/main/resources/base/media/ic_device_matebook_filled.svg rename to componentstacklibrary/src/main/resources/base/media/ic_device_matebook_filled.svg diff --git a/entry/src/main/resources/base/media/ic_device_smartscreen_filled.svg b/componentstacklibrary/src/main/resources/base/media/ic_device_smartscreen_filled.svg similarity index 100% rename from entry/src/main/resources/base/media/ic_device_smartscreen_filled.svg rename to componentstacklibrary/src/main/resources/base/media/ic_device_smartscreen_filled.svg diff --git a/entry/src/main/resources/base/media/ic_device_sound_x_filled.svg b/componentstacklibrary/src/main/resources/base/media/ic_device_sound_x_filled.svg similarity index 100% rename from entry/src/main/resources/base/media/ic_device_sound_x_filled.svg rename to componentstacklibrary/src/main/resources/base/media/ic_device_sound_x_filled.svg diff --git a/entry/src/main/resources/base/media/ic_device_vr_glass_filled.svg b/componentstacklibrary/src/main/resources/base/media/ic_device_vr_glass_filled.svg similarity index 100% rename from entry/src/main/resources/base/media/ic_device_vr_glass_filled.svg rename to componentstacklibrary/src/main/resources/base/media/ic_device_vr_glass_filled.svg diff --git a/entry/src/main/resources/base/media/ic_device_watch_filled.svg b/componentstacklibrary/src/main/resources/base/media/ic_device_watch_filled.svg similarity index 100% rename from entry/src/main/resources/base/media/ic_device_watch_filled.svg rename to componentstacklibrary/src/main/resources/base/media/ic_device_watch_filled.svg diff --git a/entry/src/main/resources/base/media/ic_gallery_puzzle.svg b/componentstacklibrary/src/main/resources/base/media/ic_gallery_puzzle.svg similarity index 100% rename from entry/src/main/resources/base/media/ic_gallery_puzzle.svg rename to componentstacklibrary/src/main/resources/base/media/ic_gallery_puzzle.svg diff --git a/entry/src/main/resources/base/media/ic_public_car.svg b/componentstacklibrary/src/main/resources/base/media/ic_public_car.svg similarity index 100% rename from entry/src/main/resources/base/media/ic_public_car.svg rename to componentstacklibrary/src/main/resources/base/media/ic_public_car.svg diff --git a/entry/src/main/resources/base/media/ic_public_cards.svg b/componentstacklibrary/src/main/resources/base/media/ic_public_cards.svg similarity index 100% rename from entry/src/main/resources/base/media/ic_public_cards.svg rename to componentstacklibrary/src/main/resources/base/media/ic_public_cards.svg diff --git a/entry/src/main/resources/base/media/ic_public_devices_phone_filled.svg b/componentstacklibrary/src/main/resources/base/media/ic_public_devices_phone_filled.svg similarity index 100% rename from entry/src/main/resources/base/media/ic_public_devices_phone_filled.svg rename to componentstacklibrary/src/main/resources/base/media/ic_public_devices_phone_filled.svg diff --git a/entry/src/main/resources/base/media/ic_public_highlight.svg b/componentstacklibrary/src/main/resources/base/media/ic_public_highlight.svg similarity index 100% rename from entry/src/main/resources/base/media/ic_public_highlight.svg rename to componentstacklibrary/src/main/resources/base/media/ic_public_highlight.svg diff --git a/entry/src/main/resources/base/media/layered_image.json b/componentstacklibrary/src/main/resources/base/media/layered_image.json similarity index 100% rename from entry/src/main/resources/base/media/layered_image.json rename to componentstacklibrary/src/main/resources/base/media/layered_image.json diff --git a/entry/src/main/resources/base/media/product00.png b/componentstacklibrary/src/main/resources/base/media/product00.png similarity index 100% rename from entry/src/main/resources/base/media/product00.png rename to componentstacklibrary/src/main/resources/base/media/product00.png diff --git a/entry/src/main/resources/base/media/product01.png b/componentstacklibrary/src/main/resources/base/media/product01.png similarity index 100% rename from entry/src/main/resources/base/media/product01.png rename to componentstacklibrary/src/main/resources/base/media/product01.png diff --git a/entry/src/main/resources/base/media/product02.png b/componentstacklibrary/src/main/resources/base/media/product02.png similarity index 100% rename from entry/src/main/resources/base/media/product02.png rename to componentstacklibrary/src/main/resources/base/media/product02.png diff --git a/entry/src/main/resources/base/media/product03.png b/componentstacklibrary/src/main/resources/base/media/product03.png similarity index 100% rename from entry/src/main/resources/base/media/product03.png rename to componentstacklibrary/src/main/resources/base/media/product03.png diff --git a/entry/src/main/resources/base/media/product04.png b/componentstacklibrary/src/main/resources/base/media/product04.png similarity index 100% rename from entry/src/main/resources/base/media/product04.png rename to componentstacklibrary/src/main/resources/base/media/product04.png diff --git a/entry/src/main/resources/base/media/startIcon.png b/componentstacklibrary/src/main/resources/base/media/startIcon.png similarity index 100% rename from entry/src/main/resources/base/media/startIcon.png rename to componentstacklibrary/src/main/resources/base/media/startIcon.png diff --git a/componentstacklibrary/src/main/resources/base/profile/main_pages.json b/componentstacklibrary/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000..3b90675 --- /dev/null +++ b/componentstacklibrary/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/ComponentStackPage" + ] +} diff --git a/entry/src/main/resources/en_US/element/string.json b/componentstacklibrary/src/main/resources/en_US/element/string.json similarity index 100% rename from entry/src/main/resources/en_US/element/string.json rename to componentstacklibrary/src/main/resources/en_US/element/string.json diff --git a/entry/src/main/resources/zh_CN/element/string.json b/componentstacklibrary/src/main/resources/zh_CN/element/string.json similarity index 100% rename from entry/src/main/resources/zh_CN/element/string.json rename to componentstacklibrary/src/main/resources/zh_CN/element/string.json diff --git a/entry/build-profile.json5 b/componentstacksample/build-profile.json5 similarity index 100% rename from entry/build-profile.json5 rename to componentstacksample/build-profile.json5 diff --git a/entry/hvigorfile.ts b/componentstacksample/hvigorfile.ts similarity index 100% rename from entry/hvigorfile.ts rename to componentstacksample/hvigorfile.ts diff --git a/entry/obfuscation-rules.txt b/componentstacksample/obfuscation-rules.txt similarity index 100% rename from entry/obfuscation-rules.txt rename to componentstacksample/obfuscation-rules.txt diff --git a/componentstacksample/oh-package.json5 b/componentstacksample/oh-package.json5 new file mode 100644 index 0000000..a8b6100 --- /dev/null +++ b/componentstacksample/oh-package.json5 @@ -0,0 +1,11 @@ +{ + "name": "componentstacksample", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "componentstacklibrary": "file:../componentstacklibrary" + } +} \ No newline at end of file diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/componentstacksample/src/main/ets/entryability/EntryAbility.ets similarity index 36% rename from entry/src/main/ets/entryability/EntryAbility.ets rename to componentstacksample/src/main/ets/entryability/EntryAbility.ets index 5d6b5dd..d583592 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/componentstacksample/src/main/ets/entryability/EntryAbility.ets @@ -15,34 +15,12 @@ import { Configuration, ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { display, window } from '@kit.ArkUI'; -import { BusinessError } from '@kit.BasicServicesKit'; +import { window } from '@kit.ArkUI'; +import { WindowUtil } from 'componentstacklibrary'; const TAG = '[EntryAbility]'; export default class EntryAbility extends UIAbility { - private curBp: string = ''; - - private updateBreakpoint(windowWidth: number): void { - try { - let windowWidthVp = windowWidth / display.getDefaultDisplaySync().densityPixels; - let newBp: string = ''; - if (windowWidthVp < 600) { - newBp = 'sm'; - } else if (windowWidthVp < 840) { - newBp = 'md'; - } else { - newBp = 'lg'; - } - if (this.curBp !== newBp) { - this.curBp = newBp; - AppStorage.setOrCreate('currentBreakpoint', this.curBp); - } - } catch (error) { - const err = error as BusinessError; - hilog.error(0x000, TAG, `updateBreakpoint catch err: code: ${err.code}, message: ${err.message}`); - } - } onCreate(): void { hilog.info(0x0000, TAG, '%{public}s', 'Ability onCreate'); @@ -55,37 +33,14 @@ export default class EntryAbility extends UIAbility { } 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); - } + WindowUtil.updatedColorMode(newConfig) } onWindowStageCreate(windowStage: window.WindowStage): void { // Main window is created, set main page for this ability. hilog.info(0x0000, TAG, '%{public}s', 'Ability onWindowStageCreate'); - - windowStage.getMainWindow().then((windowObj: window.Window) => { - try { - this.updateBreakpoint(windowObj.getWindowProperties().windowRect.width); - windowObj.on('windowSizeChange', (windowSize) => { - this.updateBreakpoint(windowSize.width); - }) - windowObj.setWindowLayoutFullScreen(true).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, err code: ${err.code}, message: ${err.message}`); - }); - } catch (error) { - const err = error as BusinessError; - hilog.error(0x000, TAG, `onWindowStageCreate catch err, code: ${err.code}, message: ${err.message}`); - } - }).catch((err: BusinessError) => { - hilog.error(0x0000, 'testTag', `Failed to get main window. Cause:`, err.message); - }); + WindowUtil.requestFullScreen(windowStage) + WindowUtil.registerBreakPoint(windowStage) windowStage.loadContent('pages/Index', (err) => { if (err.code) { @@ -94,43 +49,6 @@ export default class EntryAbility extends UIAbility { } hilog.info(0x0000, TAG, 'Succeeded in loading the content.'); }); - let windowClass: window.Window | undefined = undefined; - window.getLastWindow(this.context, (err: BusinessError, data) => { - if (err.code) { - hilog.error(0x0000, TAG, `Failed to obtain top window, err code: ${err.code}, message: ${err.message}`); - return; - } - windowClass = data; - // Top status bar height for window content avoidance. - let statusHeight = 0; - // Height of the bottom security zone that is avoided by the window content. - let bottomHeight = 0; - // Gets the region that the window content avoids. - let type = window.AvoidAreaType.TYPE_SYSTEM; - try { - let avoidArea: window.AvoidArea = windowClass.getWindowAvoidArea(type); - statusHeight = avoidArea.topRect.height; - bottomHeight = avoidArea.bottomRect.height - } catch (error) { - const err = error as BusinessError; - hilog.error(0x0000, TAG, `Failed to obtain the area, err code: ${err.code}, message: ${err.message}`); - } - AppStorage.setOrCreate('statusHeight', statusHeight); - AppStorage.setOrCreate('bottomHeight', bottomHeight); - let screenHeight: number = 0; - let displayClass: display.Display | null = null; - try { - displayClass = display.getDefaultDisplaySync(); - screenHeight = displayClass.height; - } catch (exception) { - const e = exception as BusinessError; - hilog.error(0x0000, TAG, - `Failed to obtain the default display object, err code: ${e.code}, message: ${e.message}`); - } - hilog.info(0x0000, TAG, - 'Succeeded to obtain the default display object. Code: ' + JSON.stringify(displayClass)); - AppStorage.setOrCreate('screenHeight', screenHeight); - }); } onWindowStageDestroy(): void { diff --git a/componentstacksample/src/main/ets/pages/Index.ets b/componentstacksample/src/main/ets/pages/Index.ets new file mode 100644 index 0000000..8be4f1c --- /dev/null +++ b/componentstacksample/src/main/ets/pages/Index.ets @@ -0,0 +1,26 @@ +/* + * 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 { ComponentStackPage } from 'componentstacklibrary' + +@Entry +@Component +struct Index { + build() { + Stack(){ + ComponentStackPage() + } + } +} \ No newline at end of file diff --git a/entry/src/main/module.json5 b/componentstacksample/src/main/module.json5 similarity index 88% rename from entry/src/main/module.json5 rename to componentstacksample/src/main/module.json5 index b2b33b8..f3d8c7c 100644 --- a/entry/src/main/module.json5 +++ b/componentstacksample/src/main/module.json5 @@ -1,6 +1,6 @@ { "module": { - "name": "entry", + "name": "componentstacksample", "type": "entry", "description": "$string:module_desc", "mainElement": "EntryAbility", @@ -14,14 +14,14 @@ "pages": "$profile:main_pages", "abilities": [ { - "name": "EntryAbility", + "name": "ComponentstacksampleAbility", "srcEntry": "./ets/entryability/EntryAbility.ets", "description": "$string:EntryAbility_desc", "icon": "$media:layered_image", "label": "$string:EntryAbility_label", "startWindowIcon": "$media:startIcon", "startWindowBackground": "$color:start_window_background", - "exported": false, + "exported": true, "skills": [ { "entities": [ diff --git a/entry/src/main/resources/base/profile/main_pages.json b/componentstacksample/src/main/resources/base/profile/main_pages.json similarity index 100% rename from entry/src/main/resources/base/profile/main_pages.json rename to componentstacksample/src/main/resources/base/profile/main_pages.json -- Gitee