diff --git a/WaterFlowSample/README.md b/WaterFlowSample/README.md new file mode 100644 index 0000000000000000000000000000000000000000..90b36e1d5d1b57207c240d7d439bae50fbd2ce96 --- /dev/null +++ b/WaterFlowSample/README.md @@ -0,0 +1,54 @@ +# 常见瀑布流操作 + +### 简介 + +本示例基于WaterFlow组件的特性,整理了瀑布流常见操作的示例代码。 + +### 工程目录 +``` +├─entry/src/main/ets +│ ├─common/constants +│ │ └─CommonConstants.ets // 常量类 +│ ├─entryability +│ │ └─EntryAbility.ets // 入口文件 +│ ├─entrybackupability +│ │ └─EntryBackupAbility.ets // backup +│ ├─model +│ │ ├─BasicDataSource.ets // 基类DataSource +│ │ ├─MediaItem.ets // 媒体实体类 +│ │ ├─MyDataSource.ets // 我的DataSource +│ │ ├─SectionsWaterFlowDataSource.ets // 分组DataSource +│ │ └─StickyWaterFlowDataSource.ets // 吸顶DataSource +│ ├─pages +│ │ ├─CustomItemHeightPage.ets // 自定义分组和高度页面 +│ │ ├─DataLoadMorePage.ets // 加载更多页面 +│ │ ├─DataUpadteAndAnimationPage.ets // 下拉刷新页面 +│ │ ├─ElementByOrderPage.ets // 元素分类页面 +│ │ ├─FadingEdgePage.ets // 边缘渐隐页面 +│ │ ├─FlowItemAutoPlayPage.ets // 停止自动播放页面 +│ │ ├─FlowItemRmoveAnimationPage.ets // 移除item带动画页面 +│ │ ├─FlowItemRmovePage.ets // 移除item页面 +│ │ ├─ForceShowOnTopLeftPage.ets // 强制左上角显示页面 +│ │ ├─Index.ets // 主页 +│ │ ├─MergeDoubleWaterFlowPage.ets // 合并两个瀑布流页面 +│ │ ├─SectionOptionsUsePage.ets // 分组功能页面 +│ │ ├─StickOnTopPage.ets // 吸顶功能页面 +│ │ └─ZoomChangeColumnPage.ets // 缩放改变列数页面 +│ └─utils +│ └─WindowUtil.ets // 窗口工具类 +└─entry/src/main/resources // 应用资源目录 +``` + +### 相关权限 + +不涉及 + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:华为手机。 + +2.HarmonyOS系统:HarmonyOS 5.0.5 Release及以上。 + +3.DevEco Studio版本:DevEco Studio 5.0.5 Release及以上。 + +4.HarmonyOS SDK版本:HarmonyOS 5.0.5 Release SDK及以上。 \ No newline at end of file diff --git a/WaterFlowSample/build-profile.json5 b/WaterFlowSample/build-profile.json5 index 62265cd52976474b15a363b3ce0cf6451946114d..7cfdffbbeca5c27f3c74076ae11f44209b1e6615 100644 --- a/WaterFlowSample/build-profile.json5 +++ b/WaterFlowSample/build-profile.json5 @@ -6,8 +6,8 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "5.0.5(17)", "targetSdkVersion": "5.0.5(17)", + "compatibleSdkVersion": "5.0.5(17)", "runtimeOS": "HarmonyOS", "buildOption": { "strictMode": { diff --git a/WaterFlowSample/entry/src/main/ets/common/constants/CommonConstants.ets b/WaterFlowSample/entry/src/main/ets/common/constants/CommonConstants.ets index a6ba20f2f665a02fa9ff25f7c8d24ca331a3b894..5de6c0e929c97be47221b4434a7c09e517bcfc9e 100644 --- a/WaterFlowSample/entry/src/main/ets/common/constants/CommonConstants.ets +++ b/WaterFlowSample/entry/src/main/ets/common/constants/CommonConstants.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 diff --git a/WaterFlowSample/entry/src/main/ets/entryability/EntryAbility.ets b/WaterFlowSample/entry/src/main/ets/entryability/EntryAbility.ets index a1b9d910217b8eb04b87a1ec2d9dd34edac9a616..b6b0dcb6600718a51cc3a795e187ff03b2c54eba 100644 --- a/WaterFlowSample/entry/src/main/ets/entryability/EntryAbility.ets +++ b/WaterFlowSample/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2025 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'; @@ -7,8 +22,12 @@ const DOMAIN = 0x0000; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { - this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(0x0000, 'testTag', 'Failed to setColorMode. Cause: %{public}s', JSON.stringify(err) ?? ''); + } } onDestroy(): void { diff --git a/WaterFlowSample/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/WaterFlowSample/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets index fae19f9dd53d2857e2843539cbedf5bee4a34b5a..1fca37ecc34e1079aaf6557f1272cd694aa0068c 100644 --- a/WaterFlowSample/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +++ b/WaterFlowSample/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2025 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/WaterFlowSample/entry/src/main/ets/model/MyDataSource.ets b/WaterFlowSample/entry/src/main/ets/model/MyDataSource.ets index 540edfc0bd36a13a89c4e7ef4c74eafd27f00ae7..ceef0cc51a841364b359e808f2a3db393394ddda 100644 --- a/WaterFlowSample/entry/src/main/ets/model/MyDataSource.ets +++ b/WaterFlowSample/entry/src/main/ets/model/MyDataSource.ets @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { BasicDataSource } from "./BasicDataSource"; export class MyDataSource extends BasicDataSource { diff --git a/WaterFlowSample/entry/src/main/ets/pages/CustomItemHeightPage.ets b/WaterFlowSample/entry/src/main/ets/pages/CustomItemHeightPage.ets index 95b6dd02c6779460c2103db821be935f72637611..c72e67e6ef0f3a90b33961fdf7015650a52045d8 100644 --- a/WaterFlowSample/entry/src/main/ets/pages/CustomItemHeightPage.ets +++ b/WaterFlowSample/entry/src/main/ets/pages/CustomItemHeightPage.ets @@ -1,5 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + // [Start quick_start] import { SectionsWaterFlowDataSource } from "../model/SectionsWaterFlowDataSource"; + // [StartExclude flow_item_layout] @Reusable struct ReusableFlowItem { @@ -60,6 +76,7 @@ struct ReusableFlowItem { .backgroundColor(Color.Gray) } } + // [EndExclude flow_item_layout] @Entry @Component @@ -108,12 +125,12 @@ export struct CustomItemHeightPage { } }; - getSize() { + getSize(): number { let ret = Math.floor(Math.random() * this.maxSize); return (ret > this.minSize ? ret : this.minSize); } - setItemSizeArray() { + setItemSizeArray(): void { for (let i = 0; i < 100; i++) { this.itemHeightArray.push(this.getSize()); } @@ -124,7 +141,7 @@ export struct CustomItemHeightPage { this.initSections(); } - initSections() { + initSections(): void { let sectionOptions: SectionOptions[] = []; let count = 0; let oneOrTwo = 0; @@ -166,6 +183,8 @@ export struct CustomItemHeightPage { .layoutWeight(1) } } + // [EndExclude method_declare] } + // [End quick_start] \ No newline at end of file diff --git a/WaterFlowSample/entry/src/main/ets/pages/DataLoadMorePage.ets b/WaterFlowSample/entry/src/main/ets/pages/DataLoadMorePage.ets index a57960564289adbec073a538bc2715a27fed1ea3..b1b6abb552271031efdf1db8f228c3b4d8e6936b 100644 --- a/WaterFlowSample/entry/src/main/ets/pages/DataLoadMorePage.ets +++ b/WaterFlowSample/entry/src/main/ets/pages/DataLoadMorePage.ets @@ -1,6 +1,22 @@ +/* + * Copyright (c) 2025 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. + */ + // [Start quick_start] import { CommonConstants } from "../common/constants/CommonConstants"; import { SectionsWaterFlowDataSource } from "../model/SectionsWaterFlowDataSource"; + // [StartExclude flow_item_layout] @Reusable struct ReusableFlowItem { @@ -61,6 +77,7 @@ struct ReusableFlowItem { .backgroundColor(Color.Gray) } } + // [EndExclude flow_item_layout] @Entry @Component @@ -120,7 +137,7 @@ struct DataLoadMorePage { .justifyContent(FlexAlign.Center) } - refresh() { + refresh(): void { this.currentItem = -1; setTimeout(() => { // Add new data. @@ -144,18 +161,18 @@ struct DataLoadMorePage { }, 2000); } - getSize() { + getSize(): number { let ret = Math.floor(Math.random() * this.maxSize); return (ret > this.minSize ? ret : this.minSize); } - setItemSizeArray() { + setItemSizeArray(): void { for (let i = 0; i < 100; i++) { this.itemHeightArray.push(this.getSize()); } } - initSections() { + initSections(): void { let sectionOptions: SectionOptions[] = []; let count = 0; let oneOrTwo = 0; @@ -184,7 +201,7 @@ struct DataLoadMorePage { let newSection: SectionOptions; let tmpIndex = 0; let sectionIndex = 0; - for(let i = 0; i < sections.length; i++) { + for (let i = 0; i < sections.length; i++) { tmpIndex += sections[i].itemsCount; if (index < tmpIndex) { sectionIndex = i; @@ -203,16 +220,17 @@ struct DataLoadMorePage { this.setItemSizeArray(); this.initSections(); } + // [EndExclude variable_declare] build() { Column({ space: 0 }) { - Refresh({ refreshing: $$this.isRefreshing, builder: this.headerRefresh()}) { + Refresh({ refreshing: $$this.isRefreshing, builder: this.headerRefresh() }) { WaterFlow({ scroller: this.scroller, sections: this.sections }) { // [StartExclude water_flow_data] LazyForEach(this.dataSource, (item: number) => { FlowItem() { Stack() { - Row(){ + Row() { Button('Delete') .fontColor(Color.Red) .backgroundColor(Color.White) @@ -229,6 +247,7 @@ struct DataLoadMorePage { .zIndex(1) .visibility(this.currentItem === item ? Visibility.Visible : Visibility.Hidden) .backgroundColor('#33000000') + ReusableFlowItem({ item: item }) } } @@ -270,6 +289,7 @@ struct DataLoadMorePage { .onRefreshing(() => { this.refresh(); }) + // [EndExclude refresh] } .padding({ @@ -277,4 +297,5 @@ struct DataLoadMorePage { }) } } + // [End quick_start] \ No newline at end of file diff --git a/WaterFlowSample/entry/src/main/ets/pages/DataUpadteAndAnimationPage.ets b/WaterFlowSample/entry/src/main/ets/pages/DataUpadteAndAnimationPage.ets index 577a7a7e3b9931f22fe6e24de698abe7966f1417..8f822627f5b98f9aeee2fe3348d9bcfee0a68e86 100644 --- a/WaterFlowSample/entry/src/main/ets/pages/DataUpadteAndAnimationPage.ets +++ b/WaterFlowSample/entry/src/main/ets/pages/DataUpadteAndAnimationPage.ets @@ -1,6 +1,22 @@ +/* + * Copyright (c) 2025 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. + */ + // [Start quick_start] import { CommonConstants } from "../common/constants/CommonConstants"; import { SectionsWaterFlowDataSource } from "../model/SectionsWaterFlowDataSource"; + // [StartExclude flow_item_layout] @Reusable struct ReusableFlowItem { @@ -58,6 +74,7 @@ struct ReusableFlowItem { .backgroundColor(Color.Gray) } } + // [EndExclude flow_item_layout] @Entry @Component @@ -72,7 +89,6 @@ struct DataUpadteAndAnimationPage { private itemHeightArray: number[] = []; @State sections: WaterFlowSections = new WaterFlowSections(); @StorageProp(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT) statusBarHeight: number = 0; - sectionMargin: Margin = { top: 8, left: 16, @@ -105,6 +121,7 @@ struct DataUpadteAndAnimationPage { return this.itemHeightArray[index % 100]; } }; + // [EndExclude variable_declare] // 1、Refresh Loading Animation Component. @Builder @@ -120,7 +137,7 @@ struct DataUpadteAndAnimationPage { } // 5、Pull down to refresh the data update logic. - refresh() { + refresh(): void { this.currentItem = -1; setTimeout(() => { // Add new data. @@ -144,7 +161,7 @@ struct DataUpadteAndAnimationPage { }, 2000); } - loadMore(last: number) { + loadMore(last: number): void { setTimeout(() => { let totalCount = this.dataSource.totalCount(); if (last + 20 >= totalCount) { @@ -157,19 +174,20 @@ struct DataUpadteAndAnimationPage { } }, 1000); } + // [StartExclude section_init] - getSize() { + getSize(): number { let ret = Math.floor(Math.random() * this.maxSize); return (ret > this.minSize ? ret : this.minSize); } - setItemSizeArray() { + setItemSizeArray(): void { for (let i = 0; i < 100; i++) { this.itemHeightArray.push(this.getSize()); } } - initSections() { + initSections(): void { let sectionOptions: SectionOptions[] = []; let count = 0; let oneOrTwo = 0; @@ -198,7 +216,7 @@ struct DataUpadteAndAnimationPage { let newSection: SectionOptions; let tmpIndex = 0; let sectionIndex = 0; - for(let i = 0; i < sections.length; i++) { + for (let i = 0; i < sections.length; i++) { tmpIndex += sections[i].itemsCount; if (index < tmpIndex) { sectionIndex = i; @@ -217,6 +235,7 @@ struct DataUpadteAndAnimationPage { this.setItemSizeArray(); this.initSections(); } + // [EndExclude section_init] build() { Column({ space: 0 }) { @@ -225,16 +244,17 @@ struct DataUpadteAndAnimationPage { .width('100%') .fontSize(24) .fontWeight(FontWeight.Bold) - .margin({ top: '18vp', left: '16vp', bottom: '8vp'}) + .margin({ top: '18vp', left: '16vp', bottom: '8vp' }) } + // 2、Pull-to-refresh control. - Refresh({ refreshing: $$this.isRefreshing, builder: this.headerRefresh()}) { + Refresh({ refreshing: $$this.isRefreshing, builder: this.headerRefresh() }) { // [StartExclude water_flow_init] WaterFlow({ scroller: this.scroller, sections: this.sections }) { LazyForEach(this.dataSource, (item: number) => { FlowItem() { Stack() { - Row(){ + Row() { Button('Delete') .fontColor(Color.Red) .backgroundColor(Color.White) @@ -251,6 +271,7 @@ struct DataUpadteAndAnimationPage { .zIndex(1) .visibility(this.currentItem === item ? Visibility.Visible : Visibility.Hidden) .backgroundColor('#33000000') + ReusableFlowItem({ item: item }) } } @@ -288,4 +309,5 @@ struct DataUpadteAndAnimationPage { }) } } + // [End quick_start] \ No newline at end of file diff --git a/WaterFlowSample/entry/src/main/ets/pages/ElementByOrderPage.ets b/WaterFlowSample/entry/src/main/ets/pages/ElementByOrderPage.ets index 2cabc98ac2587f4bb44efd248146287b16b2992c..cb533a3cf0ccc9237b80c22541d1d4fc0b13a3f5 100644 --- a/WaterFlowSample/entry/src/main/ets/pages/ElementByOrderPage.ets +++ b/WaterFlowSample/entry/src/main/ets/pages/ElementByOrderPage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2025 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 { CommonConstants } from '../common/constants/CommonConstants'; @Entry @@ -19,7 +34,7 @@ struct ElementByOrderPage { ForEach(this.data1, (item: string) => { if (item === '1') { Text('item' + item + - this.getUIContext().getHostContext()?.resourceManager.getStringSync($r('app.string.item_height')) + ':' + + this.getUIContext().getHostContext()?.resourceManager.getStringSync($r('app.string.item_height').id) + ':' + this.getHeight(item).toString()) .id('item' + item) .alignRules({ @@ -31,7 +46,7 @@ struct ElementByOrderPage { .backgroundColor(this.colors[Number(item) - 1]) } else if (item === '2') { Text('item' + item + - this.getUIContext().getHostContext()?.resourceManager.getStringSync($r('app.string.item_height')) + ':' + + this.getUIContext().getHostContext()?.resourceManager.getStringSync($r('app.string.item_height').id) + ':' + this.getHeight(item).toString()) .id('item' + item) .alignRules({ @@ -43,7 +58,7 @@ struct ElementByOrderPage { .backgroundColor(this.colors[Number(item) - 1]) } else { Text('item' + item + - this.getUIContext().getHostContext()?.resourceManager.getStringSync($r('app.string.item_height')) + ':' + + this.getUIContext().getHostContext()?.resourceManager.getStringSync($r('app.string.item_height').id) + ':' + this.getHeight(item).toString()) .id('item' + item) .alignRules({ diff --git a/WaterFlowSample/entry/src/main/ets/pages/FadingEdgePage.ets b/WaterFlowSample/entry/src/main/ets/pages/FadingEdgePage.ets index 6826eed28022d40f46a9e14e984ed7b2f6373324..585ceced26486ccf1b0f6ea241157d30a28125a6 100644 --- a/WaterFlowSample/entry/src/main/ets/pages/FadingEdgePage.ets +++ b/WaterFlowSample/entry/src/main/ets/pages/FadingEdgePage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2025 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. + */ + // [Start quick_start] import { CommonConstants } from "../common/constants/CommonConstants"; import { SectionsWaterFlowDataSource } from "../model/SectionsWaterFlowDataSource"; @@ -8,7 +23,7 @@ import { LengthMetrics } from '@kit.ArkUI'; struct ReusableFlowItem { @State item: number = 0; - aboutToReuse(params: Record) { + aboutToReuse(params: Record): void { this.item = params.item; } @@ -60,6 +75,7 @@ struct ReusableFlowItem { .backgroundColor(Color.Gray) } } + // [EndExclude flow_item_layout] @Entry @Component @@ -80,7 +96,6 @@ struct FadingEdgePage { // 1、Create group information. @State sections: WaterFlowSections = new WaterFlowSections(); @StorageProp(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT) statusBarHeight: number = 0; - // 2、Create the first group. oneColumnSection: SectionOptions = { itemsCount: 3, @@ -110,16 +125,17 @@ struct FadingEdgePage { } // [StartExclude method_declare] - getSize() { + getSize(): number { let ret = Math.floor(Math.random() * this.maxSize); return (ret > this.minSize ? ret : this.minSize); } - setItemSizeArray() { + setItemSizeArray(): void { for (let i = 0; i < 100; i++) { this.itemHeightArray.push(this.getSize()); } } + // [EndExclude method_declare] aboutToAppear() { @@ -128,7 +144,7 @@ struct FadingEdgePage { } // 5、Initialise group data. - initSections() { + initSections(): void { let sectionOptions: SectionOptions[] = []; let count = 0; let oneOrTwo = 0; @@ -157,8 +173,9 @@ struct FadingEdgePage { .width('100%') .fontSize(24) .fontWeight(FontWeight.Bold) - .margin({ top: '18vp', left: '16vp', bottom: '8vp'}) + .margin({ top: '18vp', left: '16vp', bottom: '8vp' }) } + // 6、Link the grouping information to WaterFlow. WaterFlow({ scroller: this.scroller, sections: this.sections }) { // [StartExclude water_flow_data] @@ -179,11 +196,12 @@ struct FadingEdgePage { .height('100%') .layoutWeight(1) .scrollBar(BarState.On) - .fadingEdge(true, { fadingEdgeLength: LengthMetrics.vp(80)}) + .fadingEdge(true, { fadingEdgeLength: LengthMetrics.vp(80) }) } .padding({ top: this.statusBarHeight }) } } + // [End quick_start] \ No newline at end of file diff --git a/WaterFlowSample/entry/src/main/ets/pages/FlowItemAutoPlayPage.ets b/WaterFlowSample/entry/src/main/ets/pages/FlowItemAutoPlayPage.ets index 6606e901a55fbe196c5c84ccfc6e087ad0e10937..56763280afb183ed00f5d0c434a4d7dd69b10835 100644 --- a/WaterFlowSample/entry/src/main/ets/pages/FlowItemAutoPlayPage.ets +++ b/WaterFlowSample/entry/src/main/ets/pages/FlowItemAutoPlayPage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2025 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. + */ + // [Start quick_start] import { hilog } from '@kit.PerformanceAnalysisKit'; import { CommonConstants } from '../common/constants/CommonConstants'; @@ -57,7 +72,8 @@ struct FlowVideoItem { }) .id('image') - Stack() {} + Stack() { + } .linearGradient({ angle: 0, colors: [['#80000000', 0.0], @@ -90,10 +106,12 @@ struct FlowVideoItem { .width('100%') .borderRadius(8) .backgroundColor(Color.Gray) + // [EndExclude image_item] } } } + // [StartExclude water_flow_init] @Entry @Component @@ -146,12 +164,12 @@ struct FlowItemAutoPlayPage { return result; } - getSize() { + getSize(): number { let ret = Math.floor(Math.random() * this.maxSize); return (ret > this.minSize ? ret : this.minSize); } - setItemSizeArray() { + setItemSizeArray(): void { for (let i = 0; i < 100; i++) { this.itemWidthArray.push(this.getSize()); this.itemHeightArray.push(this.getSize()); @@ -182,8 +200,9 @@ struct FlowItemAutoPlayPage { .width('100%') .fontSize(24) .fontWeight(FontWeight.Bold) - .margin({ top: '18vp', left: '16vp', bottom: '16vp'}) + .margin({ top: '18vp', left: '16vp', bottom: '16vp' }) } + WaterFlow({ scroller: this.scroller, sections: this.sections }) { LazyForEach(this.dataSource, (item: MediaItem) => { FlowItem() { @@ -207,5 +226,6 @@ struct FlowItemAutoPlayPage { }) } } + // [EndExclude water_flow_init] // [End quick_start] \ No newline at end of file diff --git a/WaterFlowSample/entry/src/main/ets/pages/FlowItemRmoveAnimationPage.ets b/WaterFlowSample/entry/src/main/ets/pages/FlowItemRmoveAnimationPage.ets index a38c698caf28360c310c52d10c3d7af734aab796..5d6b224ab706aa4f15b3a574c79c3de1aa540496 100644 --- a/WaterFlowSample/entry/src/main/ets/pages/FlowItemRmoveAnimationPage.ets +++ b/WaterFlowSample/entry/src/main/ets/pages/FlowItemRmoveAnimationPage.ets @@ -1,6 +1,22 @@ +/* + * Copyright (c) 2025 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. + */ + // [Start quick_start] import { CommonConstants } from "../common/constants/CommonConstants"; import { SectionsWaterFlowDataSource } from "../model/SectionsWaterFlowDataSource"; + // [StartExclude flow_item_layout] @Reusable struct ReusableFlowItem { @@ -58,6 +74,7 @@ struct ReusableFlowItem { .backgroundColor(Color.Gray) } } + // [EndExclude flow_item_layout] @Entry @Component @@ -117,7 +134,7 @@ struct FlowItemRmoveAnimationPage { .justifyContent(FlexAlign.Center) } - refresh() { + refresh(): void { this.currentItem = -1; setTimeout(() => { // Add new data. @@ -141,18 +158,18 @@ struct FlowItemRmoveAnimationPage { }, 2000); } - getSize() { + getSize(): number { let ret = Math.floor(Math.random() * this.maxSize); return (ret > this.minSize ? ret : this.minSize); } - setItemSizeArray() { + setItemSizeArray(): void { for (let i = 0; i < 100; i++) { this.itemHeightArray.push(this.getSize()); } } - initSections() { + initSections(): void { let sectionOptions: SectionOptions[] = []; let count = 0; let oneOrTwo = 0; @@ -186,7 +203,7 @@ struct FlowItemRmoveAnimationPage { let newSection: SectionOptions; let tmpIndex = 0; let sectionIndex = 0; - for(let i = 0; i < sections.length; i++) { + for (let i = 0; i < sections.length; i++) { tmpIndex += sections[i].itemsCount; if (index < tmpIndex) { sectionIndex = i; @@ -200,15 +217,16 @@ struct FlowItemRmoveAnimationPage { } this.sections.update(sectionIndex, newSection); } + // [EndExclude variable_declare] build() { Column({ space: 0 }) { - Refresh({ refreshing: $$this.isRefreshing, builder: this.headerRefresh()}) { + Refresh({ refreshing: $$this.isRefreshing, builder: this.headerRefresh() }) { WaterFlow({ scroller: this.scroller, sections: this.sections }) { LazyForEach(this.dataSource, (item: number) => { FlowItem() { Stack() { - Row(){ + Row() { Button($r('app.string.delete')) .fontColor(Color.Red) .backgroundColor(Color.White) @@ -227,6 +245,7 @@ struct FlowItemRmoveAnimationPage { .zIndex(1) .visibility(this.currentItem === item ? Visibility.Visible : Visibility.Hidden) .backgroundColor('#33000000') + ReusableFlowItem({ item: item }) // [EndExclude row_setting] } @@ -263,6 +282,7 @@ struct FlowItemRmoveAnimationPage { } }, 1000); }) + // [EndExclude water_flow_setting] } // [StartExclude water_flow_refresh] @@ -270,6 +290,7 @@ struct FlowItemRmoveAnimationPage { .onRefreshing(() => { this.refresh(); }) + // [EndExclude water_flow_refresh] } .padding({ @@ -277,4 +298,5 @@ struct FlowItemRmoveAnimationPage { }) } } + // [End quick_start] \ No newline at end of file diff --git a/WaterFlowSample/entry/src/main/ets/pages/FlowItemRmovePage.ets b/WaterFlowSample/entry/src/main/ets/pages/FlowItemRmovePage.ets index 870d96ac3ccd58e056f0f8642d07a0d81a9578e9..ea2e70b28c6d275765828d08d1ff87f76048567b 100644 --- a/WaterFlowSample/entry/src/main/ets/pages/FlowItemRmovePage.ets +++ b/WaterFlowSample/entry/src/main/ets/pages/FlowItemRmovePage.ets @@ -1,5 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + // [Start quick_start] import { SectionsWaterFlowDataSource } from "../model/SectionsWaterFlowDataSource"; + // [StartExclude flow_item_layout] @Reusable struct ReusableFlowItem { @@ -57,13 +73,13 @@ struct ReusableFlowItem { .backgroundColor(Color.Gray) } } + // [EndExclude flow_item_layout] @Entry @Component struct FlowItemRmoveAnimationPage { // 1、Select the index of the FlowItem. @State currentItem: number = -1; - // [StartExclude variable_declare] @State isRefreshing: boolean = false; @State minSize: number = 80; @@ -117,7 +133,7 @@ struct FlowItemRmoveAnimationPage { .justifyContent(FlexAlign.Center) } - refresh() { + refresh(): void { this.currentItem = -1; setTimeout(() => { // Add new data. @@ -141,18 +157,18 @@ struct FlowItemRmoveAnimationPage { }, 2000); } - getSize() { + getSize(): number { let ret = Math.floor(Math.random() * this.maxSize); return (ret > this.minSize ? ret : this.minSize); } - setItemSizeArray() { + setItemSizeArray(): void { for (let i = 0; i < 100; i++) { this.itemHeightArray.push(this.getSize()); } } - initSections() { + initSections(): void { let sectionOptions: SectionOptions[] = []; let count = 0; let oneOrTwo = 0; @@ -178,6 +194,7 @@ struct FlowItemRmoveAnimationPage { this.setItemSizeArray(); this.initSections(); } + // [EndExclude variable_declare] removeItem(item: number): void { // 5、Delete source data. @@ -188,7 +205,7 @@ struct FlowItemRmoveAnimationPage { let newSection: SectionOptions; let tmpIndex = 0; let sectionIndex = 0; - for(let i = 0; i < sections.length; i++) { + for (let i = 0; i < sections.length; i++) { tmpIndex += sections[i].itemsCount; if (index < tmpIndex) { sectionIndex = i; @@ -205,13 +222,13 @@ struct FlowItemRmoveAnimationPage { build() { Column({ space: 0 }) { - Refresh({ refreshing: $$this.isRefreshing, builder: this.headerRefresh()}) { + Refresh({ refreshing: $$this.isRefreshing, builder: this.headerRefresh() }) { WaterFlow({ scroller: this.scroller, sections: this.sections }) { LazyForEach(this.dataSource, (item: number) => { FlowItem() { Stack() { // 3、Delete button. - Row(){ + Row() { Button('Delete') .fontColor(Color.Red) .backgroundColor(Color.White) @@ -229,6 +246,7 @@ struct FlowItemRmoveAnimationPage { .zIndex(1) .visibility(this.currentItem === item ? Visibility.Visible : Visibility.Hidden) .backgroundColor('#33000000') + ReusableFlowItem({ item: item }) } } @@ -269,8 +287,10 @@ struct FlowItemRmoveAnimationPage { .onRefreshing(() => { this.refresh(); }) + // [EndExclude water_flow_setting] } } } + // [End quick_start] \ No newline at end of file diff --git a/WaterFlowSample/entry/src/main/ets/pages/ForceShowOnTopLeftPage.ets b/WaterFlowSample/entry/src/main/ets/pages/ForceShowOnTopLeftPage.ets index a711b3684a3eda7ea6419f13ee5dc3fd4bfbd6b7..712b2c13f47b8e18069293f13b4a30a9fa552723 100644 --- a/WaterFlowSample/entry/src/main/ets/pages/ForceShowOnTopLeftPage.ets +++ b/WaterFlowSample/entry/src/main/ets/pages/ForceShowOnTopLeftPage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2025 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. + */ + // [Start quick_start] import { CommonConstants } from '../common/constants/CommonConstants'; import { MyDataSource } from '../model/MyDataSource' @@ -10,20 +25,22 @@ struct ForceShowOnTopLeftPage { @StorageProp(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT) statusBarHeight: number = 0; aboutToAppear(): void { - for(let i = 0; i < 80; i++) { + for (let i = 0; i < 80; i++) { this.data.pushData(i); } } + // [EndExclude data_init] build() { - Column({ space: 0}) { + Column({ space: 0 }) { Row() { Text($r('app.string.force_left_show')) .width('100%') .fontSize(24) .fontWeight(FontWeight.Bold) - .margin({ top: '18vp', left: '16vp', bottom: '16vp'}) + .margin({ top: '18vp', left: '16vp', bottom: '16vp' }) } + WaterFlow() { // 1、Add the layout content in the top left corner of WaterFlow. FlowItem() { @@ -71,4 +88,5 @@ struct ForceShowOnTopLeftPage { }) } } + // [End quick_start] \ No newline at end of file diff --git a/WaterFlowSample/entry/src/main/ets/pages/Index.ets b/WaterFlowSample/entry/src/main/ets/pages/Index.ets index 05cb67b498c78deec8fc9cdb72f675b40cb43ec5..e92c93015bfa71c6557aad7bba0649971aecbfa7 100644 --- a/WaterFlowSample/entry/src/main/ets/pages/Index.ets +++ b/WaterFlowSample/entry/src/main/ets/pages/Index.ets @@ -13,7 +13,6 @@ * limitations under the License. */ - @Entry @Component struct Index { diff --git a/WaterFlowSample/entry/src/main/ets/pages/MergeDoubleWaterFlowPage.ets b/WaterFlowSample/entry/src/main/ets/pages/MergeDoubleWaterFlowPage.ets index 54cb0e868ace2c6bc8e8eaab34a577304ea197c7..0a107c8de9033cc14a612d3865e00e5a4f4035c1 100644 --- a/WaterFlowSample/entry/src/main/ets/pages/MergeDoubleWaterFlowPage.ets +++ b/WaterFlowSample/entry/src/main/ets/pages/MergeDoubleWaterFlowPage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2025 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. + */ + // [Start quick_start] import { CommonConstants } from '../common/constants/CommonConstants'; import { MyDataSource } from '../model/MyDataSource' @@ -48,19 +63,19 @@ struct MergeDoubleWaterFlowPage { } }; - getSize() { + getSize(): number { let ret = Math.floor(Math.random() * this.maxSize); return (ret > this.minSize ? ret : this.minSize); } - setItemSizeArray() { + setItemSizeArray(): void { for (let i = 0; i < 100; i++) { this.itemHeightArray.push(this.getSize()); } } aboutToAppear(): void { - for(let i = 0; i < 100; i++) { + for (let i = 0; i < 100; i++) { this.data.pushData(i); } this.setItemSizeArray(); @@ -70,6 +85,7 @@ struct MergeDoubleWaterFlowPage { sectionOptions.push(this.lastSection); this.sections.splice(0, 0, sectionOptions); } + // [EndExclude data_init] build() { Column({ space: 2 }) { @@ -78,8 +94,9 @@ struct MergeDoubleWaterFlowPage { .width('100%') .fontSize(24) .fontWeight(FontWeight.Bold) - .margin({ top: '18vp', left: '16vp', bottom: '12vp'}) + .margin({ top: '18vp', left: '16vp', bottom: '12vp' }) } + WaterFlow({ scroller: this.scroller, sections: this.sections }) { LazyForEach(this.data, (item: number) => { FlowItem() { @@ -121,4 +138,5 @@ struct MergeDoubleWaterFlowPage { .backgroundColor('#efefef') } } + // [End quick_start] \ No newline at end of file diff --git a/WaterFlowSample/entry/src/main/ets/pages/SectionOptionsUsePage.ets b/WaterFlowSample/entry/src/main/ets/pages/SectionOptionsUsePage.ets index 12137c6a9b0c6a03773193d7f7707497f049cfab..0200f6c85d565ab03c0405ccdfb4906d1268eff9 100644 --- a/WaterFlowSample/entry/src/main/ets/pages/SectionOptionsUsePage.ets +++ b/WaterFlowSample/entry/src/main/ets/pages/SectionOptionsUsePage.ets @@ -1,6 +1,22 @@ +/* + * Copyright (c) 2025 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. + */ + // [Start quick_start] import { CommonConstants } from "../common/constants/CommonConstants"; import { SectionsWaterFlowDataSource } from "../model/SectionsWaterFlowDataSource"; + // [StartExclude flow_item_layout] @Reusable struct ReusableFlowItem { @@ -58,6 +74,7 @@ struct ReusableFlowItem { .backgroundColor(Color.Gray) } } + // [EndExclude flow_item_layout] @Entry @Component @@ -78,7 +95,6 @@ struct SectionOptionsUsePage { // 1、Create group information. @State sections: WaterFlowSections = new WaterFlowSections(); @StorageProp(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT) statusBarHeight: number = 0; - // 2、Create the first group. oneColumnSection: SectionOptions = { itemsCount: 3, @@ -108,16 +124,17 @@ struct SectionOptionsUsePage { } // [StartExclude method_declare] - getSize() { + getSize(): number { let ret = Math.floor(Math.random() * this.maxSize); return (ret > this.minSize ? ret : this.minSize); } - setItemSizeArray() { + setItemSizeArray(): void { for (let i = 0; i < 100; i++) { this.itemHeightArray.push(this.getSize()); } } + // [EndExclude method_declare] aboutToAppear() { @@ -126,7 +143,7 @@ struct SectionOptionsUsePage { } // 5、Initialise group data. - initSections() { + initSections(): void { let sectionOptions: SectionOptions[] = []; let count = 0; let oneOrTwo = 0; @@ -155,8 +172,9 @@ struct SectionOptionsUsePage { .width('100%') .fontSize(24) .fontWeight(FontWeight.Bold) - .margin({ top: '18vp', left: '16vp', bottom: '8vp'}) + .margin({ top: '18vp', left: '16vp', bottom: '8vp' }) } + // 6、Link the grouping information to WaterFlow. WaterFlow({ scroller: this.scroller, sections: this.sections }) { // [StartExclude water_flow_data] @@ -182,4 +200,5 @@ struct SectionOptionsUsePage { }) } } + // [End quick_start] \ No newline at end of file diff --git a/WaterFlowSample/entry/src/main/ets/pages/StickOnTopPage.ets b/WaterFlowSample/entry/src/main/ets/pages/StickOnTopPage.ets index 929dc3ed021e6c46a994c83f774fde0ca501d89a..25149c30082dbf3ede824464f2ee2020b6db9724 100644 --- a/WaterFlowSample/entry/src/main/ets/pages/StickOnTopPage.ets +++ b/WaterFlowSample/entry/src/main/ets/pages/StickOnTopPage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2025 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. + */ + // [Start quick_start] import { hilog } from '@kit.PerformanceAnalysisKit'; import { CommonConstants } from '../common/constants/CommonConstants'; @@ -5,6 +20,7 @@ import MediaItem, { ItemType } from '../model/MediaItem'; import { StickyWaterFlowDataSource } from '../model/StickyWaterFlowDataSource'; const TAG = 'StickyPage'; + // [StartExclude item_layout] @Component struct FlowVideoItem { @@ -53,7 +69,8 @@ struct FlowVideoItem { right: { anchor: '__container__', align: HorizontalAlign.End } }) - Stack() {} + Stack() { + } .linearGradient({ angle: 0, colors: [['#80000000', 0.0], @@ -87,6 +104,7 @@ struct FlowVideoItem { } } } + // [EndExclude item_layout] @Component export struct StickyPage { @@ -132,6 +150,7 @@ export struct StickyPage { return 250; } }; + // [StartExclude section_init] getResourceStringArray(resource: Resource): Array { let result: Array = new Array(); @@ -143,12 +162,12 @@ export struct StickyPage { return result; } - getSize() { + getSize(): number { let ret = Math.floor(Math.random() * this.maxSize); return (ret > this.minSize ? ret : this.minSize); } - setItemSizeArray() { + setItemSizeArray(): void { for (let i = 0; i < 100; i++) { this.itemWidthArray.push(this.getSize()); this.itemHeightArray.push(this.getSize()); @@ -171,6 +190,7 @@ export struct StickyPage { } this.sections.splice(-1, 0, sectionOptions); } + // [EndExclude section_init] build() { Stack({ alignContent: Alignment.TopStart }) { @@ -319,6 +339,7 @@ export struct StickyPage { right: 16 }) }.alignItems(HorizontalAlign.Start) + // [EndExclude stick_content] } .width('100%') @@ -330,6 +351,7 @@ export struct StickyPage { } } } + // [StartExclude homepage] @Entry @Component @@ -436,5 +458,6 @@ struct StickOnTopPage { }) } } + // [EndExclude homepage] // [End quick_start] \ No newline at end of file diff --git a/WaterFlowSample/entry/src/main/ets/pages/ZoomChangeColumnPage.ets b/WaterFlowSample/entry/src/main/ets/pages/ZoomChangeColumnPage.ets index aef08e29a5960703e399e72674ee5a12ffbca878..3214e0e2eac5d4d0cf030ac942b3e6cf099206b0 100644 --- a/WaterFlowSample/entry/src/main/ets/pages/ZoomChangeColumnPage.ets +++ b/WaterFlowSample/entry/src/main/ets/pages/ZoomChangeColumnPage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2025 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. + */ + // [Start quick_start] import { MyDataSource } from '../model/MyDataSource' import { image } from '@kit.ImageKit'; @@ -26,6 +41,7 @@ struct ReusableItem { } } } + // [EndExclude flow_item] @Entry @Component @@ -53,12 +69,12 @@ struct ZoomChangeColumnPage { private oldColumn: number = this.columns; // [StartExclude section_init] - getSize() { + getSize(): number { let ret = Math.floor(Math.random() * this.maxSize); return (ret > this.minSize ? ret : this.minSize); } - setItemSizeArray() { + setItemSizeArray(): void { for (let i = 0; i < 100; i++) { this.itemWidthArray.push(this.getSize()); this.itemHeightArray.push(this.getSize()); @@ -66,7 +82,7 @@ struct ZoomChangeColumnPage { } aboutToAppear(): void { - for(let i = 0; i < 100; i++) { + for (let i = 0; i < 100; i++) { this.data.pushData(i); } let lastCount = AppStorage.get('columnsCount'); @@ -75,9 +91,10 @@ struct ZoomChangeColumnPage { } this.setItemSizeArray(); } + // [EndExclude section_init] // 7、Adjust the number of columns according to the zoom ratio. - changeColumns(scale: number) { + changeColumns(scale: number): void { this.oldColumn = this.columns; if (scale > (this.columns / (this.columns - 0.5))) { this.columns--; @@ -99,6 +116,7 @@ struct ZoomChangeColumnPage { .fontWeight(FontWeight.Bold) .margin({ top: '18vp', left: '16vp', bottom: '16vp' }) } + // [EndExclude title] Stack() { // 2、Display the current screen's snapshot when zooming. @@ -198,4 +216,5 @@ struct ZoomChangeColumnPage { }) } } + // [End quick_start] \ No newline at end of file diff --git a/WaterFlowSample/entry/src/main/ets/utils/WindowUtil.ets b/WaterFlowSample/entry/src/main/ets/utils/WindowUtil.ets index f711a36ffc3fafdae96e1180d00f6e3939a568af..4034146b1cc7ca1bc00399a06c1dec931ecfe5cf 100644 --- a/WaterFlowSample/entry/src/main/ets/utils/WindowUtil.ets +++ b/WaterFlowSample/entry/src/main/ets/utils/WindowUtil.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2025 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 @@ -55,19 +55,27 @@ export class WindowUtil { } private static updateAvoidArea(windowObj: window.Window) { - WindowUtil.setAvoidArea(window.AvoidAreaType.TYPE_SYSTEM, - windowObj.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM)); - WindowUtil.setAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR, - windowObj.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR)); + try { + WindowUtil.setAvoidArea(window.AvoidAreaType.TYPE_SYSTEM, + windowObj.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM)); + WindowUtil.setAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR, + windowObj.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR)); + } catch (err) { + hilog.error(0x0000, 'testTag', 'getWindowAvoidArea get exception. Cause: %{public}s', JSON.stringify(err) ?? ''); + } } // Get status bar height and indicator height. private static setAvoidArea(type: window.AvoidAreaType, area: window.AvoidArea) { - let uiContext = WindowUtil.windowClass.getUIContext(); - if (type === window.AvoidAreaType.TYPE_SYSTEM) { - AppStorage.setOrCreate(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT, uiContext.px2vp(area.topRect.height)); - } else if (type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { - AppStorage.setOrCreate(CommonConstants.AS_KEY_NAVIGATOR_BAR_HEIGHT, uiContext.px2vp(area.bottomRect.height)); + try { + let uiContext = WindowUtil.windowClass.getUIContext(); + if (type === window.AvoidAreaType.TYPE_SYSTEM) { + AppStorage.setOrCreate(CommonConstants.AS_KEY_STATUS_BAR_HEIGHT, uiContext.px2vp(area.topRect.height)); + } else if (type === window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR) { + AppStorage.setOrCreate(CommonConstants.AS_KEY_NAVIGATOR_BAR_HEIGHT, uiContext.px2vp(area.bottomRect.height)); + } + } catch (err) { + hilog.error(0x0000, 'testTag', 'getUIContext get exception. Cause: %{public}s', JSON.stringify(err) ?? ''); } } } \ No newline at end of file diff --git a/WaterFlowSample/entry/src/main/module.json5 b/WaterFlowSample/entry/src/main/module.json5 index f88d84078c34c62b0352f3cbf10e398bb619b10e..3b66f73597f73a92a458d254d6451caa006acb27 100644 --- a/WaterFlowSample/entry/src/main/module.json5 +++ b/WaterFlowSample/entry/src/main/module.json5 @@ -5,10 +5,7 @@ "description": "$string:module_desc", "mainElement": "EntryAbility", "deviceTypes": [ - "phone", - "tablet", - "2in1", - "wearable" + "phone" ], "deliveryWithInstall": true, "installationFree": false,