diff --git a/build-profile.json5 b/build-profile.json5 index c033ce4278fb0641d84107c3c134047ac487368e..e82b0bb2e65a6100ff04495d6ca067b934fc9b76 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -20,8 +20,8 @@ }, "modules": [ { - "name": "entry", - "srcPath": "./entry", + "name": "scrollcomponentsample", + "srcPath": "./scrollcomponentsample", "targets": [ { "name": "default", @@ -30,6 +30,10 @@ ] } ] + }, + { + "name": "scrollcomponentlibrary", + "srcPath": "./scrollcomponentlibrary", } ] } \ No newline at end of file diff --git a/scrollcomponentlibrary/.gitignore b/scrollcomponentlibrary/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/scrollcomponentlibrary/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/scrollcomponentlibrary/Index.ets b/scrollcomponentlibrary/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..4626d608d19819ea7eb7e424dc8d9ab5c2616404 --- /dev/null +++ b/scrollcomponentlibrary/Index.ets @@ -0,0 +1,2 @@ +export { ScrollComponentNestedSlidingPage} from './src/main/ets/pages/ScrollComponentNestedSlidingPage' +export { WindowUtil } from './src/main/ets/utils/WindowUtil'; \ No newline at end of file diff --git a/scrollcomponentlibrary/build-profile.json5 b/scrollcomponentlibrary/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e6773f9f5d76a66d6d19fddc9c6ddb3f5621d3b1 --- /dev/null +++ b/scrollcomponentlibrary/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/scrollcomponentlibrary/consumer-rules.txt b/scrollcomponentlibrary/consumer-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/scrollcomponentlibrary/hvigorfile.ts b/scrollcomponentlibrary/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..42187071482d292588ad40babeda74f7b8d97a23 --- /dev/null +++ b/scrollcomponentlibrary/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/scrollcomponentlibrary/obfuscation-rules.txt b/scrollcomponentlibrary/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/scrollcomponentlibrary/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/scrollcomponentlibrary/oh-package.json5 similarity index 58% rename from entry/oh-package.json5 rename to scrollcomponentlibrary/oh-package.json5 index 248c3b7541a589682a250f86a6d3ecf7414d2d6a..5454d3e8b876977b9b1bd693fb8dec7f3d6770a7 100644 --- a/entry/oh-package.json5 +++ b/scrollcomponentlibrary/oh-package.json5 @@ -1,10 +1,9 @@ { - "name": "entry", + "name": "scrollcomponentlibrary", "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/common/constants/CommonConstants.ets b/scrollcomponentlibrary/src/main/ets/common/constants/CommonConstants.ets similarity index 100% rename from entry/src/main/ets/common/constants/CommonConstants.ets rename to scrollcomponentlibrary/src/main/ets/common/constants/CommonConstants.ets diff --git a/entry/src/main/ets/pages/Index.ets b/scrollcomponentlibrary/src/main/ets/pages/ScrollComponentNestedSlidingPage.ets similarity index 89% rename from entry/src/main/ets/pages/Index.ets rename to scrollcomponentlibrary/src/main/ets/pages/ScrollComponentNestedSlidingPage.ets index 713a34a7c24a04029a22e99fac20568c948066a1..2a2ab5d8f29ddf91eaee585d0083daf9095a5059 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/scrollcomponentlibrary/src/main/ets/pages/ScrollComponentNestedSlidingPage.ets @@ -15,7 +15,7 @@ import { listArr } from '../viewmodel/InitData'; import { CommonConstants } from '../common/constants/CommonConstants'; -import { BreakpointType } from '../common/utils/Utils'; +import { BreakpointType } from '../utils/BreakpointSystem'; import { ItemRestriction, SegmentButton, @@ -23,9 +23,8 @@ import { SegmentButtonTextItem } from '@ohos.arkui.advanced.SegmentButton'; -@Entry @Component -struct NestedCeiling { +export struct ScrollComponentNestedSlidingPage { @State @Watch('onSegmentButtonChange') tabSelectedIndexes: number[] = [0]; @State currentIndex: number = 0; @State tabOptions: SegmentButtonOptions = SegmentButtonOptions.tab({ @@ -103,7 +102,7 @@ struct NestedCeiling { }, (item: string) => JSON.stringify(item)) } .borderRadius($r('app.float.list_item_radius')) - .lanes(new BreakpointType(1, 2, 2).getValue(this.curBp)) + .lanes(new BreakpointType({ sm: 1, md: 2, lg: 2 }).getValue(this.curBp)) .width(CommonConstants.FULL_WIDTH) .height(CommonConstants.FULL_HEIGHT) .edgeEffect(EdgeEffect.None) @@ -140,15 +139,19 @@ struct NestedCeiling { } } } - .height(new BreakpointType('210%', '120%', '120%').getValue(this.curBp)) + .height(new BreakpointType({ sm: '210%', md: '120%', lg: '120%' }).getValue(this.curBp)) .scrollBar(BarState.Off) .width(CommonConstants.FULL_WIDTH) } .padding({ - left: new BreakpointType($r('sys.float.padding_level8'), $r('sys.float.padding_level12'), - $r('sys.float.padding_level16')).getValue(this.curBp), - right: new BreakpointType($r('sys.float.padding_level8'), $r('sys.float.padding_level12'), - $r('sys.float.padding_level16')).getValue(this.curBp), + left: new BreakpointType({ + sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level12'), + lg: $r('sys.float.padding_level16') + }).getValue(this.curBp), + right: new BreakpointType({ + sm: $r('sys.float.padding_level8'), md: $r('sys.float.padding_level12'), + lg: $r('sys.float.padding_level16') + }).getValue(this.curBp), top: px2vp(this.topRectHeight) }) .width(CommonConstants.FULL_WIDTH) diff --git a/scrollcomponentlibrary/src/main/ets/utils/BreakpointSystem.ets b/scrollcomponentlibrary/src/main/ets/utils/BreakpointSystem.ets new file mode 100644 index 0000000000000000000000000000000000000000..aa7581b2047323eac83c8d9a031e21faabc55bd2 --- /dev/null +++ b/scrollcomponentlibrary/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/scrollcomponentlibrary/src/main/ets/utils/WindowUtil.ets b/scrollcomponentlibrary/src/main/ets/utils/WindowUtil.ets new file mode 100644 index 0000000000000000000000000000000000000000..5b26bd8705d8ce54fe1d6b642fa559db683bef0b --- /dev/null +++ b/scrollcomponentlibrary/src/main/ets/utils/WindowUtil.ets @@ -0,0 +1,70 @@ +/* + * 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'; + +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('statusBarHeight', px2vp(area.topRect.height)); + } else { + AppStorage.setOrCreate('naviIndicatorHeight', px2vp(area.bottomRect.height)); + } + } +} \ No newline at end of file diff --git a/entry/src/main/ets/viewmodel/InitData.ets b/scrollcomponentlibrary/src/main/ets/viewmodel/InitData.ets similarity index 100% rename from entry/src/main/ets/viewmodel/InitData.ets rename to scrollcomponentlibrary/src/main/ets/viewmodel/InitData.ets diff --git a/scrollcomponentlibrary/src/main/module.json5 b/scrollcomponentlibrary/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6eb1064bc0b57431cf7f429a9115ed80b095e36a --- /dev/null +++ b/scrollcomponentlibrary/src/main/module.json5 @@ -0,0 +1,11 @@ +{ + "module": { + "name": "scrollcomponentlibrary", + "type": "har", + "deviceTypes": [ + "default", + "tablet", + "2in1" + ] + } +} diff --git a/entry/src/main/resources/base/element/color.json b/scrollcomponentlibrary/src/main/resources/base/element/color.json similarity index 100% rename from entry/src/main/resources/base/element/color.json rename to scrollcomponentlibrary/src/main/resources/base/element/color.json diff --git a/entry/src/main/resources/base/element/float.json b/scrollcomponentlibrary/src/main/resources/base/element/float.json similarity index 100% rename from entry/src/main/resources/base/element/float.json rename to scrollcomponentlibrary/src/main/resources/base/element/float.json diff --git a/entry/src/main/resources/base/element/string.json b/scrollcomponentlibrary/src/main/resources/base/element/string.json similarity index 100% rename from entry/src/main/resources/base/element/string.json rename to scrollcomponentlibrary/src/main/resources/base/element/string.json diff --git a/entry/src/main/resources/base/media/icon.png b/scrollcomponentlibrary/src/main/resources/base/media/icon.png similarity index 100% rename from entry/src/main/resources/base/media/icon.png rename to scrollcomponentlibrary/src/main/resources/base/media/icon.png diff --git a/entry/src/main/resources/base/media/startIcon.png b/scrollcomponentlibrary/src/main/resources/base/media/startIcon.png similarity index 100% rename from entry/src/main/resources/base/media/startIcon.png rename to scrollcomponentlibrary/src/main/resources/base/media/startIcon.png diff --git a/scrollcomponentlibrary/src/main/resources/base/profile/main_pages.json b/scrollcomponentlibrary/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..b7abdcd71467024676e06d95d7e8cee39084a055 --- /dev/null +++ b/scrollcomponentlibrary/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/ScrollComponentNestedSlidingPage" + ] +} diff --git a/entry/src/main/resources/en_US/element/string.json b/scrollcomponentlibrary/src/main/resources/en_US/element/string.json similarity index 100% rename from entry/src/main/resources/en_US/element/string.json rename to scrollcomponentlibrary/src/main/resources/en_US/element/string.json diff --git a/entry/src/main/resources/zh_CN/element/string.json b/scrollcomponentlibrary/src/main/resources/zh_CN/element/string.json similarity index 100% rename from entry/src/main/resources/zh_CN/element/string.json rename to scrollcomponentlibrary/src/main/resources/zh_CN/element/string.json diff --git a/entry/build-profile.json5 b/scrollcomponentsample/build-profile.json5 similarity index 100% rename from entry/build-profile.json5 rename to scrollcomponentsample/build-profile.json5 diff --git a/entry/hvigorfile.ts b/scrollcomponentsample/hvigorfile.ts similarity index 100% rename from entry/hvigorfile.ts rename to scrollcomponentsample/hvigorfile.ts diff --git a/entry/obfuscation-rules.txt b/scrollcomponentsample/obfuscation-rules.txt similarity index 100% rename from entry/obfuscation-rules.txt rename to scrollcomponentsample/obfuscation-rules.txt diff --git a/scrollcomponentsample/oh-package.json5 b/scrollcomponentsample/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..60a91ce653903b16d0c483c50d8270c720e53787 --- /dev/null +++ b/scrollcomponentsample/oh-package.json5 @@ -0,0 +1,11 @@ +{ + "name": "scrollcomponentsample", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "scrollcomponentlibrary": "file:../scrollcomponentlibrary" + } +} \ No newline at end of file diff --git a/scrollcomponentsample/oh_modules/scrollcomponentlibrary/.gitignore b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/scrollcomponentsample/oh_modules/scrollcomponentlibrary/BuildProfile.ets b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/BuildProfile.ets new file mode 100644 index 0000000000000000000000000000000000000000..3a501e5ddee8ea6d28961648fc7dd314a5304bd4 --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/BuildProfile.ets @@ -0,0 +1,17 @@ +/** + * 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/scrollcomponentsample/oh_modules/scrollcomponentlibrary/Index.ets b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..4626d608d19819ea7eb7e424dc8d9ab5c2616404 --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/Index.ets @@ -0,0 +1,2 @@ +export { ScrollComponentNestedSlidingPage} from './src/main/ets/pages/ScrollComponentNestedSlidingPage' +export { WindowUtil } from './src/main/ets/utils/WindowUtil'; \ No newline at end of file diff --git a/scrollcomponentsample/oh_modules/scrollcomponentlibrary/build-profile.json5 b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e6773f9f5d76a66d6d19fddc9c6ddb3f5621d3b1 --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/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/scrollcomponentsample/oh_modules/scrollcomponentlibrary/consumer-rules.txt b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/consumer-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/scrollcomponentsample/oh_modules/scrollcomponentlibrary/hvigorfile.ts b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..42187071482d292588ad40babeda74f7b8d97a23 --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/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/scrollcomponentsample/oh_modules/scrollcomponentlibrary/obfuscation-rules.txt b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/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/scrollcomponentsample/oh_modules/scrollcomponentlibrary/oh-package.json5 b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5454d3e8b876977b9b1bd693fb8dec7f3d6770a7 --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/oh-package.json5 @@ -0,0 +1,9 @@ +{ + "name": "scrollcomponentlibrary", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "Index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": {} +} diff --git a/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/ets/common/constants/CommonConstants.ets b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/ets/common/constants/CommonConstants.ets new file mode 100644 index 0000000000000000000000000000000000000000..ffaf983e4c9c60c9576488653e04b25e92b3f601 --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/ets/common/constants/CommonConstants.ets @@ -0,0 +1,44 @@ +/* + * 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. + */ + +/** + * Common constants for all features. + */ +export class CommonConstants { + /** + * font weight is 500. + */ + public static readonly FONT_WEIGHT_FIVE: number = 500; + /** + * Width the percentage of the 100. + */ + public static readonly FULL_WIDTH: string = '100%'; + /** + * Height the percentage of the 100. + */ + public static readonly FULL_HEIGHT: string = '100%'; + /** + * Breakpoint sm. + */ + public static readonly BREAK_POINT_SM: string = 'sm'; + /** + * Breakpoint md. + */ + public static readonly BREAK_POINT_MD: string = 'md'; + /** + * Breakpoint lg. + */ + public static readonly BREAK_POINT_LG: string = 'lg'; +} \ No newline at end of file diff --git a/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/ets/utils/WindowUtil.ets b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/ets/utils/WindowUtil.ets new file mode 100644 index 0000000000000000000000000000000000000000..5b26bd8705d8ce54fe1d6b642fa559db683bef0b --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/ets/utils/WindowUtil.ets @@ -0,0 +1,70 @@ +/* + * 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'; + +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('statusBarHeight', px2vp(area.topRect.height)); + } else { + AppStorage.setOrCreate('naviIndicatorHeight', px2vp(area.bottomRect.height)); + } + } +} \ No newline at end of file diff --git a/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/ets/viewmodel/InitData.ets b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/ets/viewmodel/InitData.ets new file mode 100644 index 0000000000000000000000000000000000000000..cf044492379cb9351ef02a7db2dfdc07b815d448 --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/ets/viewmodel/InitData.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +/** + * List data + */ +export const listArr: string[] = + ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', + '22', '23', '24']; \ No newline at end of file diff --git a/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/module.json5 b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6eb1064bc0b57431cf7f429a9115ed80b095e36a --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/module.json5 @@ -0,0 +1,11 @@ +{ + "module": { + "name": "scrollcomponentlibrary", + "type": "har", + "deviceTypes": [ + "default", + "tablet", + "2in1" + ] + } +} diff --git a/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/element/color.json b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..81279aa6575f3fe6547aabf35842a0972543787d --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#F1F3F5" + } + ] +} \ No newline at end of file diff --git a/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/element/float.json b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..4c2b7be365f14481e64b85e29b341bfdbfc569a5 --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/element/float.json @@ -0,0 +1,40 @@ +{ + "float": [ + { + "name": "middle_font_size", + "value": "14fp" + }, + { + "name": "button_border_radius", + "value": "21fp" + }, + { + "name": "button_height", + "value": "36fp" + }, + { + "name": "button_width", + "value": "84fp" + }, + { + "name": "list_item_radius", + "value": "16vp" + }, + { + "name": "list_item_padding", + "value": "12vp" + }, + { + "name": "list_item_height", + "value": "56vp" + }, + { + "name": "big_font_size", + "value": "30fp" + }, + { + "name": "discover_bottom_padding", + "value": "16vp" + } + ] +} \ No newline at end of file diff --git a/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/element/string.json b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e64f6259e1b2a6801fffa820f8b2fb6ad0b81c44 --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/element/string.json @@ -0,0 +1,36 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "Scroll组件嵌套滑动" + }, + { + "name": "title", + "value": "Scroll组件嵌套滑动" + }, + { + "name": "Promotional", + "value": "促销活动" + }, + { + "name": "Travel", + "value": "行程服务" + }, + { + "name": "goods", + "value": "促销商品" + }, + { + "name": "Itinerary", + "value": "行程安排" + } + ] +} \ No newline at end of file diff --git a/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/media/icon.png b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..cd45accb1dfd2fd0da16c732c72faa6e46b26521 Binary files /dev/null and b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/media/icon.png differ diff --git a/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/media/startIcon.png b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..366f76459ffd4494ec40d0ddd5c59385b9c5da11 Binary files /dev/null and b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/media/startIcon.png differ diff --git a/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/profile/main_pages.json b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..b7abdcd71467024676e06d95d7e8cee39084a055 --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/ScrollComponentNestedSlidingPage" + ] +} diff --git a/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/en_US/element/string.json b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..cf462b72a09320f8b68af2f622ad8e8be4daf8a3 --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/en_US/element/string.json @@ -0,0 +1,36 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "ScrollComponentNestedSliding" + }, + { + "name": "title", + "value": "Nested scrolling of the Scroll component" + }, + { + "name": "Promotional", + "value": "Promotion activity" + }, + { + "name": "Travel", + "value": "Travel service" + }, + { + "name": "goods", + "value": "Promotion goods" + }, + { + "name": "Itinerary", + "value": "Itinerary arrangement" + } + ] +} \ No newline at end of file diff --git a/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/zh_CN/element/string.json b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e64f6259e1b2a6801fffa820f8b2fb6ad0b81c44 --- /dev/null +++ b/scrollcomponentsample/oh_modules/scrollcomponentlibrary/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,36 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "Scroll组件嵌套滑动" + }, + { + "name": "title", + "value": "Scroll组件嵌套滑动" + }, + { + "name": "Promotional", + "value": "促销活动" + }, + { + "name": "Travel", + "value": "行程服务" + }, + { + "name": "goods", + "value": "促销商品" + }, + { + "name": "Itinerary", + "value": "行程安排" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/scrollcomponentsample/src/main/ets/entryability/EntryAbility.ets similarity index 47% rename from entry/src/main/ets/entryability/EntryAbility.ets rename to scrollcomponentsample/src/main/ets/entryability/EntryAbility.ets index 51b3851f4a9c0d20d912afe86eae0116c6e3e9da..dd6cbe14e632587499cb8d2fef0c602a91c177b3 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/scrollcomponentsample/src/main/ets/entryability/EntryAbility.ets @@ -14,34 +14,11 @@ */ import { ConfigurationConstant, UIAbility } from '@kit.AbilityKit'; -import { display, window } from '@kit.ArkUI'; +import { window } from '@kit.ArkUI'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { resourceManager } from '@kit.LocalizationKit'; +import { WindowUtil } from 'scrollcomponentlibrary'; 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 (exception) { - hilog.error(0x0000, 'testTag', '%{public}s', - `UpdateBreakpoint fail, error code: ${(exception as BusinessError).code}`); - } - } onCreate(): void { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); @@ -54,38 +31,10 @@ export default class EntryAbility extends UIAbility { } onWindowStageCreate(windowStage: window.WindowStage): void { - windowStage.getMainWindow().then((windowObj: window.Window) => { - let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; - try { - let avoidArea = windowObj.getWindowAvoidArea(type); - let bottomRectHeight = avoidArea.bottomRect.height; - AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight); - type = window.AvoidAreaType.TYPE_SYSTEM; - avoidArea = windowObj.getWindowAvoidArea(type); - let topRectHeight = avoidArea.topRect.height; - AppStorage.setOrCreate('topRectHeight', topRectHeight); - this.updateBreakpoint(windowObj.getWindowProperties().windowRect.width); - - windowObj.on('windowSizeChange', (windowSize) => { - this.updateBreakpoint(windowSize.width); - }); - - windowObj.setWindowLayoutFullScreen(true).then(() => { - hilog.info(0x0000, 'testTag', '%{public}s', 'Succeeded in setting the window layout to full-screen mode.'); - }).catch((err: BusinessError) => { - hilog.error(0x0000, 'testTag', `Failed to set the window layout to full-screen mode. Cause: ${err.message}`); - }); - } catch (err) { - hilog.error(0x0000, 'testTag', '%{public}s', `config window fail. Cause: ${err.code}`); - } - }).catch((err: BusinessError) => { - hilog.error(0x0000, 'testTag', `Failed to get main window. Cause: ${err.message}`); - }); + WindowUtil.requestFullScreen(windowStage) + WindowUtil.registerBreakPoint(windowStage) // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - let context = this.context; - let resourceManager: resourceManager.ResourceManager = context.resourceManager; - AppStorage.setOrCreate('resourceManager', resourceManager); windowStage.loadContent('pages/Index', (err) => { if (err.code) { hilog.error(0x0000, 'testTag', '%{public}s', `Failed to load the content. Cause: ${err.code}`); diff --git a/entry/src/main/ets/common/utils/Utils.ets b/scrollcomponentsample/src/main/ets/pages/Index.ets similarity index 55% rename from entry/src/main/ets/common/utils/Utils.ets rename to scrollcomponentsample/src/main/ets/pages/Index.ets index 271114e5f8f02d20e9ec6033cefc39da7d31ea0a..629ac835538bb38bcdd93f45f9479f387a392c0a 100644 --- a/entry/src/main/ets/common/utils/Utils.ets +++ b/scrollcomponentsample/src/main/ets/pages/Index.ets @@ -12,27 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { CommonConstants } from '../constants/CommonConstants'; -export class BreakpointType { - private sm: T; - private md: T; - private lg: T; +import { ScrollComponentNestedSlidingPage } from 'scrollcomponentlibrary' - constructor(sm: T, md: T, lg: T) { - this.sm = sm; - this.md = md; - this.lg = lg; - } - - getValue(currentBreakpoint: string): T { - if (currentBreakpoint === CommonConstants.BREAK_POINT_MD) { - return this.md; - } - if (currentBreakpoint === CommonConstants.BREAK_POINT_LG) { - return this.lg; - } else { - return this.sm; +@Entry +@Component +struct Index { + build() { + Stack(){ + ScrollComponentNestedSlidingPage() } } } \ No newline at end of file diff --git a/entry/src/main/module.json5 b/scrollcomponentsample/src/main/module.json5 similarity index 88% rename from entry/src/main/module.json5 rename to scrollcomponentsample/src/main/module.json5 index 4ce13180c363e69c1fc454fba00c230b668cb871..b33a6d47deaa7210ad22759cbe2e2baa9a9956cb 100644 --- a/entry/src/main/module.json5 +++ b/scrollcomponentsample/src/main/module.json5 @@ -1,6 +1,6 @@ { "module": { - "name": "entry", + "name": "scrollcomponentsample", "type": "entry", "description": "$string:module_desc", "mainElement": "EntryAbility", @@ -14,14 +14,14 @@ "pages": "$profile:main_pages", "abilities": [ { - "name": "EntryAbility", + "name": "ScrollcomponentsampleAbility", "srcEntry": "./ets/entryability/EntryAbility.ets", "description": "$string:EntryAbility_desc", "icon": "$media:icon", "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/scrollcomponentsample/src/main/resources/base/profile/main_pages.json similarity index 100% rename from entry/src/main/resources/base/profile/main_pages.json rename to scrollcomponentsample/src/main/resources/base/profile/main_pages.json