diff --git a/README.md b/README.md index fbd0ac847f2c71db63d4a18a0f6dd5bf06da3f68..e45666cba70ef95f2125cd2633316ec2f8c0a16f 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ * [ImageEditTaskPool:基于TaskPool实现图片编辑功能](ImageEditTaskPool) * [SegmentedPhotograph:实现相机分段式拍照功能](SegmentedPhotograph) * [ScreenFlickerSolution:解决应用动效闪屏的方案](ScreenFlickerSolution) +* [VisibleComponent:不可见组件低功耗建议](VisibleComponent) ## 使用说明 diff --git a/VisibleComponent/README.md b/VisibleComponent/README.md index 36acc6c4274df08fb134c6a307dc3cfe2ccb504e..9d1bfff2d4893005526f1de244dd062fe549f89b 100644 --- a/VisibleComponent/README.md +++ b/VisibleComponent/README.md @@ -10,6 +10,9 @@ 本示例通过监听法,展示列表组件下拉刷新时,管理刷新动画的不可见现象的场景;通过可见法,展示使用ImageAnimator实现的动画组件。 +### 效果预览 +![pic1.png](screenshots/visibleComponent.gif) + ### 工程目录 ``` ├──entry/src/main/ets @@ -28,10 +31,10 @@ ### 约束与限制 -1.本示例仅支持标准系统上运行,支持设备:华为手机。 +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 -2.HarmonyOS系统:HarmonyOS NEXT Release及以上。 +2. HarmonyOS系统:HarmonyOS 5.0.0 Release及以上。 -3.DevEco Studio版本:DevEco Studio NEXT Release及以上。 +3. DevEco Studio版本:DevEco Studio 5.0.0 Release及以上。 -4.HarmonyOS SDK版本:HarmonyOS NEXT Release SDK及以上。 \ No newline at end of file +4. HarmonyOS SDK版本:HarmonyOS 5.0.0 Release SDK及以上。 \ No newline at end of file diff --git a/VisibleComponent/build-profile.json5 b/VisibleComponent/build-profile.json5 index 2844c740f45df0bfbe0cc3e3472327be382fc1db..1e69556b3411622cb2e87a87389653bb34f1b148 100644 --- a/VisibleComponent/build-profile.json5 +++ b/VisibleComponent/build-profile.json5 @@ -5,7 +5,7 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "5.0.2(14)", + "compatibleSdkVersion": "5.0.0(12)", "runtimeOS": "HarmonyOS", "buildOption": { "strictMode": { diff --git a/VisibleComponent/entry/src/main/ets/entryability/EntryAbility.ets b/VisibleComponent/entry/src/main/ets/entryability/EntryAbility.ets index 508880af8c33aa838016d1cd4b2c68be2f447540..09bb1597f56fcfd063f3a28f8a478fd8cc6f2bbe 100644 --- a/VisibleComponent/entry/src/main/ets/entryability/EntryAbility.ets +++ b/VisibleComponent/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,3 +1,18 @@ +/* +* 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 { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { window } from '@kit.ArkUI'; diff --git a/VisibleComponent/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/VisibleComponent/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets index 8e4de99282050bad799ac892eb85ac5449364a51..73d83824f294cb8bab02d7e49bdefb050b3168be 100644 --- a/VisibleComponent/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/VisibleComponent/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,3 +1,18 @@ +/* +* 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 { hilog } from '@kit.PerformanceAnalysisKit'; import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; diff --git a/VisibleComponent/entry/src/main/ets/pages/Index.ets b/VisibleComponent/entry/src/main/ets/pages/Index.ets index 0e2ee81e17b7079d364d5a0cf5f83a03472da5df..32b627eaa5502e9487f32acf54212a0289d3f270 100644 --- a/VisibleComponent/entry/src/main/ets/pages/Index.ets +++ b/VisibleComponent/entry/src/main/ets/pages/Index.ets @@ -15,6 +15,7 @@ // DocsCode 1 import { apng, ApngController } from '@ohos/apng'; +import { hilog } from '@kit.PerformanceAnalysisKit'; @Entry @Component @@ -30,15 +31,11 @@ struct RefreshExample { Row() { Column() { apng({ - src: 'https://gitee.com/openharmony-sig/ohos_apng/raw/master/entry/src/main/resources/base/media/stack.png', + src: $r('app.media.stack'), controller: this.controller }) - .height('50%') + .margin({ top: 40 }) } - - Text('Refreshing...') - .fontSize(16) - .margin({ left: 20 }) } .alignItems(VerticalAlign.Center) } @@ -51,32 +48,26 @@ struct RefreshExample { build() { Column() { Refresh({ refreshing: $$this.isRefreshing, builder: this.customRefreshComponent() }) { - List() { - ImageAnimatorTest() - ForEach(this.arr, (item: string) => { - ListItem() { - Text('' + item) - .width('70%') - .height(80) - .fontSize(16) - .margin(10) - .textAlign(TextAlign.Center) - .borderRadius(10) - .backgroundColor(0xFFFFFF) - } - }, (item: string) => item) + Scroll() { + Column() { + ImageAnimatorTest() + ForEach(this.arr, (item: string) => { + ListItem() { + Text('' + item) + .height(80) + .fontSize(16) + .textAlign(TextAlign.Center) + .fontColor(0xF1F3F5) + } + }, (item: string) => item) + } } - .onScrollIndex((first: number) => { - console.info(first.toString()); - }) - .width('100%') - .height('100%') - .alignListItem(ListItemAlign.Center) .scrollBar(BarState.Off) } - .backgroundColor(0x89CFF0) + .backgroundColor(0xF1F3F5) .pullToRefresh(true) .refreshOffset(64) + .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]) // Use onStateChange and apngcontroller to control play and stop .onStateChange((refreshStatus: RefreshStatus) => { if (refreshStatus >= 1 && refreshStatus < 4) { @@ -84,13 +75,13 @@ struct RefreshExample { } else { this.controller.stop(); } - console.info('Refresh onStatueChange state is ' + refreshStatus); + hilog.info(0x0000, 'testTag', 'Refresh onStatueChange state is ' + refreshStatus); }) .onRefreshing(() => { setTimeout(() => { this.isRefreshing = false; }, 2000) - console.log('onRefreshing test') + hilog.info(0x0000, 'testTag', 'onRefreshing test') }) } } @@ -108,12 +99,12 @@ struct ImageAnimatorTest { // Method 1: use aboutToAppear to register a setOnVisibleAreaApproximateChange aboutToAppear(): void { this.uid = this.getUniqueId(); - console.log(`getUniqueId in ImageAnimatorTest aboutAppear is ${this.uid}`); + hilog.info(0x0000, 'testTag', `getUniqueId in ImageAnimatorTest aboutAppear is ${this.uid}`); let node = this.getUIContext().getFrameNodeByUniqueId(this.uid); node?.commonEvent.setOnVisibleAreaApproximateChange( { ratios: [0], expectedUpdateInterval: 500 }, (isVisible, currentRatio) => { - console.log(`Method aboutToAppear: setOnVisibleAreaApproximateChange isVisible:${isVisible}, currentRatio:${currentRatio}`); + hilog.info(0x0000, 'testTag', `Method aboutToAppear: setOnVisibleAreaApproximateChange isVisible:${isVisible}, currentRatio:${currentRatio}`); this.running = isVisible; }) } @@ -134,7 +125,7 @@ struct ImageAnimatorTest { .state(this.running ? AnimationStatus.Running : AnimationStatus.Paused) // Method 2: Directly use onVisibleAreaChange .onVisibleAreaChange([0.0, 1.0], (isVisible: boolean, currentRatio: number) => { - console.log(`Method Direct: onVisibleAreaChange isVisible:${isVisible}, currentRatio:${currentRatio}`); + hilog.info(0x0000, 'testTag', `Method Direct: onVisibleAreaChange isVisible:${isVisible}, currentRatio:${currentRatio}`); if (isVisible && currentRatio >= 1.0) { this.running = true; } @@ -149,7 +140,7 @@ struct ImageAnimatorTest { { ratios: [0], expectedUpdateInterval: 500 }, (isVisible, currentRatio) => { this.running = isVisible; - console.log(`Method onAppear: setOnVisibleAreaApproximateChange isVisible:${isVisible}, currentRatio:${currentRatio}`); + hilog.info(0x0000, 'testTag', `Method onAppear: setOnVisibleAreaApproximateChange isVisible:${isVisible}, currentRatio:${currentRatio}`); } ) }) diff --git a/VisibleComponent/entry/src/main/resources/base/media/stack.png b/VisibleComponent/entry/src/main/resources/base/media/stack.png new file mode 100644 index 0000000000000000000000000000000000000000..23d70b8748c9a4cfe3d6003eb315381a2b64d762 Binary files /dev/null and b/VisibleComponent/entry/src/main/resources/base/media/stack.png differ diff --git a/VisibleComponent/screenshots/visibleComponent.gif b/VisibleComponent/screenshots/visibleComponent.gif new file mode 100644 index 0000000000000000000000000000000000000000..4967d58d95c4ac576d587f79728b01321cce9a50 Binary files /dev/null and b/VisibleComponent/screenshots/visibleComponent.gif differ