diff --git a/ComponentReuse/AppScope/app.json5 b/ComponentReuse/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4e246fb31127fdca21d21cc450a0a7df4a9712f5 --- /dev/null +++ b/ComponentReuse/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.componentreuse", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/ComponentReuse/AppScope/resources/base/element/string.json b/ComponentReuse/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ec56da8554feed8b1d65b4150ddc674268924840 --- /dev/null +++ b/ComponentReuse/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ComponentReuse" + } + ] +} diff --git a/ComponentReuse/AppScope/resources/base/media/app_icon.png b/ComponentReuse/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/ComponentReuse/AppScope/resources/base/media/app_icon.png differ diff --git a/ComponentReuse/LICENSE b/ComponentReuse/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..338e5b0bc22082e0ffcc7121c2ed3897a3ddccb0 --- /dev/null +++ b/ComponentReuse/LICENSE @@ -0,0 +1,78 @@ + Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +Apache License, Version 2.0 +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: +1.You must give any other recipients of the Work or Derivative Works a copy of this License; and +2.You must cause any modified files to carry prominent notices stating that You changed the files; and +3.You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and +4.If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + +You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/ComponentReuse/README.md b/ComponentReuse/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8764b757d2ecd1c76030d04365a9090e032c447e --- /dev/null +++ b/ComponentReuse/README.md @@ -0,0 +1,68 @@ +# 基于组件复用实现应用界面优化 + +### 介绍 + +HarmonyOS应用框架提供了组件复用能力:可复用组件树上移除时,会进入一个回收缓存区,后续创建新组件节点时,会复用缓存区中的节点,节约组件重新创建的时间。 +本工程配套官网[组件复用最佳实践](https://developer.huawei.com/consumer/cn/doc/best-practices-V5/bpta-component-reuse-V5), +文章介绍如何使用组件复用机制提升应用帧率。 + +### 预览效果 + +| 减少组件复用的嵌套层级 | 精准控制组件刷新范围 | +|-----------------------------------------|-----------------------------------------| +| ![image](screenshots/device/mode_1.gif) | ![image](screenshots/device/mode_2.gif) | + +| 使用reuseId标记不同的组件 | 复用组件采用@State变量入参 | +|-----------------------------------------|-----------------------------------------| +| ![image](screenshots/device/mode_3.gif) | ![image](screenshots/device/mode_4.gif) | + +#### 使用说明 + +1. 点击“减少组件复用的嵌套层级”按钮,进入二级页面“附近的人”, 滑动列表。 +2. 点击“精准控制组件刷新范围”按钮,进入二级页面“附近的人”, 滑动列表。 +3. 点击“使用reuseId标记不同的组件”按钮,进入二级页面“附近的人”, 滑动列表。 +4. 点击“复用组件创建时的@State变量入参”按钮,进入二级页面“附近的人”, 滑动列表。 + +## 工程目录 + +``` +├──entry/src/main/ets +│ ├──common +│ │ ├──Constants.ets // 公共常量 +│ │ └──GlobalBuilderContext.ets // 缓存全局@Builder +│ ├──entryability +│ │ └──EntryAbility.ets // 程序入口类 +│ ├──entrybackupability +│ │ └──EntryBackupAbility.ets // 自定义应用数据转换和迁移模板类 +│ ├──model +│ │ ├──BasicDataSource.ets // 数据适配器基类 +│ │ ├──ColorData.ets // 二级页面“文字列表”的数据适配器 +│ │ └──FriendMomentData.ets // 二级页面“附近的人”/“图文列表”/“网名列表”的数据适配器 +│ ├──pages.ets +│ │ └──Index.ets // 首页 +│ └──view +│ ├──OneMoment.ets // 二级页面“附近的人”中列表的每条item UI +│ ├──PageListSlideToHistory.ets // 二级页面“附近的人”UI +│ ├──UpdaterComponent.ets // 二级页面“文字列表”UI +│ ├──WithFuncParam.ets // 二级页面“网名列表”UI +│ └──WithReuseId.ets // 二级页面“图文列表”UI +└──entry/src/main/resources // 应用资源目录 +``` + +### 具体实现 + +1. [组件复用原理介绍](https://developer.huawei.com/consumer/cn/doc/best-practices-V5/bpta-component-reuse-V5#section142448345398) +2. [组件复用使用规则](https://developer.huawei.com/consumer/cn/doc/best-practices-V5/bpta-component-reuse-V5#section5923195311402) +3. [组件复用优化方法](https://developer.huawei.com/consumer/cn/doc/best-practices-V5/bpta-component-reuse-V5#section937434455716) +4. [组件复用失效场景](https://developer.huawei.com/consumer/cn/doc/best-practices-V5/bpta-component-reuse-V5#section1556917819517) + +### 相关权限 + +不涉及 + +## 约束与限制 + +* 本示例仅支持标准系统上运行,支持设备:华为手机。 +* HarmonyOS系统:HarmonyOS 5.0.0 Release及以上。 +* DevEco Studio版本:DevEco Studio 5.0.0 Release及以上。 +* HarmonyOS SDK版本:HarmonyOS 5.0.0 Release SDK及以上。 \ No newline at end of file diff --git a/ComponentReuse/build-profile.json5 b/ComponentReuse/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..90a9741e1b74bdafe09b7e6574aa2a84ee331425 --- /dev/null +++ b/ComponentReuse/build-profile.json5 @@ -0,0 +1,40 @@ +{ + "app": { + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.0(12)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug" + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ComponentReuse/entry/build-profile.json5 b/ComponentReuse/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4d611879c7913fb0610c686e2399258ab3a6dad1 --- /dev/null +++ b/ComponentReuse/entry/build-profile.json5 @@ -0,0 +1,28 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ComponentReuse/entry/hvigorfile.ts b/ComponentReuse/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- /dev/null +++ b/ComponentReuse/entry/hvigorfile.ts @@ -0,0 +1,6 @@ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ComponentReuse/entry/obfuscation-rules.txt b/ComponentReuse/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ComponentReuse/entry/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/ComponentReuse/entry/oh-package.json5 b/ComponentReuse/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..248c3b7541a589682a250f86a6d3ecf7414d2d6a --- /dev/null +++ b/ComponentReuse/entry/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ComponentReuse/entry/src/main/ets/common/Constants.ets b/ComponentReuse/entry/src/main/ets/common/Constants.ets new file mode 100644 index 0000000000000000000000000000000000000000..4d9031648e10555caf423380d120dfdbbe43625d --- /dev/null +++ b/ComponentReuse/entry/src/main/ets/common/Constants.ets @@ -0,0 +1,75 @@ +/* +* 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 { NavDestinationItem } from '../pages/Index'; + +/** + * Common constants for all features + */ +export class Constants { + + /** + * Default List Interval. + */ + public static readonly LIST_SPACE: number = 12; + + /** + * Maximum width. + */ + public static readonly LAYOUT_MAX: string = '100%'; + + /** + * Common initialization. + */ + public static readonly COMM_INIT: number = 0; + + /** + * NavDestination item0. + */ + public static readonly NAV_DESTINATION_ITEM_0: string = 'NavDestination_item_0'; + + /** + * NavDestination item1. + */ + public static readonly NAV_DESTINATION_ITEM_1: string = 'NavDestination_item_1'; + + /** + * NavDestination item2. + */ + public static readonly NAV_DESTINATION_ITEM_2: string = 'NavDestination_item_2'; + + /** + * NavDestination item3. + */ + public static readonly NAV_DESTINATION_ITEM_3: string = 'NavDestination_item_3'; + + /** + * NavDestinationItem + */ + public static readonly NavDestinationData: NavDestinationItem[] = [ + { + id: Constants.NAV_DESTINATION_ITEM_0, detail: $r('app.string.nav_destination_item0') + }, + { + id: Constants.NAV_DESTINATION_ITEM_1, detail: $r('app.string.nav_destination_item1') + }, + { + id: Constants.NAV_DESTINATION_ITEM_2, detail: $r('app.string.nav_destination_item2') + }, + { + id: Constants.NAV_DESTINATION_ITEM_3, detail: $r('app.string.nav_destination_item3') + }, + ]; +} \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/ets/common/GlobalBuilderContext.ets b/ComponentReuse/entry/src/main/ets/common/GlobalBuilderContext.ets new file mode 100644 index 0000000000000000000000000000000000000000..97e06e5dc114bf08521f2430e1a76ae1c87172c9 --- /dev/null +++ b/ComponentReuse/entry/src/main/ets/common/GlobalBuilderContext.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. +*/ + +import { wrappedBuilderPageListSlideToHistory } from '../view/PageListSlideToHistory'; +import { wrappedBuilderUpdaterComponent } from '../view/UpdaterComponent'; +import { wrappedBuilderWithFuncParam } from '../view/WithFuncParam'; +import { wrappedBuilderWithReuseId } from '../view/WithReuseId'; +import { Constants } from './Constants'; + +export class GlobalBuilderContext { + private static instance: GlobalBuilderContext; + private objects = new Map(); + + public static getContext(): GlobalBuilderContext { + if (!GlobalBuilderContext.instance) { + GlobalBuilderContext.instance = new GlobalBuilderContext(); + GlobalBuilderContext.instance.setObject(Constants.NAV_DESTINATION_ITEM_0, wrappedBuilderPageListSlideToHistory); + GlobalBuilderContext.instance.setObject(Constants.NAV_DESTINATION_ITEM_1, wrappedBuilderUpdaterComponent); + GlobalBuilderContext.instance.setObject(Constants.NAV_DESTINATION_ITEM_2, wrappedBuilderWithReuseId); + GlobalBuilderContext.instance.setObject(Constants.NAV_DESTINATION_ITEM_3, wrappedBuilderWithFuncParam); + } + return GlobalBuilderContext.instance; + } + + getObject(key: string): Object | undefined { + return this.objects.get(key); + } + + setObject(key: string, objectClass: Object): void { + this.objects.set(key, objectClass); + } +} \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/ets/entryability/EntryAbility.ets b/ComponentReuse/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..658b37ad825e994dbaae500a620986562981d06a --- /dev/null +++ b/ComponentReuse/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,78 @@ +/* +* 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 { window } from '@kit.ArkUI'; +import { UIAbility } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +export default class EntryAbility extends UIAbility { + private windowClass: window.Window | undefined = undefined; + + onCreate(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + this.windowClass = windowStage.getMainWindowSync(); + this.windowClass.setWindowLayoutFullScreen(true).then(() => { + hilog.info(0x0000, 'testTag', 'Success in setting the window layout to full-screen mode.'); + }).catch((err: BusinessError) => { + hilog.info(0x0000, 'testTag', + 'Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err)); + }); + this.immersive(); + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + private immersive(): void { + let type: window.AvoidAreaType = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; + let avoidArea: window.AvoidArea = this.windowClass?.getWindowAvoidArea(type) as window.AvoidArea; + let bottomRectHeight: number = avoidArea.bottomRect.height; + AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight); + type = window.AvoidAreaType.TYPE_SYSTEM; + avoidArea = this.windowClass?.getWindowAvoidArea(type) as window.AvoidArea; + let topRectHeight: number = avoidArea.topRect.height; + AppStorage.setOrCreate('topRectHeight', topRectHeight); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ComponentReuse/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ComponentReuse/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..1086e7e62c43cb995cd63f2edc6ce3fbc206084e --- /dev/null +++ b/ComponentReuse/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* +* 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'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/ets/model/BasicDataSource.ets b/ComponentReuse/entry/src/main/ets/model/BasicDataSource.ets new file mode 100644 index 0000000000000000000000000000000000000000..0bff0f4e13e6a721a3db42bb411a4b5a4cf39667 --- /dev/null +++ b/ComponentReuse/entry/src/main/ets/model/BasicDataSource.ets @@ -0,0 +1,92 @@ +/* +* 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. +*/ + +export abstract class BasicDataSource implements IDataSource { + private listeners: DataChangeListener[] = []; + + public abstract totalCount(): number; + + public abstract getData(index: number): T | void; + + registerDataChangeListener(listener: DataChangeListener): void { + if (this.listeners.indexOf(listener) < 0) { + this.listeners.push(listener); + } + } + + unregisterDataChangeListener(listener: DataChangeListener): void { + const pos = this.listeners.indexOf(listener); + if (pos > 0) { + this.listeners.splice(pos, 1); + } + } + + notifyDataAdd(index: number): void { + this.listeners.forEach((listener: DataChangeListener) => { + listener.onDataAdd(index); + }) + } +} + +/** + * Nearby People Topic Data + */ +export class FriendMoment { + id: string; + userName: string; + avatar: string; + text: string; + image: string; + share: ShareModel; + + constructor(id: string, userName: string, avatar: string, text: string, image: string, share: ShareModel) { + this.id = id; + this.userName = userName; + this.avatar = avatar; + this.text = text; + this.image = image; + this.share = share; + } +} + +/** + * Share Model + */ +export class ShareModel { + heart: number; + star: number; + message: number; + + constructor(heart: number, star: number, message: number) { + this.heart = heart; + this.star = star; + this.message = message; + } +} + +/** + * Color Model + */ +export class ColorModel { + id: string; + text: string; + color: Color; + + constructor(id: string, text: string, color: Color) { + this.id = id; + this.text = text; + this.color = color; + } +} \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/ets/model/ColorData.ets b/ComponentReuse/entry/src/main/ets/model/ColorData.ets new file mode 100644 index 0000000000000000000000000000000000000000..2477328f8f42ba7e28b93ca08a37ec7b22bb90b5 --- /dev/null +++ b/ComponentReuse/entry/src/main/ets/model/ColorData.ets @@ -0,0 +1,50 @@ +/* +* 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 { BasicDataSource, ColorModel } from './BasicDataSource'; + +export class ColorData extends BasicDataSource { + textColorData: Array = []; + + public totalCount(): number { + return this.textColorData.length; + } + + public getData(index: number): ColorModel | void { + if (index === this.textColorData.length - 1) { + this.getColorData(); + } + return this.textColorData[index]; + } + + public pushData(data: ColorModel): void { + this.textColorData.push(data); + this.notifyDataAdd(this.textColorData.length - 1); + } + + public async getColorData(): Promise { + let color: Color[] = + [Color.Black, Color.Blue, Color.Red, Color.Green, Color.Pink, Color.Black, Color.Blue, Color.Red, Color.Green, + Color.Pink]; + for (let i = 0; i < 10; i++) { + let colorModel: ColorModel = new ColorModel('', '', Color.White); + colorModel.id = Math.floor(this.totalCount() / 10) + i.toString(); + colorModel.text = + getContext().resourceManager.getStringSync($r('app.string.update_component_title'), parseInt(colorModel.id) + 1); + colorModel.color = color[i]; + this.pushData(colorModel); + } + } +} \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/ets/model/FriendMomentData.ets b/ComponentReuse/entry/src/main/ets/model/FriendMomentData.ets new file mode 100644 index 0000000000000000000000000000000000000000..cc418ec0ff9286682e260fa2d45bf45e9e2c7807 --- /dev/null +++ b/ComponentReuse/entry/src/main/ets/model/FriendMomentData.ets @@ -0,0 +1,63 @@ +/* +* 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 { BasicDataSource, FriendMoment } from './BasicDataSource'; +import { util } from '@kit.ArkTS'; +import { Constants } from '../common/Constants'; + +export class FriendMomentsData extends BasicDataSource { + private friendMoments: Array = []; + private mode: string | undefined = ''; + + constructor(mode?: string) { + super(); + this.mode = mode; + } + + public totalCount(): number { + return this.friendMoments.length; + } + + public getData(index: number): FriendMoment { + if (index === this.friendMoments.length - 1) { + this.getFriendMomentFromRawFile(); + } + return this.friendMoments[index]; + } + + public pushData(data: FriendMoment): void { + this.friendMoments.push(data); + this.notifyDataAdd(this.friendMoments.length - 1); + } + + public async getFriendMomentFromRawFile(): Promise { + const resourceManager = getContext().resourceManager; + const res = await resourceManager.getRawFileContent('mockFriendMomentOneModelData.json'); + const textDecoder = util.TextDecoder.create(); + const friendMomentArray = (JSON.parse(textDecoder.decodeToString(res)) as FriendMomentsData).friendMoments; + + friendMomentArray.forEach(item => { + if (item.id) { + item.id = Math.floor(this.totalCount() / 10) + item.id; + } + if (this.mode === Constants.NAV_DESTINATION_ITEM_3) { + item.text = resourceManager.getStringSync($r('app.string.with_func_title'), parseInt(item.id) + 1); + } else { + item.text = resourceManager.getStringSync($r('app.string.jump_text_one'), parseInt(item.id) + 1) + item.text; + } + this.pushData(item); + }) + } +} \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/ets/pages/Index.ets b/ComponentReuse/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..55f519f4bc74c95be1b8367563a4a70fba24a906 --- /dev/null +++ b/ComponentReuse/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,94 @@ +/* +* 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 { Constants } from '../common/Constants'; +import { GlobalBuilderContext } from '../common/GlobalBuilderContext'; + +@Entry +@Component +struct Index { + @StorageProp('topRectHeight') + topRectHeight: number = 0; + private readonly LIST_SPACE: number = 12; + private navDestinationData: NavDestinationItem[] = Constants.NavDestinationData; + private pageInfos: NavPathStack = new NavPathStack(); + + @Builder + PagesMap(id: string) { + if (GlobalBuilderContext.getContext().getObject(id)) { + (GlobalBuilderContext.getContext().getObject(id) as WrappedBuilder<[string]>).builder(id); + } + } + + build() { + Column() { + Navigation(this.pageInfos) { + List({ space: this.LIST_SPACE }) { + ForEach(this.navDestinationData, (item: NavDestinationItem) => { + ListItem() { + Button(item.detail) + .width(Constants.LAYOUT_MAX) + .height(40) + .borderRadius(20) + .fontSize(16) + .fontColor(Color.White) + .fontWeight(500) + .onClick(() => { + this.pageInfos.pushPathByName(item.id, ''); + }) + } + }, (item: NavDestinationItem) => JSON.stringify(item)) + } + .scrollBar(BarState.Off) + .width('90%') + .height('40%') + .margin({ top: 432 }) + } + .mode(NavigationMode.Stack) + .title({ + builder: this.mainPageTitle(), + height: 112 + }) + .navDestination(this.PagesMap) + } + .height(Constants.LAYOUT_MAX) + .width(Constants.LAYOUT_MAX) + .backgroundColor('#F1F3F5') + .padding({ top: px2vp(this.topRectHeight) }) + } + + @Builder + mainPageTitle() { + Row() { + Text($r('app.string.EntryAbility_label')) + .fontSize(30) + .lineHeight(40) + .fontWeight(700) + .fontColor('#E6000000') + } + .width(Constants.LAYOUT_MAX) + .height(Constants.LAYOUT_MAX) + .padding({ + left: 16, + top: 64, + bottom: 8 + }) + } +} + +export interface NavDestinationItem { + id: string, + detail: Resource +} diff --git a/ComponentReuse/entry/src/main/ets/view/OneMoment.ets b/ComponentReuse/entry/src/main/ets/view/OneMoment.ets new file mode 100644 index 0000000000000000000000000000000000000000..457c819f89cb08bd30243791095da16766ccf567 --- /dev/null +++ b/ComponentReuse/entry/src/main/ets/view/OneMoment.ets @@ -0,0 +1,151 @@ +/* +* 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 { Constants } from '../common/Constants'; +import { FriendMoment } from '../model/BasicDataSource'; + +@Reusable +@Component +export struct OneMoment { + @Prop moment: FriendMoment; + private readonly SHARE_INDEX_0: number = 0; + private readonly SHARE_INDEX_1: number = 1; + private readonly SHARE_INDEX_2: number = 2; + + build() { + Column() { + Row() { + Image($r(this.moment.avatar)) + .autoResize(false) + .borderRadius(15) + .width(30) + .height(30) + Column() { + Text(this.moment.userName) + .fontSize(14) + .fontColor($r('sys.color.font_primary')) + .lineHeight(19) + .fontWeight(FontWeight.Medium) + Text($r('app.string.two_days_ago')) + .fontSize(10) + .fontWeight(FontWeight.Regular) + .fontColor($r('sys.color.font_primary')) + .lineHeight(14) + .opacity(0.6) + } + .margin({ left: 8 }) + .alignItems(HorizontalAlign.Start) + } + .width(Constants.LAYOUT_MAX) + .constraintSize({ minHeight: 38 }) + .padding({ + left: 12, + top: 11, + bottom: 11 + }) + + Stack() { + if (this.moment.image) { + Column() { + Image($r(this.moment.image)) + .id('singleImage') + .width(Constants.LAYOUT_MAX) + .height(278) + } + .alignItems(HorizontalAlign.Start) + .width(Constants.LAYOUT_MAX) + .padding({ + left: 12, + right: 12 + }) + } + } + + Row() { + Text(this.moment.text) + .fontSize(14) + .fontWeight(FontWeight.Regular) + .fontColor(Color.Black) + .lineHeight(19) + } + .width(Constants.LAYOUT_MAX) + .padding({ + left: 11, + top: 8 + }) + + // Using @Builder, you can reduce the time-consuming creation and rendering of custom components. + Row() { + Image($r('app.media.share')) + .width(24) + .height(24) + .autoResize(false) + + Row() { + interactiveButton({ + imageStr: $r('app.media.heart'), + text: `${this.moment.share.heart}` + }, this.SHARE_INDEX_0) + interactiveButton({ + imageStr: $r('app.media.star'), + text: `${this.moment.share.star}` + }, this.SHARE_INDEX_1) + interactiveButton({ + imageStr: $r('app.media.ellipsis_message'), + text: `${this.moment.share.message}` + }, this.SHARE_INDEX_2) + } + .justifyContent(FlexAlign.End) + .layoutWeight(1) + } + .width(Constants.LAYOUT_MAX) + .padding({ + left: 12, + top: 8, + bottom: 12, + right: 29.75 + }) + } + .backgroundColor(Color.White) + .width(Constants.LAYOUT_MAX) + .borderRadius(16) + } +} + +@Builder +export function interactiveButton($$: Temp, index: number) { + Row() { + // Use $$ to transfer data by reference so that @Builder can sense data changes and refresh the UI. + Image($$.imageStr) + .width(24) + .height(24) + .objectFit(ImageFit.Contain) + .autoResize(false) + Text($$.text) + .fontSize(12) + .fontWeight(FontWeight.Medium) + .fontColor(Color.Black) + .lineHeight(16) + .opacity(0.9) + .margin({ left: 2 }) + } + .alignItems(VerticalAlign.Center) + .margin({ left: index > 0 ? 12 : 0 }) +} + +class Temp { + imageStr: ResourceStr = ''; + text: ResourceStr | string = ''; +} \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/ets/view/PageListSlideToHistory.ets b/ComponentReuse/entry/src/main/ets/view/PageListSlideToHistory.ets new file mode 100644 index 0000000000000000000000000000000000000000..cc35bc15018a5fec9b0f7591b96c3b816221287c --- /dev/null +++ b/ComponentReuse/entry/src/main/ets/view/PageListSlideToHistory.ets @@ -0,0 +1,148 @@ +/* +* 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 { Constants } from '../common/Constants'; +import { FriendMoment } from '../model/BasicDataSource'; +import { FriendMomentsData } from '../model/FriendMomentData'; +import { OneMoment } from './OneMoment'; + +@Component +export struct PageListSlideToHistory { + @State firstVisibleItemIndex: number = 0; // The first visible item index + private readonly DEFAULT_OFFSET: number = 1000; + private readonly ANIMATION_DURATION: number = 500; + private readonly DEFAULT_VISIBLE_BTN_INDEX: number = 3; // Show jump history button when scroll more than 3 item + private readonly LIST_CACHE_COUNT: number = 3; + private momentData: FriendMomentsData = new FriendMomentsData(); + private listScroller: ListScroller = new ListScroller(); + private historyOffset: number = 0; + private isHistoricalRecord: boolean = false; + + aboutToAppear(): void { + this.momentData.getFriendMomentFromRawFile(); + } + + build() { + Stack({ alignContent: Alignment.BottomEnd }) { + Column() { + List({ space: Constants.LIST_SPACE, scroller: this.listScroller }) { + LazyForEach(this.momentData, (moment: FriendMoment, index: number) => { + ListItem() { + this.itemBuilder(moment, index); + } + }, (moment: FriendMoment) => moment.id) + } + .cachedCount(this.LIST_CACHE_COUNT) + .width(Constants.LAYOUT_MAX) + .height(Constants.LAYOUT_MAX) + .margin({ top: 8 }) + .listDirection(Axis.Vertical) + .scrollBar(BarState.Off) + .onScrollIndex((first: number) => { + this.firstVisibleItemIndex = first; + }) + } + .width(Constants.LAYOUT_MAX) + .height(Constants.LAYOUT_MAX) + + Row() { + Image($r('app.media.ic_back_to_top')) + .width(24) + .height(24) + .opacity(0.8) + } + .visibility(this.firstVisibleItemIndex >= this.DEFAULT_VISIBLE_BTN_INDEX ? Visibility.Visible : Visibility.None) + .justifyContent(FlexAlign.Center) + .width(48) + .height(48) + .backgroundColor('#0A59F7') + .borderRadius(36) + .margin({ right: 16 }) + .onClick(() => { + if (this.firstVisibleItemIndex >= this.DEFAULT_VISIBLE_BTN_INDEX) { + this.historyOffset = this.listScroller.currentOffset().yOffset; + this.listScroller.scrollTo({ + xOffset: Constants.COMM_INIT, + yOffset: Constants.COMM_INIT, + animation: { duration: this.ANIMATION_DURATION, curve: Curve.LinearOutSlowIn } + }); + this.isHistoricalRecord = true; + } + }) + } + } + + @Builder + itemBuilder(moment: FriendMoment, index: number) { + Column() { + if (index === Constants.COMM_INIT && this.isHistoricalRecord) { + Text($r('app.string.jump_to_history')) + .fontColor('#0A59F7') + .fontSize(12) + .margin({ + top: 24, + bottom: 24 + }) + .onClick(() => { + if (this.firstVisibleItemIndex < this.DEFAULT_VISIBLE_BTN_INDEX) { + this.listScroller.scrollTo({ + xOffset: 0, + yOffset: this.historyOffset === Constants.COMM_INIT ? this.DEFAULT_OFFSET : this.historyOffset, + animation: { + duration: this.ANIMATION_DURATION, + curve: Curve.LinearOutSlowIn + } + }); + this.isHistoricalRecord = false; + } + }) + } + OneMoment({ moment: moment }) + } + .margin({ + left: 16, + right: 16 + }) + } +} + +@Builder +function getPageListSlideToHistory(name: string): void { + if (name === Constants.NAV_DESTINATION_ITEM_0) { + NavDestination() { + PageListSlideToHistory() + } + .title(title()) + .backgroundColor('#F1F3F5') + } +} + +@Builder +function title() { + Text($r('app.string.near_people')) + .fontSize(20) + .fontColor($r('sys.color.font_primary')) + .fontWeight(FontWeight.Bold) + .margin({ + left: 8, + top: 16 + }) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .lineHeight(24) +} + +export const wrappedBuilderPageListSlideToHistory: WrappedBuilder<[string]> = + wrapBuilder(getPageListSlideToHistory); \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/ets/view/UpdaterComponent.ets b/ComponentReuse/entry/src/main/ets/view/UpdaterComponent.ets new file mode 100644 index 0000000000000000000000000000000000000000..507e3d0c60552f305934d2a44d9c09f8b779ade5 --- /dev/null +++ b/ComponentReuse/entry/src/main/ets/view/UpdaterComponent.ets @@ -0,0 +1,145 @@ +/* +* 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 '@ohos.hilog'; +import { AttributeUpdater } from '@ohos.arkui.modifier'; +import { Constants } from '../common/Constants'; +import { ColorModel } from '../model/BasicDataSource'; +import { ColorData } from '../model/ColorData'; + +const TAG = 'UpdaterComponent' + +export class MyTextUpdater extends AttributeUpdater { + private color: string | number | Resource | Color = ''; + + constructor(color: string | number | Resource | Color) { + super(); + this.color = color; + } + + initializeModifier(instance: TextAttribute): void { + instance.fontColor(this.color) // Differentiated update + } +} + +@Component +export struct UpdaterComponent { + private colorData: ColorData = new ColorData(); + private readonly LIST_CACHE_COUNT: number = 5; + private readonly LIST_SPACE: number = 18; + + aboutToAppear(): void { + this.colorData.getColorData(); + } + + build() { + Column() { + List({ space: this.LIST_SPACE }) { + LazyForEach(this.colorData, (colorModel: ColorModel) => { + ListItem() { + OneMomentNoModifier({ color: colorModel.color, text: colorModel.text }) + .onClick(() => { + hilog.info(0x0000, TAG, `my id is ${colorModel.id}`); + }) + } + }, (color: ColorModel) => color.id) + } + .cachedCount(this.LIST_CACHE_COUNT) + .margin({ top: 8 }) + .width(Constants.LAYOUT_MAX) + .height(Constants.LAYOUT_MAX) + } + } +} + +@Reusable +@Component +export struct OneMomentNoModifier { + @Prop text: string; + color: string | number | Resource | Color = ''; + textUpdater: MyTextUpdater | null = null; + + aboutToAppear(): void { + this.textUpdater = new MyTextUpdater(this.color); + } + + aboutToReuse(params: Record): void { + this.color = params.color as string; + this.textUpdater?.attribute?.fontColor(this.color); + } + + build() { + Column() { + Text(this.text) + .fontSize(18) + .textAlign(TextAlign.Center) + .fontWeight(500) + .lineHeight(24) + .fontColor(Color.Black) + .opacity(0.6) + Column() { + Text($r('app.string.update_component_internal_text')) + .attributeModifier(this.textUpdater) // Precise refresh + .textAlign(TextAlign.Start) + .fontSize(16) + .fontWeight(400) + .lineHeight(21) + } + .borderRadius(16) + .margin({ top: 14 }) + .padding({ + left: 16, + right: 16, + top: 8, + bottom: 8 + }) + .backgroundColor('#0D000000') + } + .alignItems(HorizontalAlign.Start) + .margin({ + left: 16, + right: 16 + }) + } +} + +@Builder +function getUpdaterComponent(name: string): void { + if (name === Constants.NAV_DESTINATION_ITEM_1) { + NavDestination() { + UpdaterComponent() + } + .title(title()) + .backgroundColor('#F1F3F5') + } +} + +@Builder +function title() { + Text($r('app.string.text_list')) + .fontSize(20) + .fontColor($r('sys.color.font_primary')) + .fontWeight(FontWeight.Bold) + .margin({ + left: 8, + top: 16 + }) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .lineHeight(24) +} + +export const wrappedBuilderUpdaterComponent: WrappedBuilder<[string]> = + wrapBuilder(getUpdaterComponent); \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/ets/view/WithFuncParam.ets b/ComponentReuse/entry/src/main/ets/view/WithFuncParam.ets new file mode 100644 index 0000000000000000000000000000000000000000..72f66546e9cdf6f994ae4114728083d1c07abf34 --- /dev/null +++ b/ComponentReuse/entry/src/main/ets/view/WithFuncParam.ets @@ -0,0 +1,175 @@ +/* +* 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 { Constants } from '../common/Constants'; +import { FriendMoment } from '../model/BasicDataSource'; +import { FriendMomentsData } from '../model/FriendMomentData'; + +@Entry +@Component +struct WithFuncParam { + @State sum: number = 0; + private momentData: FriendMomentsData = new FriendMomentsData(Constants.NAV_DESTINATION_ITEM_3); + private readonly LIST_CACHE_COUNT: number = 5; + private readonly LIST_SPACE: number = 18; + private readonly MOCK_ASYNC_DEFAULT_NUM: number = 1000000; + private readonly MOCK_ASYNC_TIME_OUT_NUM: number = 2000; + + aboutToAppear(): void { + this.momentData.getFriendMomentFromRawFile(); + // Execute the asynchronous function + this.countAndRecord(); + } + + async countAndRecord(): Promise { + await this.sleep(); + this.sum = this.MOCK_ASYNC_DEFAULT_NUM; + } + + sleep(): Promise { + return new Promise((resolve) => { + setTimeout(() => { + resolve('ok'); + }, this.MOCK_ASYNC_TIME_OUT_NUM) + }); + } + + build() { + Column() { + List({ space: this.LIST_SPACE }) { + LazyForEach(this.momentData, (moment: FriendMoment) => { + ListItem() { + // Parameters of subcomponents are transferred through status variables + OneMoment({ + moment: moment, + sum: this.sum + }) + } + }, (moment: FriendMoment) => moment.id) + } + .cachedCount(this.LIST_CACHE_COUNT) + .margin({ top: 8 }) + .width(Constants.LAYOUT_MAX) + .height(Constants.LAYOUT_MAX) + } + } +} + +@Reusable +@Component +export struct OneMoment { + @Prop moment: FriendMoment; + @Prop sum: number; + private readonly LAST_ITEM_INDEX: number = 2; + + aboutToReuse(params: Record): void { + this.sum = params.sum as number; + } + + build() { + Column() { + Text(this.moment.text) + .fontSize(18) + .textAlign(TextAlign.Center) + .fontWeight(500) + .lineHeight(24) + .fontColor(Color.Black) + .opacity(0.6) + Column() { + this.item(); + this.item(); + this.item(this.LAST_ITEM_INDEX); + } + .borderRadius(16) + .margin({ top: 14 }) + .padding({ + left: 12, + right: 12, + top: 13, + bottom: 13 + }) + .backgroundColor(Color.White) + .width(Constants.LAYOUT_MAX) + } + .alignItems(HorizontalAlign.Start) + .margin({ + left: 16, + right: 16 + }) + } + + @Builder + item(index?: number) { + Column() { + Row() { + Text(this.moment.userName) + .fontSize(16) + .fontWeight(500) + .lineHeight(22) + .textAlign(TextAlign.Start) + .opacity(0.9) + Text(`${this.moment.id}/${this.sum}`) + .fontSize(14) + .fontWeight(400) + .lineHeight(19) + .textAlign(TextAlign.End) + .layoutWeight(1) + .opacity(0.6) + } + .width(Constants.LAYOUT_MAX) + } + + if (index !== this.LAST_ITEM_INDEX) { + Row() + .width(Constants.LAYOUT_MAX) + .height(1) + .backgroundColor(Color.Black) + .margin({ + top: 12.5, + bottom: 13 + }) + .opacity(0.1) + } + } +} + +@Builder +function getWithFuncParam(name: string): void { + if (name === Constants.NAV_DESTINATION_ITEM_3) { + NavDestination() { + WithFuncParam() + } + .title(title()) + .backgroundColor('#F1F3F5') + } +} + +@Builder +function title() { + Text($r('app.string.net_name_message')) + .fontSize(20) + .fontColor($r('sys.color.font_primary')) + .fontWeight(FontWeight.Bold) + .margin({ + left: 8, + top: 16 + }) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .lineHeight(24) +} + +export const wrappedBuilderWithFuncParam: WrappedBuilder<[string]> = + wrapBuilder(getWithFuncParam); \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/ets/view/WithReuseId.ets b/ComponentReuse/entry/src/main/ets/view/WithReuseId.ets new file mode 100644 index 0000000000000000000000000000000000000000..a78aeb546c600f5b3116fa3a1f9636a58b70b7fb --- /dev/null +++ b/ComponentReuse/entry/src/main/ets/view/WithReuseId.ets @@ -0,0 +1,115 @@ +/* +* 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 { Constants } from '../common/Constants'; +import { FriendMoment } from '../model/BasicDataSource'; +import { FriendMomentsData } from '../model/FriendMomentData' + +@Entry +@Component +struct WithReuseId { + private momentData: FriendMomentsData = new FriendMomentsData(); + private readonly LIST_CACHE_COUNT: number = 5; + private readonly LIST_SPACE: number = 18; + + aboutToAppear(): void { + this.momentData.getFriendMomentFromRawFile(); + } + + build() { + Column() { + List({ space: this.LIST_SPACE }) { + LazyForEach(this.momentData, (moment: FriendMoment) => { + ListItem() { + OneMoment({ moment: moment })// ReusId is used to control component reuse + .reuseId((moment.image !== '') ? 'withImage_id' : 'noImage_id') + } + }, (moment: FriendMoment) => moment.id) + } + .cachedCount(this.LIST_CACHE_COUNT) + .margin({ top: 8 }) + .width(Constants.LAYOUT_MAX) + .height(Constants.LAYOUT_MAX) + } + } +} + +@Reusable +@Component +export struct OneMoment { + @Prop moment: FriendMoment; + + build() { + Column() { + Text(this.moment.text) + .width(Constants.LAYOUT_MAX) + .fontSize(18) + .fontWeight(500) + .lineHeight(24) + .opacity(0.6) + + if (this.moment.image !== '') { + Flex({ wrap: FlexWrap.Wrap }) { + Image($r(this.moment.image)) + .width(Constants.LAYOUT_MAX) + .height('27.5%') + .borderRadius(16) + Image($r(this.moment.image)) + .width(Constants.LAYOUT_MAX) + .height('27.5%') + .borderRadius(16) + .margin({ top: 10 }) + } + .width(Constants.LAYOUT_MAX) + .margin({ top: 14 }) + } + } + .justifyContent(FlexAlign.Start) + .margin({ + left: 16, + right: 16 + }) + } +} + +@Builder +function getWithReuseId(name: string): void { + if (name === Constants.NAV_DESTINATION_ITEM_2) { + NavDestination() { + WithReuseId() + } + .title(title()) + .backgroundColor('#F1F3F5') + } +} + +@Builder +function title() { + Text($r('app.string.pic_text_list')) + .fontSize(20) + .fontColor($r('sys.color.font_primary')) + .fontWeight(FontWeight.Bold) + .margin({ + left: 8, + top: 16 + }) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .lineHeight(24) +} + +export const wrappedBuilderWithReuseId: WrappedBuilder<[string]> = + wrapBuilder(getWithReuseId); + diff --git a/ComponentReuse/entry/src/main/module.json5 b/ComponentReuse/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ad219d733f6afa5ea07f85f580208b08cc3b9041 --- /dev/null +++ b/ComponentReuse/entry/src/main/module.json5 @@ -0,0 +1,50 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/resources/base/element/color.json b/ComponentReuse/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ComponentReuse/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/resources/base/element/string.json b/ComponentReuse/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8e59ae9d4c7181dcca0bc23615bf24b3eae72a81 --- /dev/null +++ b/ComponentReuse/entry/src/main/resources/base/element/string.json @@ -0,0 +1,72 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "nav_destination_item0", + "value": "Reduce nested levels of component reuse" + }, + { + "name": "nav_destination_item1", + "value": "Accurately control the refresh range of components" + }, + { + "name": "nav_destination_item2", + "value": "Use reuseId to mark components of different structures" + }, + { + "name": "nav_destination_item3", + "value": "@State variable input when reusing component creation" + }, + { + "name": "update_component_title", + "value": "title %d" + }, + { + "name": "with_func_title", + "value": "List%d" + }, + { + "name": "jump_text_one", + "value": "This is message number %d:" + }, + { + "name": "two_days_ago", + "value": "two days ago" + }, + { + "name": "jump_to_history", + "value": "jump to history" + }, + { + "name": "near_people", + "value": "near people" + }, + { + "name": "update_component_internal_text", + "value": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "name": "text_list", + "value": "text list" + }, + { + "name": "net_name_message", + "value": "net name list" + }, + { + "name": "pic_text_list", + "value": "picture and text list" + } + ] +} \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/resources/base/media/background.png b/ComponentReuse/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/ComponentReuse/entry/src/main/resources/base/media/background.png differ diff --git a/ComponentReuse/entry/src/main/resources/base/media/ellipsis_message.svg b/ComponentReuse/entry/src/main/resources/base/media/ellipsis_message.svg new file mode 100644 index 0000000000000000000000000000000000000000..d32365d773b4ccb5bb3b0aea7fa2f746c16b267c --- /dev/null +++ b/ComponentReuse/entry/src/main/resources/base/media/ellipsis_message.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/resources/base/media/foreground.png b/ComponentReuse/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/ComponentReuse/entry/src/main/resources/base/media/foreground.png differ diff --git a/ComponentReuse/entry/src/main/resources/base/media/heart.svg b/ComponentReuse/entry/src/main/resources/base/media/heart.svg new file mode 100644 index 0000000000000000000000000000000000000000..fa899b0fcfceec7178e51a6d90a4acc0c49683d3 --- /dev/null +++ b/ComponentReuse/entry/src/main/resources/base/media/heart.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/resources/base/media/ic_back_to_top.svg b/ComponentReuse/entry/src/main/resources/base/media/ic_back_to_top.svg new file mode 100644 index 0000000000000000000000000000000000000000..f6ee17b436f329b1fc1bec599cf60bc60ccb1518 --- /dev/null +++ b/ComponentReuse/entry/src/main/resources/base/media/ic_back_to_top.svg @@ -0,0 +1,13 @@ + + + Public/ic_public_backtotop + + + + + + + + + + \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic1.JPG b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic1.JPG new file mode 100644 index 0000000000000000000000000000000000000000..1b7509552c7c10f33c289292363b5514bb282c5b Binary files /dev/null and b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic1.JPG differ diff --git a/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic10.JPG b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic10.JPG new file mode 100644 index 0000000000000000000000000000000000000000..a3793131c5ca7f93f054debda5109d93df2d4120 Binary files /dev/null and b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic10.JPG differ diff --git a/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic11.JPG b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic11.JPG new file mode 100644 index 0000000000000000000000000000000000000000..86d3c5bbcc5e6afc14c292c047d8f53dd7a9040a Binary files /dev/null and b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic11.JPG differ diff --git a/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic2.JPG b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic2.JPG new file mode 100644 index 0000000000000000000000000000000000000000..a06b244c55436d2baf4accd41af8019b0632a13a Binary files /dev/null and b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic2.JPG differ diff --git a/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic3.JPG b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic3.JPG new file mode 100644 index 0000000000000000000000000000000000000000..49d315f3c1cee8a395225077a597ac94416d5f93 Binary files /dev/null and b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic3.JPG differ diff --git a/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic4.JPG b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic4.JPG new file mode 100644 index 0000000000000000000000000000000000000000..07dbababf470a2c5484070e4bfdc34c677184205 Binary files /dev/null and b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic4.JPG differ diff --git a/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic5.JPG b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic5.JPG new file mode 100644 index 0000000000000000000000000000000000000000..d404585d6bcfbd465eec15ccd2f9e7aa4a1c59f4 Binary files /dev/null and b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic5.JPG differ diff --git a/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic6.JPG b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic6.JPG new file mode 100644 index 0000000000000000000000000000000000000000..f40467335e6d9a67c68dfc3148fea4a6be380f77 Binary files /dev/null and b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic6.JPG differ diff --git a/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic7.JPG b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic7.JPG new file mode 100644 index 0000000000000000000000000000000000000000..3afff45814aaa18429c62154bd2f7b1a6483a36a Binary files /dev/null and b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic7.JPG differ diff --git a/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic8.JPG b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic8.JPG new file mode 100644 index 0000000000000000000000000000000000000000..9961a64cc5de344c847d86a9b5be2998acc80f57 Binary files /dev/null and b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic8.JPG differ diff --git a/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic9.JPG b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic9.JPG new file mode 100644 index 0000000000000000000000000000000000000000..4f8b01f06b70040307d55ee3a6955e034d9de86e Binary files /dev/null and b/ComponentReuse/entry/src/main/resources/base/media/ic_comm_pic9.JPG differ diff --git a/ComponentReuse/entry/src/main/resources/base/media/img.png b/ComponentReuse/entry/src/main/resources/base/media/img.png new file mode 100644 index 0000000000000000000000000000000000000000..8a4b50bf84719ee09175ce824c3140b158b07e3b Binary files /dev/null and b/ComponentReuse/entry/src/main/resources/base/media/img.png differ diff --git a/ComponentReuse/entry/src/main/resources/base/media/layered_image.json b/ComponentReuse/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ComponentReuse/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/resources/base/media/share.svg b/ComponentReuse/entry/src/main/resources/base/media/share.svg new file mode 100644 index 0000000000000000000000000000000000000000..eb8fdd7faba07d4b04d0d461f44c6e8ecbbe5e6d --- /dev/null +++ b/ComponentReuse/entry/src/main/resources/base/media/share.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/resources/base/media/star.svg b/ComponentReuse/entry/src/main/resources/base/media/star.svg new file mode 100644 index 0000000000000000000000000000000000000000..6794c145e8b22ede6975ee17a5ebdf7be7a75132 --- /dev/null +++ b/ComponentReuse/entry/src/main/resources/base/media/star.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/resources/base/media/startIcon.png b/ComponentReuse/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ComponentReuse/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ComponentReuse/entry/src/main/resources/base/profile/backup_config.json b/ComponentReuse/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ComponentReuse/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/resources/base/profile/main_pages.json b/ComponentReuse/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ComponentReuse/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ComponentReuse/entry/src/main/resources/en_US/element/string.json b/ComponentReuse/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8e59ae9d4c7181dcca0bc23615bf24b3eae72a81 --- /dev/null +++ b/ComponentReuse/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,72 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "nav_destination_item0", + "value": "Reduce nested levels of component reuse" + }, + { + "name": "nav_destination_item1", + "value": "Accurately control the refresh range of components" + }, + { + "name": "nav_destination_item2", + "value": "Use reuseId to mark components of different structures" + }, + { + "name": "nav_destination_item3", + "value": "@State variable input when reusing component creation" + }, + { + "name": "update_component_title", + "value": "title %d" + }, + { + "name": "with_func_title", + "value": "List%d" + }, + { + "name": "jump_text_one", + "value": "This is message number %d:" + }, + { + "name": "two_days_ago", + "value": "two days ago" + }, + { + "name": "jump_to_history", + "value": "jump to history" + }, + { + "name": "near_people", + "value": "near people" + }, + { + "name": "update_component_internal_text", + "value": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "name": "text_list", + "value": "text list" + }, + { + "name": "net_name_message", + "value": "net name list" + }, + { + "name": "pic_text_list", + "value": "picture and text list" + } + ] +} \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/resources/rawfile/mockFriendMomentOneModelData.json b/ComponentReuse/entry/src/main/resources/rawfile/mockFriendMomentOneModelData.json new file mode 100644 index 0000000000000000000000000000000000000000..7e21e95e5f74ffb5d01a079c2500c1e87c213514 --- /dev/null +++ b/ComponentReuse/entry/src/main/resources/rawfile/mockFriendMomentOneModelData.json @@ -0,0 +1,124 @@ +{ + "friendMoments": [ + { + "id": "0", + "userName": "\u4E3A\u8C01\u70F9\u8FC7\u8336", + "avatar": "app.media.ic_comm_pic8", + "text": "\u4F24\u5FC3\u5343\u53E4\uFF0C\u6CEA\u75D5\u5982\u6D17\u3002", + "image": "app.media.ic_comm_pic1", + "share": { + "heart": 267, + "star": 193, + "message": 1593 + } + }, + { + "id": "1", + "userName": "\u6709\u98CE\u63A0\u8FC7", + "avatar": "app.media.ic_comm_pic9", + "text": "\u770B\u7236\u8001\u8885\u82B1\uFF0C\u82E6\u906E\u53BB\u8F99\uFF0C\u513F\u7AE5\u9A91\u7AF9\uFF0C\u4E89\u95EE\u5F52\u671F\u3002", + "image": "app.media.ic_comm_pic5", + "share": { + "heart": 1234, + "star": 200, + "message": 111 + } + }, + { + "id": "2", + "userName": "\u70FD\u70DF\u56DB\u8D77", + "avatar": "app.media.ic_comm_pic10", + "text": "\u6168\u5546\u5973\u4E0D\u77E5\u5174\u5E9F\u3002", + "image": "app.media.ic_comm_pic2", + "share": { + "heart": 567, + "star": 193, + "message": 6523 + } + }, + { + "id": "3", + "userName": "\u672B\u7231\u4E16\u7EAA", + "avatar": "app.media.ic_comm_pic11", + "text": "\u770B\u7236\u8001\u8885\u82B1\uFF0C\u82E6\u906E\u53BB\u8F99\uFF0C\u513F\u7AE5\u9A91\u7AF9\uFF0C\u4E89\u95EE\u5F52\u671F\u3002", + "image": "app.media.ic_comm_pic7", + "share": { + "heart": 842, + "star": 243, + "message": 900 + } + }, + { + "id": "4", + "userName": "\u6C89\u7720\u7684\u57CE", + "avatar": "app.media.ic_comm_pic8", + "text": "\u4FBF\u7A33\u5949\u5B89\u8206\uFF0C\u6C5F\u5357\u5411\u6696\uFF0C\u65E9\u4F20\u8A00\u8BED\uFF0C\u6A35\u66F2\u5148\u77E5\u3002", + "image": "app.media.ic_comm_pic3", + "share": { + "heart": 324, + "star": 1423, + "message": 1213 + } + }, + { + "id": "5", + "userName": "\u6CEA\u6BD4\u6D77\u6C34\u54B8", + "avatar": "app.media.ic_comm_pic9", + "text": "\u4E8B\u53BB\u7A7A\u6D41\u4E1C\u6C74\u6C34\uFF0C\u6101\u6765\u4E0D\u89C1\u897F\u6E56\u6708\u3002", + "image": "", + "share": { + "heart": 654, + "star": 245, + "message": 6643 + } + }, + { + "id": "6", + "userName": "\u9634\u5929\u5206\u624B", + "avatar": "app.media.ic_comm_pic10", + "text": "\u9F99\u864E\u6563\uFF0C\u98CE\u4E91\u706D\u3002", + "image": "app.media.ic_comm_pic4", + "share": { + "heart": 1423, + "star": 4235, + "message": 4254 + } + }, + { + "id": "7", + "userName": "\u522B\u8DDF\u7740\u6211", + "avatar": "app.media.ic_comm_pic11", + "text": "\u56E0\u601D\u7574\u6614\uFF0C\u94C1\u7D22\u5343\u5BFB\uFF0C\u8C29\u6C88\u6C5F\u5E95\u3002", + "image": "", + "share": { + "heart": 312, + "star": 423, + "message": 876 + } + }, + { + "id": "8", + "userName": "\u672B\u8DEF\u9752\u6625", + "avatar": "app.media.ic_comm_pic8", + "text": "\u4E00\u4E2A\u5170\u821F\uFF0C\u53CC\u6842\u6868\u3001\u987A\u6D41\u4E1C\u53BB\u3002", + "image": "app.media.ic_comm_pic6", + "share": { + "heart": 321, + "star": 432, + "message": 876 + } + }, + { + "id": "9", + "userName": "\u4E0E\u964C\u751F\u4EBA\u76F8\u5BF9", + "avatar": "app.media.ic_comm_pic9", + "text": "\u5BA2\u9986\u591C\u60CA\u5C18\u571F\u68A6\uFF0C\u5BAB\u8F66\u6653\u78BE\u5173\u5C71\u6708\u3002", + "image": "", + "share": { + "heart": 124, + "star": 654, + "message": 756 + } + } + ] +} \ No newline at end of file diff --git a/ComponentReuse/entry/src/main/resources/zh_CN/element/string.json b/ComponentReuse/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..453a6b114955fe32006678fbec7684c86b1d98e2 --- /dev/null +++ b/ComponentReuse/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,72 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "组件复用" + }, + { + "name": "nav_destination_item0", + "value": "减少组件复用的嵌套层级" + }, + { + "name": "nav_destination_item1", + "value": "精准控制组件刷新范围" + }, + { + "name": "nav_destination_item2", + "value": "使用reuseId标记不同结构的组件" + }, + { + "name": "nav_destination_item3", + "value": "复用组件创建时的@State变量入参" + }, + { + "name": "update_component_title", + "value": "标题%d" + }, + { + "name": "with_func_title", + "value": "列表%d" + }, + { + "name": "jump_text_one", + "value": "这是第%d条消息:" + }, + { + "name": "two_days_ago", + "value": "2天前" + }, + { + "name": "jump_to_history", + "value": "跳转到上次浏览历史" + }, + { + "name": "near_people", + "value": "附近的人" + }, + { + "name": "update_component_internal_text", + "value": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + }, + { + "name": "text_list", + "value": "文字列表" + }, + { + "name": "net_name_message", + "value": "网名列表" + }, + { + "name": "pic_text_list", + "value": "图文列表" + } + ] +} \ No newline at end of file diff --git a/ComponentReuse/hvigor/hvigor-config.json5 b/ComponentReuse/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..06b2783670a348f95533b352c1ceda909a842bbc --- /dev/null +++ b/ComponentReuse/hvigor/hvigor-config.json5 @@ -0,0 +1,22 @@ +{ + "modelVersion": "5.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ComponentReuse/hvigorfile.ts b/ComponentReuse/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775 --- /dev/null +++ b/ComponentReuse/hvigorfile.ts @@ -0,0 +1,6 @@ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ComponentReuse/oh-package.json5 b/ComponentReuse/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8bf916d4a165e0466c65bc49f58ab2e3c27e8931 --- /dev/null +++ b/ComponentReuse/oh-package.json5 @@ -0,0 +1,8 @@ +{ + "modelVersion": "5.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + } +} diff --git a/ComponentReuse/screenshots/device/mode_1.gif b/ComponentReuse/screenshots/device/mode_1.gif new file mode 100644 index 0000000000000000000000000000000000000000..324ffce9f7246adf79e8ddc35479d1920f7662e7 Binary files /dev/null and b/ComponentReuse/screenshots/device/mode_1.gif differ diff --git a/ComponentReuse/screenshots/device/mode_2.gif b/ComponentReuse/screenshots/device/mode_2.gif new file mode 100644 index 0000000000000000000000000000000000000000..59122ce49d004480d89369c99b5c8a37ec5928b5 Binary files /dev/null and b/ComponentReuse/screenshots/device/mode_2.gif differ diff --git a/ComponentReuse/screenshots/device/mode_3.gif b/ComponentReuse/screenshots/device/mode_3.gif new file mode 100644 index 0000000000000000000000000000000000000000..557b5c5a6a4d4883748f81642400609bc67f4cbb Binary files /dev/null and b/ComponentReuse/screenshots/device/mode_3.gif differ diff --git a/ComponentReuse/screenshots/device/mode_4.gif b/ComponentReuse/screenshots/device/mode_4.gif new file mode 100644 index 0000000000000000000000000000000000000000..a9d85c57b54eed9d50b2044ea594bec5d5d04d8c Binary files /dev/null and b/ComponentReuse/screenshots/device/mode_4.gif differ diff --git a/README.md b/README.md index 485c3fceece78e6b07779a5e27a7ee4f6760dfb7..43343617d8cf86604d37940481b934b749367e52 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ * [AppDataSecurity: 应用数据安全](AppDataSecurity) * [AppPrivacyProtection:应用隐私保护](AppPrivacyProtection) * [AvoidTimeComsume:主线程耗时操作优化指导](AvoidTimeComsume) +* [ComponentReuse:组件复用开发实践](ComponentReuse) * [CustomDialogPractice:应用自定义弹窗开发实践](CustomDialogPractice) * [FuzzySceneOptimization:图像模糊动效优化](FuzzySceneOptimization) * [NdkQoS:基于QoS设置线程优先级](NdkQoS)