diff --git a/ArkUIKit/StateStyle/.gitignore b/ArkUIKit/StateStyle/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/ArkUIKit/StateStyle/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/ArkUIKit/StateStyle/AppScope/app.json5 b/ArkUIKit/StateStyle/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e3afbf37a6d3601558f96d4961524654043cb577 --- /dev/null +++ b/ArkUIKit/StateStyle/AppScope/app.json5 @@ -0,0 +1,24 @@ +/* + * 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. + */ +{ + "app": { + "bundleName": "com.example.StateStyle", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/ArkUIKit/StateStyle/AppScope/resources/base/element/string.json b/ArkUIKit/StateStyle/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3b57591431fa00901f16b8fd617cbdbe3b7ca535 --- /dev/null +++ b/ArkUIKit/StateStyle/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ComponentExtension" + } + ] +} diff --git a/ArkUIKit/StateStyle/AppScope/resources/base/media/background.png b/ArkUIKit/StateStyle/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/StateStyle/AppScope/resources/base/media/background.png differ diff --git a/ArkUIKit/StateStyle/AppScope/resources/base/media/foreground.png b/ArkUIKit/StateStyle/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..eb9427585b36d14b12477435b6419d1f07b3e0bb Binary files /dev/null and b/ArkUIKit/StateStyle/AppScope/resources/base/media/foreground.png differ diff --git a/ArkUIKit/StateStyle/AppScope/resources/base/media/layered_image.json b/ArkUIKit/StateStyle/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/StateStyle/AppScope/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/ArkUIKit/StateStyle/README_zh.md b/ArkUIKit/StateStyle/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..c6eeaf21200fefd71213c87f897a2365936c6c17 --- /dev/null +++ b/ArkUIKit/StateStyle/README_zh.md @@ -0,0 +1,76 @@ +# ArkUI使用支持交互事件指南文档示例 + +### 介绍 + +本示例通过使用[ArkUI指南文档](https://gitcode.com/openharmony/docs/tree/master/zh-cn/application-dev/ui) +中各场景的开发示例,展示在工程中,帮助开发者更好地理解ArkUI提供的组件及组件属性并合理使用。 + +### 效果预览 + +| 首页 | 交互类组件目录 | 多态样式示例 | +|------------------------------------|------------------------------------|------------------------------------| +| ![](screenshots/device/image2.png) | ![](screenshots/device/image2.png) | ![](screenshots/device/image3.png) | + +### 使用说明 + +1. 在主界面,可以点击对应卡片,选择需要参考的组件示例。 + +2. 在组件目录选择详细的示例参考。 + +3. 进入示例界面,查看参考示例。 + +4. 通过自动测试框架可进行测试及维护。 + +### 工程目录 + +``` +entry/src/main/ets/ +|---entryability +|---pages +| |---FocusStyle //多态样式 +| | |---CompWithInlineStateStyles.ets +| |---NormalStyle +| | |---MyComponent.ets +| |---StateStyle +| | |---StateStylesSample.ets +|---pages +| |---Index.ets // 应用主页面 +entry/src/ohosTest/ +|---ets +| |---index.test.ets // 示例代码测试代码 +``` + +### 具体实现 + +stateStyles 通过为组件的不同内部状态(如 normal、focused、pressed 等) +绑定对应的样式规则,实现动态的多态视觉效果,其使用方式是在组件上调用 +.stateStyles({}) 方法,传入一个以状态名为键的对象,每个状态内通过链式调 +用设置通用样式属性,从而在用户交互时自动切换外观,提升用户体验。 + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.57。 + +3.本示例需要使用DevEco Studio NEXT Developer Preview2 (Build Version: 5.0.5.306, built on December 12, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkUISample/EventProject > .git/info/sparse-checkout +git remote add origin https://gitcode.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/ArkUIKit/StateStyle/build-profile.json5 b/ArkUIKit/StateStyle/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3ca5a93fb814017ac4c398aacbdf17b1d8b0a237 --- /dev/null +++ b/ArkUIKit/StateStyle/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * 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. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "6.0.0(20)", + "targetSdkVersion": "6.0.0(20)", + "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/ArkUIKit/StateStyle/code-linter.json5 b/ArkUIKit/StateStyle/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5c4682f8164874ec7e9cb8f99ff8b3228ffbc126 --- /dev/null +++ b/ArkUIKit/StateStyle/code-linter.json5 @@ -0,0 +1,46 @@ +/* + * 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. + */ +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/.gitignore b/ArkUIKit/StateStyle/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/build-profile.json5 b/ArkUIKit/StateStyle/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9016faf39f8a65cf648bae246a53575510fe8b9f --- /dev/null +++ b/ArkUIKit/StateStyle/entry/build-profile.json5 @@ -0,0 +1,47 @@ +/* + * 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. + */ +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "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/ArkUIKit/StateStyle/entry/hvigorfile.ts b/ArkUIKit/StateStyle/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..cfa8a00f74f409d9647f55cdf270ab6aec69fe41 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/hvigorfile.ts @@ -0,0 +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. + */ + +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. */ +} \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/obfuscation-rules.txt b/ArkUIKit/StateStyle/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkUIKit/StateStyle/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/ArkUIKit/StateStyle/entry/oh-package.json5 b/ArkUIKit/StateStyle/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/ArkUIKit/StateStyle/entry/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * 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. + */ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ArkUIKit/StateStyle/entry/ohosTest.md b/ArkUIKit/StateStyle/entry/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..df37d59f8784527a375e72c934bf5150ff999aa5 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/ohosTest.md @@ -0,0 +1,9 @@ +| 测试功能 | 预置条件 | 输入 | 预期输出 | 测试结果 | +| | ------------ | ---------------------- | --------------------------- | -------- | +| 首页加载测试 | 设备正常运行 | 验证基础元素渲染 | 检查标题和列表组件 | Pass | +| 基础场景测试 | 设备正常运行 | 点击button1 | 随点击变色 | Pass | +| 获焦变色测试 | 设备正常运行 | 长按"clickMe"" | 变为灰色 | Pass | + + + + diff --git a/ArkUIKit/StateStyle/entry/src/main/ets/common/resource.ets b/ArkUIKit/StateStyle/entry/src/main/ets/common/resource.ets new file mode 100644 index 0000000000000000000000000000000000000000..723a394265ee2e6bf6d895e9503c4b2d8e49207a --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/main/ets/common/resource.ets @@ -0,0 +1,25 @@ +/* + * 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. + */ + +export class P2PManager { + public resourceToString(resource: Resource): string { + return getContext(this).resourceManager.getStringSync(resource); + } +} + +// 默认导出let +let p2pManager = new P2PManager(); + +export default p2pManager as P2PManager; \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUIKit/StateStyle/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..081b700cacec6def24d204fbc37ab93985f7b4ec --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,95 @@ +/* + * 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 { display, uiObserver, window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +function callBackFunc(info: uiObserver.NavDestinationSwitchInfo) { + console.info(`testTag navDestinationSwitch from: ${JSON.stringify(info.from)} to: ${JSON.stringify(info.to)}`) +} + +function callBackFunc2(info: uiObserver.NavDestinationSwitchInfo) { + console.info(`testTag2 navDestinationSwitch from: ${JSON.stringify(info.from)} to: ${JSON.stringify(info.to)}`) +} + +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'); + uiObserver.on('navDestinationSwitch', this.context, callBackFunc); + uiObserver.on('navDestinationSwitch', this.context, { + navigationId: 'myNavId' + }, callBackFunc2); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + uiObserver.off('navDestinationSwitch', this.context, callBackFunc); + uiObserver.off('navDestinationSwitch', this.context, { + navigationId: 'myNavId' + }, callBackFunc); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + let mainWindow: window.Window; + try { + mainWindow = windowStage.getMainWindowSync(); + let displayClass: display.Display = display.getDefaultDisplaySync(); + AppStorage.setOrCreate('orientation', displayClass.orientation); + // 监听窗口的windowsSizeChange事件,旋转屏时会触发该事件 + mainWindow.on('windowSizeChange', (data) => { + console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data)); + let displayClass: display.Display | null = null; + try { + displayClass = display.getDefaultDisplaySync(); + console.info('display orientation is ' + JSON.stringify(displayClass.orientation)); + // 获取屏幕的显示方向 + AppStorage.set('orientation', displayClass.orientation); + } catch { + return; + } + }) + } catch { + hilog.info(0x0000, 'testTag', '%{public}s', 'error'); + return; + } + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkUIKit/StateStyle/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,30 @@ +/* + * 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'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/src/main/ets/pages/FocusStyle/CompWithInlineStateStyles.ets b/ArkUIKit/StateStyle/entry/src/main/ets/pages/FocusStyle/CompWithInlineStateStyles.ets new file mode 100644 index 0000000000000000000000000000000000000000..b2142aa519ada618b8d6e2abeb25689b70e73b04 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/main/ets/pages/FocusStyle/CompWithInlineStateStyles.ets @@ -0,0 +1,42 @@ +/* + * 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 focus_style] +@Entry +@Component +struct CompWithInlineStateStyles { + @State focusedColor: Color = 0xD5D5D5; + normalColor: Color = 0x004AAF; + + build() { + Column() { + Button('clickMe') + .height(100) + .width(100) + .stateStyles({ + normal: { + .backgroundColor(this.normalColor) + }, + focused: { + .backgroundColor(this.focusedColor) + } + }) + .onClick(() => { + this.focusedColor = 0x707070; + }) + .margin('30%') + } + } +} +// [End focus_style] \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/src/main/ets/pages/Index.ets b/ArkUIKit/StateStyle/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..bf5b7cdb6aaceed711c2986615213428f97aa21d --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,164 @@ +/* + * 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 curves from '@ohos.curves'; +import { Route, RouteGroup } from './common/Index'; +import { KeyboardAvoidMode } from '@kit.ArkUI'; +import router from '@ohos.router'; + +@Styles +function cardPressedStyle() { + .backgroundColor('rgba(0,0,0,0.1)') + .opacity(1) + .animation({ curve: curves.cubicBezierCurve(0.33, 0, 0.67, 1), duration: 100 }) +} + +@Styles +function cardNormalStyle() { + .backgroundColor('rgba(0,0,0,0)') + .opacity(1) + .animation({ curve: curves.cubicBezierCurve(0.33, 0, 0.67, 1), duration: 100 }) +} + +@Styles +function cardDisabledStyle() { + .backgroundColor('rgba(0,0,0,0)') + .opacity(0.5) + .animation({ curve: curves.cubicBezierCurve(0.33, 0, 0.67, 1), duration: 100 }) +} + + +@Entry +@Component +struct ComponentExtension { + @Provide('router') router: NavPathStack = new NavPathStack(); + @State routes: RouteGroup[] = [ + { + name: 'StateStyle', + label: $r('app.string.StateStyles'), + children: [ + { name: 'StateStylesSample', label: $r('app.string.StateStylesExample') }, + ] + }, + { + name: 'NormalStyle', + label: $r('app.string.MyComponent'), + children: [ + { name: 'MyComponent', label: $r('app.string.MyComponentExample') }, + ] + }, + { + name: 'FocusStyle', + label: $r('app.string.CompWithInlineStateStyles'), + children: [ + { name: 'CompWithInlineStateStyles', label: $r('app.string.CompWithInlineStateStylesExample') }, + ] + } + ]; + @State selection: string | null = null; + + @Builder + ListItemGroupHeader(route: RouteGroup) { + Row() { + Text(route.label) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .fontWeight(FontWeight.Medium) + + Blank() + + Text(`${route.children.length}`) + .fontColor($r('sys.color.ohos_id_color_text_secondary')) + .opacity(this.selection === route.name ? 0 : 1) + + Image($r('sys.media.ohos_ic_public_arrow_right')) + .fillColor($r('sys.color.ohos_id_color_fourth')) + .height(24) + .width(24) + .rotate({ angle: this.selection === route.name ? 90 : 0 }) + .animation({ curve: curves.interpolatingSpring(0, 1, 228, 30) }) + } + .borderRadius(20) + .width('100%') + .padding(8) + .enabled(!!route.children.length) + .stateStyles({ + pressed: cardPressedStyle, + normal: cardNormalStyle, + disabled: cardDisabledStyle, + }) + .onClick(() => { + animateTo( + { curve: curves.interpolatingSpring(0, 1, 228, 25) }, + () => { + if (this.selection === route.name) { + this.selection = null; + } else { + this.selection = route.name; + } + }); + }) + } + + aboutToAppear(): void{ + this.getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE); + } + build() { + Column() { + Text('ComponentExtension') + List() { + ForEach(this.routes, (routeGroup: RouteGroup) => { + ListItemGroup({ + header: this.ListItemGroupHeader(routeGroup), + style: ListItemGroupStyle.CARD, + }) { + if (routeGroup.name === this.selection) { + ForEach(routeGroup.children, (route: Route) => { + ListItem() { + Row() { + Text(route.label).fontSize(16) + Blank() + Image($r('sys.media.ohos_ic_public_arrow_right')) + .fillColor($r('sys.color.ohos_id_color_fourth')) + .height(24) + .width(24) + } + .stateStyles({ + pressed: cardPressedStyle, + normal: cardNormalStyle, + disabled: cardDisabledStyle, + }) + .borderRadius(20) + .padding(8) + .transition( + TransitionEffect.OPACITY.animation({ + curve: curves.interpolatingSpring(0, 1, 228, 30) + }) + ) + .width('100%') + .onClick(() => { + const name = `pages/${routeGroup.name}/${route.name}`; + router.pushUrl({url: name}); + }) + } + .width('100%') + }) + } + } + .padding(2) + .divider({ strokeWidth: 0.5 }) + }) + }.padding({bottom: 10}) + } + } +} \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/src/main/ets/pages/NormalStyle/MyComponent.ets b/ArkUIKit/StateStyle/entry/src/main/ets/pages/NormalStyle/MyComponent.ets new file mode 100644 index 0000000000000000000000000000000000000000..da04979f685c59cd54836e0d9faf97bdcaa97fe9 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/main/ets/pages/NormalStyle/MyComponent.ets @@ -0,0 +1,39 @@ +/* + * 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 normal_style] +@Entry +@Component +struct MyComponent { + @Styles normalStyle() { + .backgroundColor(Color.Gray) + } + + @Styles pressedStyle() { + .backgroundColor(Color.Red) + } + build() { + Column() { + Text('Text1') + .fontSize(50) + .fontColor(Color.White) + .stateStyles({ + normal: this.normalStyle, + pressed: this.pressedStyle, + }) + } + } +} +// [End normal_style] \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/src/main/ets/pages/StateStyle/StateStylesSample.ets b/ArkUIKit/StateStyle/entry/src/main/ets/pages/StateStyle/StateStylesSample.ets new file mode 100644 index 0000000000000000000000000000000000000000..8c9464cb10464de1157b7eaea493a396c9122d8b --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/main/ets/pages/StateStyle/StateStylesSample.ets @@ -0,0 +1,50 @@ +/* + * 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 state_style] +@Entry +@Component +struct StateStylesSample { + build() { + Column() { + Button('Button1') + .stateStyles({ + focused: { + .backgroundColor('#ffffeef0') + }, + pressed: { + .backgroundColor('#ff707070') + }, + normal: { + .backgroundColor('#ff2787d9') + } + }) + .margin(20) + Button('Button2') + .stateStyles({ + focused: { + .backgroundColor('#ffffeef0') + }, + pressed: { + .backgroundColor('#ff707070') + }, + normal: { + .backgroundColor('#ff2787d9') + } + }) + }.margin('30%') + } +} +// [End state_style] \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/src/main/ets/pages/common/Index.ets b/ArkUIKit/StateStyle/entry/src/main/ets/pages/common/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..02c5c6b987280c6731d3e40af7c56c416176a3af --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/main/ets/pages/common/Index.ets @@ -0,0 +1,23 @@ +/* + * 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. + */ + +export interface Route { + name: string; + label: ResourceStr; +} + +export interface RouteGroup extends Route { + children: Route[]; +} \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/src/main/module.json5 b/ArkUIKit/StateStyle/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..44e30abf324bffa0b0c832125d835c1de2cf9bc9 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/main/module.json5 @@ -0,0 +1,65 @@ +/* + * 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default" + ], + "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": [ + "ohos.want.action.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/ArkUIKit/StateStyle/entry/src/main/resources/base/element/color.json b/ArkUIKit/StateStyle/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkUIKit/StateStyle/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/ArkUIKit/StateStyle/entry/src/main/resources/base/element/float.json b/ArkUIKit/StateStyle/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/ArkUIKit/StateStyle/entry/src/main/resources/base/element/string.json b/ArkUIKit/StateStyle/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c7a9e5ca413b178718ef38892315e791d0442e90 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/main/resources/base/element/string.json @@ -0,0 +1,64 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "parent", + "value": "生命周期" + }, + { + "name": "parentExample", + "value": "自定义组件生命周期" + }, + { + "name": "AnimatablePropertyText", + "value": "动画装饰器2" + }, + { + "name": "StylesDecorator", + "value": "Style装饰器" + }, + { + "name": "fancyAndglobalFancy", + "value": "Style装饰器1" + }, + { + "name": "FancyUse", + "value": "Style装饰器2" + }, + { + "name": "StateStyles", + "value": "基础场景" + }, + { + "name": "StateStylesExample", + "value": "基础场景示例" + }, + { + "name": "MyComponent", + "value": "按压态" + }, + { + "name": "MyComponentExample", + "value": "按压态示例" + }, + { + "name": "CompWithInlineStateStyles", + "value": "获焦变色" + }, + { + "name": "CompWithInlineStateStylesExample", + "value": "获焦变色示例" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/src/main/resources/base/media/background.png b/ArkUIKit/StateStyle/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ArkUIKit/StateStyle/entry/src/main/resources/base/media/background.png differ diff --git a/ArkUIKit/StateStyle/entry/src/main/resources/base/media/foreground.png b/ArkUIKit/StateStyle/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ArkUIKit/StateStyle/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkUIKit/StateStyle/entry/src/main/resources/base/media/layered_image.json b/ArkUIKit/StateStyle/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/StateStyle/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/ArkUIKit/StateStyle/entry/src/main/resources/base/media/startIcon.png b/ArkUIKit/StateStyle/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ArkUIKit/StateStyle/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkUIKit/StateStyle/entry/src/main/resources/base/profile/backup_config.json b/ArkUIKit/StateStyle/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/src/main/resources/base/profile/main_pages.json b/ArkUIKit/StateStyle/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..bdce0c21044f47dd940418949dec745b6f28b4f2 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,8 @@ +{ + "src": [ + "pages/Index", + "pages/StateStyle/StateStylesSample", + "pages/NormalStyle/MyComponent", + "pages/FocusStyle/CompWithInlineStateStyles" + ] +} diff --git a/ArkUIKit/StateStyle/entry/src/main/resources/dark/element/color.json b/ArkUIKit/StateStyle/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/src/mock/mock-config.json5 b/ArkUIKit/StateStyle/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/mock/mock-config.json5 @@ -0,0 +1,16 @@ +/* + * 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. + */ +{ +} \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkUIKit/StateStyle/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/src/ohosTest/ets/test/List.test.ets b/ArkUIKit/StateStyle/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..69a4acf0c78a039177ffdfc09b92be284aa58463 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * 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 StateStyleTest from './StateStyle.test'; + +export default function testsuite() { + StateStyleTest(); +} \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/src/ohosTest/ets/test/StateStyle.test.ets b/ArkUIKit/StateStyle/entry/src/ohosTest/ets/test/StateStyle.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..544e23b287e4f8be840a120fe72b6acfbb780afa --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/ohosTest/ets/test/StateStyle.test.ets @@ -0,0 +1,96 @@ +/* + * 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 { describe, it, expect, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON, MatchPattern } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function ParentTest() { + describe('StateStyleTest', () => { + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + let driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + + /** + * @tc.number StateStyle_0100 + * @tc.name testStateStyle_0100 + * @tc.desc 测试多态样式 + */ + it('StateStyle_0100', 0, async (done: Function) => { + let driver = Driver.create(); + let button = await driver.findComponent(ON.text('基础场景', MatchPattern.CONTAINS)); + await button.click(); + let button1 = await driver.findComponent(ON.text('基础场景示例', MatchPattern.CONTAINS)); + await button1.click(); + let button2 = await driver.findComponent(ON.text('Button1', MatchPattern.CONTAINS)); + await button2.click(); + await driver.delayMs(2000); + await driver.pressBack(); + done(); + }) + + /** + * @tc.number StateStyle_0200 + * @tc.name testStateStyle_0200 + * @tc.desc 测试多态样式 + */ + it('StateStyle_0200', 0, async (done: Function) => { + let driver = Driver.create(); + let button = await driver.findComponent(ON.text('按压态', MatchPattern.CONTAINS)); + await button.click(); + let button1 = await driver.findComponent(ON.text('按压态示例', MatchPattern.CONTAINS)); + await button1.click(); + let button2 = await driver.findComponent(ON.text('Text1', MatchPattern.CONTAINS)); + await button2.click(); + await driver.delayMs(2000); + await driver.pressBack(); + done(); + }) + + /** + * @tc.number StateStyle_0300 + * @tc.name testStateStyle_0300 + * @tc.desc 测试多态样式 + */ + it('StateStyle_0300', 0, async (done: Function) => { + let driver = Driver.create(); + let button = await driver.findComponent(ON.text('获焦变色', MatchPattern.CONTAINS)); + await button.click(); + let button1 = await driver.findComponent(ON.text('获焦变色示例', MatchPattern.CONTAINS)); + await button1.click(); + let button2 = await driver.findComponent(ON.text('clickMe', MatchPattern.CONTAINS)); + await button2.click(); + await driver.delayMs(2000); + await driver.pressBack(); + done(); + }) + }) +} \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/src/ohosTest/module.json5 b/ArkUIKit/StateStyle/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..84d30586d591412f4252801cc483bbc6d8554104 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/ohosTest/module.json5 @@ -0,0 +1,26 @@ +/* + * 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkUIKit/StateStyle/entry/src/test/List.test.ets b/ArkUIKit/StateStyle/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * 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 localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkUIKit/StateStyle/entry/src/test/LocalUnit.test.ets b/ArkUIKit/StateStyle/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/ArkUIKit/StateStyle/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkUIKit/StateStyle/hvigor/hvigor-config.json5 b/ArkUIKit/StateStyle/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b057578a1bb4d591ee53054e39ab0154fc2e43a --- /dev/null +++ b/ArkUIKit/StateStyle/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * 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. + */ +{ + "modelVersion": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | 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 */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "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/ArkUIKit/StateStyle/hvigorfile.ts b/ArkUIKit/StateStyle/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3340f07e45ddc5dcadbb87012668555def2e6e0 --- /dev/null +++ b/ArkUIKit/StateStyle/hvigorfile.ts @@ -0,0 +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. + */ + +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. */ +} \ No newline at end of file diff --git a/ArkUIKit/StateStyle/oh-package.json5 b/ArkUIKit/StateStyle/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..69cb43cba3addcee1840403c67405134a2a9102c --- /dev/null +++ b/ArkUIKit/StateStyle/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * 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. + */ + +{ + "modelVersion": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + } +} diff --git a/ArkUIKit/StateStyle/screenshots/device/image1.png b/ArkUIKit/StateStyle/screenshots/device/image1.png new file mode 100644 index 0000000000000000000000000000000000000000..0c095852957cdfc55b7798c5181b1ab3eccc22ae Binary files /dev/null and b/ArkUIKit/StateStyle/screenshots/device/image1.png differ diff --git a/ArkUIKit/StateStyle/screenshots/device/image2.png b/ArkUIKit/StateStyle/screenshots/device/image2.png new file mode 100644 index 0000000000000000000000000000000000000000..3e758bcc3f9c4fa8573a5e1e5b8b0d7d5cf51625 Binary files /dev/null and b/ArkUIKit/StateStyle/screenshots/device/image2.png differ diff --git a/ArkUIKit/StateStyle/screenshots/device/image3.png b/ArkUIKit/StateStyle/screenshots/device/image3.png new file mode 100644 index 0000000000000000000000000000000000000000..1000f8e2273fbd7415bf45d91b8760ceb0dfc413 Binary files /dev/null and b/ArkUIKit/StateStyle/screenshots/device/image3.png differ diff --git a/ArkUIKit/statemanagementproject/AppScope/app.json5 b/ArkUIKit/statemanagementproject/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f7aed61164ee0e77e2b2b21985b338b6c92df211 --- /dev/null +++ b/ArkUIKit/statemanagementproject/AppScope/app.json5 @@ -0,0 +1,24 @@ +/* + * 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. + */ +{ + "app": { + "bundleName": "com.samples.statemanagementproject", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/ArkUIKit/statemanagementproject/AppScope/resources/base/element/string.json b/ArkUIKit/statemanagementproject/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..13a613e8fccccf05502e2bd282e778580b091cee --- /dev/null +++ b/ArkUIKit/statemanagementproject/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "CustomCanvas" + } + ] +} diff --git a/ArkUIKit/statemanagementproject/AppScope/resources/base/media/background.png b/ArkUIKit/statemanagementproject/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..b400ac8bc6cbc645e41bbf7c2dd1e2875a05852f Binary files /dev/null and b/ArkUIKit/statemanagementproject/AppScope/resources/base/media/background.png differ diff --git a/ArkUIKit/statemanagementproject/AppScope/resources/base/media/foreground.png b/ArkUIKit/statemanagementproject/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..e58ebabb168e1b4a6cc0a07d13676ea0613ba69e Binary files /dev/null and b/ArkUIKit/statemanagementproject/AppScope/resources/base/media/foreground.png differ diff --git a/ArkUIKit/statemanagementproject/AppScope/resources/base/media/layered_image.json b/ArkUIKit/statemanagementproject/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/statemanagementproject/AppScope/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/ArkUIKit/statemanagementproject/README_zh.md b/ArkUIKit/statemanagementproject/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..0eb920cc07c5716d76a481e5178017d522bc7585 --- /dev/null +++ b/ArkUIKit/statemanagementproject/README_zh.md @@ -0,0 +1,88 @@ +# 状态管理合理使用开发指导 + +### 介绍 + +statemanagementguide +本示例通过使用[ArkUI指南文档](https://gitcode.com/openharmony/docs/tree/master/zh-cn/application-dev/ui) +中各场景的开发示例,展示在工程中,帮助开发者更好地理解ArkUI提供的组件及组件属性并合理使用。该工程中展示的代码详细描述可查如下链接: + +1. [合理使用属性](https://gitcode.com/tianlongdevcode/docs_zh/blob/master/zh-cn/application-dev/ui/state-management/properly-use-state-management-to-develope.md)。 + +### 1. [合理使用属性] + +### 效果预览 + +| 首页 | statemanagementguide示例 +|------------------------------------|------------------------------------| +| ![](screenshots/device/image1.png) | ![](screenshots/device/image2.png) | + +### 使用说明 + +1. 在主界面,可以点击对应卡片,选择需要参考的组件示例。 + +2. 在组件目录选择详细的示例参考。 + +3. 进入示例界面,查看参考示例。 + +4. 通过自动测试框架可进行测试及维护。 + +### 工程目录 + +``` +entry/src/main/ets/ +|---entryability +|---pages +| |---statemanagementguide //状态管理合理使用 +| | |---StateArray.ets +| | |---StateArrayBig.ets +| | |---StateArrayForeach.ets +| | |---StateArrayForeach2.ets +| | |---StateArrayInit.ets +| | |---StateArrayLazy.ets +| | |---StateArrayLazy2.ets +| | |---StateArrayLoadDate.ets +| | |---StateArrayNo.ets +| | |---StateArrayObserved.ets +| | |---StateArrayPrecise.ets +| | |---StateArrayTrack.ets +| | |---StateArrayUpdate.ets +|---pages +| |---Index.ets // 应用主页面 +entry/src/ohosTest/ +|---ets +| |---StateManagementGuide.test.ets // 状态管理合理使用示例代码测试代码 +``` + +### 具体实现 + +实现状态管理合理使用,以下是详细实现过程: +1、点击某一条信息中年龄的Text组件时,可以通过日志发现的19条信息中年龄的Text组件也进行了刷新 +2、点击“X”按钮删除其中一条内容时,变量childList就能够观测到变化,触发了ForEach的刷新,最终UI渲染刷新 + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:RK3568。 + +2.本示例为Stage模型,支持API21版本SDK,版本号:6.0.0.254,镜像版本号:OpenHarmony_6.0.2.57。 + +3.本示例需要使用DevEco Studio NEXT Developer Preview2 (Build Version: 6.0.5.306, built on December 12, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkUISample/StateManagementProject > .git/info/sparse-checkout +git remote add origin https://gitCode.com/openharmony/applications_app_samples.git +git pull origin master +```` \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/build-profile.json5 b/ArkUIKit/statemanagementproject/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e84d1f851a1b6439c6a36dd3350ffa8ea1f46751 --- /dev/null +++ b/ArkUIKit/statemanagementproject/build-profile.json5 @@ -0,0 +1,56 @@ +/* + * 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. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "6.0.0(20)", + "compatibleSdkVersion": "6.0.0(20)", + "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/ArkUIKit/statemanagementproject/code-linter.json5 b/ArkUIKit/statemanagementproject/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..039b73502077ce0501502ab4331c1d0d8dedf7d0 --- /dev/null +++ b/ArkUIKit/statemanagementproject/code-linter.json5 @@ -0,0 +1,47 @@ +/* + * 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. + */ +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error", + "@performance/lottie-animation-destroy-check": "suggestion" + } +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/build-profile.json5 b/ArkUIKit/statemanagementproject/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9016faf39f8a65cf648bae246a53575510fe8b9f --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/build-profile.json5 @@ -0,0 +1,47 @@ +/* + * 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. + */ +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "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/ArkUIKit/statemanagementproject/entry/hvigorfile.ts b/ArkUIKit/statemanagementproject/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8b117a17af3b2d7cb87a7680e29e2bb8ccd5b46 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * 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 { 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. */ +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/obfuscation-rules.txt b/ArkUIKit/statemanagementproject/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ArkUIKit/statemanagementproject/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/ArkUIKit/statemanagementproject/entry/oh-package.json5 b/ArkUIKit/statemanagementproject/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7101339c029488d56063666b6d40f444716d1537 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/oh-package.json5 @@ -0,0 +1,27 @@ +/* + * 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. + */ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + // Lottie模块 + "@ohos/lottie": "^2.0.24" + } +} + diff --git a/ArkUIKit/statemanagementproject/entry/src/main/ets/entryability/EntryAbility.ets b/ArkUIKit/statemanagementproject/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..98182799de1294d4c21194646a0c30eff08aea33 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,62 @@ +/* + * 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'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + try { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + } catch (err) { + hilog.error(DOMAIN, 'testTag', 'Failed to set colorMode. Cause: %{public}s', JSON.stringify(err)); + } + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ArkUIKit/statemanagementproject/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,30 @@ +/* + * 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'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/Index.ets b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..26b3b8d092558e32749297751aa59e544afd243e --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,134 @@ +/* + * 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 router from '@ohos.router' +interface listItem { + router?: string; + name: string; + description?: string; +} + +let demandList: listItem[] = [ + { + name: 'StateArray', + router: 'pages/statemanagementguide/StateArray', + }, + { + name: 'StateArrayNo', + router: 'pages/statemanagementguide/StateArrayNo', + }, + { + name: 'StateArrayLazy', + router: 'pages/statemanagementguide/StateArrayLazy', + }, + { + name: 'StateArrayForeach', + router: 'pages/statemanagementguide/StateArrayForeach', + }, + { + name: 'StateArrayForeach2', + router: 'pages/statemanagementguide/StateArrayForeach2', + }, + { + name: 'StateArrayBig', + router: 'pages/statemanagementguide/StateArrayBig', + }, + { + name: 'StateArrayForeach2', + router: 'pages/statemanagementguide/StateArrayForeach2', + }, + { + name: 'StateArrayInit', + router: 'pages/statemanagementguide/StateArrayInit', + }, + { + name: 'StateArrayLazy2', + router: 'pages/statemanagementguide/StateArrayLazy2', + }, + { + name: 'StateArrayLoadDate', + router: 'pages/statemanagementguide/StateArrayLoadDate', + }, + { + name: 'StateArrayObserved', + router: 'pages/statemanagementguide/StateArrayObserved', + }, { + name: 'StateArrayPrecise', + router: 'pages/statemanagementguide/StateArrayPrecise', +}, + { + name: 'StateArrayTrack', + router: 'pages/statemanagementguide/StateArrayTrack', + }, { + name: 'StateArrayUpdate', + router: 'pages/statemanagementguide/StateArrayUpdate', +}, + + +] + +@Entry +@Component +struct Index { + @State bgColor: ResourceColor = '#39b5fa'; + + build() { + Column() { + Text($r('app.string.state_layout')) + .height('5%') + .width('100%') + .textAlign(TextAlign.Center) + .fontSize(15) + .fontWeight(FontWeight.Bold) + .backgroundColor(this.bgColor) + .fontColor(Color.White) + + Column() { + List({ space: 20, initialIndex: 0 }) { + ForEach(demandList, (listitem: listItem, index: number) => { + ListItem() { + Column() { + Text(listitem.name) + .fontSize(15) + .fontColor(this.bgColor) + .maxLines(1) + } + .onClick(() => { + if (!!listitem.router) { + this.getUIContext().getRouter().pushUrl({ url: listitem.router }) + } + }) + } + }) + } + .listDirection(Axis.Vertical) + .scrollBar(BarState.Off) + .friction(0.6) + .divider({ + strokeWidth: 2, + color: 0xFFFFFF, + startMargin: 20, + endMargin: 20 + }) + .edgeEffect(EdgeEffect.Spring) + .contentEndOffset(50) + .width('90%') + } + .width('100%') + // .height('100%') + .backgroundColor('#fff4f3f3') + .padding({ top: 5 }) + } + } +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArray.ets b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArray.ets new file mode 100644 index 0000000000000000000000000000000000000000..f0db3b9895fadbc2f5f7c43576f9ee680fad1272 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArray.ets @@ -0,0 +1,93 @@ +/* + * 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 TextComponent1_start] +import { hilog } from '@kit.PerformanceAnalysisKit'; +const DOMAIN_NUMBER: number = 0XFF00; +const TAG: string = '[EvtryAblity]'; + +@Entry +@Component +struct Index { + @State items: string[] = []; + @State ids: string[] = []; + @State age: number[] = []; + @State gender: string[] = []; + + aboutToAppear() { + this.items.push('Head'); + this.items.push('List'); + for (let i = 0; i < 20; i++) { + this.ids.push('id: ' + Math.floor(Math.random() * 1000)); + this.age.push(Math.floor(Math.random() * 100 % 40)); + this.gender.push(Math.floor(Math.random() * 100) % 2 == 0 ? 'Male' : 'Female'); + } + } + + isRenderText(index: number): number { + hilog.info(DOMAIN_NUMBER, TAG, `index ${index} is rendered`); + return 1; + } + + build() { + Row() { + Column() { + ForEach(this.items, (item: string) => { + if (item == 'Head') { + Text('Personal Info') + .fontSize(40) + } else if (item == 'List') { + List() { + ForEach(this.ids, (id: string, index) => { + ListItem() { + Row() { + Text(id) + .fontSize(20) + .margin({ + left: 30, + right: 5 + }) + Text('age: ' + this.age[index as number]) + .fontSize(20) + .margin({ + left: 5, + right: 5 + }) + .position({ x: 100 }) + .opacity(this.isRenderText(index)) + .onClick(() => { + this.age[index]++; + }) + Text('gender: ' + this.gender[index as number]) + .margin({ + left: 5, + right: 5 + }) + .position({ x: 180 }) + .fontSize(20) + } + } + .margin({ + top: 5, + bottom: 5 + }) + }) + } + } + }) + } + } + } +} +// [End TextComponent1_start] \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayBig.ets b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayBig.ets new file mode 100644 index 0000000000000000000000000000000000000000..24a0e8bb5e2b64ace14a6b615cc70002647ec8f9 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayBig.ets @@ -0,0 +1,183 @@ +/* + * 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 StateArrayBig_start] +import { hilog } from '@kit.PerformanceAnalysisKit'; +const DOMAIN_NUMBER: number = 0XFF00; +const TAG: string = '[EvtryAblity]'; + +@Observed +class UiStyle3 { + public translateX: number = 0; + public translateY: number = 0; + public scaleX: number = 0.3; + public scaleY: number = 0.3; + public width: number = 336; + public height: number = 178; + public posX: number = 10; + public posY: number = 50; + public alpha: number = 0.5; + public borderRadius: number = 24; + public imageWidth: number = 78; + public imageHeight: number = 78; + public translateImageX: number = 0; + public translateImageY: number = 0; + public fontSize: number = 20; +} + +@Component +struct SpecialImage { + @ObjectLink uiStyle: UiStyle3; + + private isRenderSpecialImage(): number { // 显示组件是否渲染的函数 + hilog.info(DOMAIN_NUMBER, TAG, 'SpecialImage is rendered'); + return 1; + } + + build() { + Image($r('app.media.startIcon')) // 此处'app.media.icon'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 + .width(this.uiStyle.imageWidth) + .height(this.uiStyle.imageHeight) + .margin({ top: 20 }) + .translate({ + x: this.uiStyle.translateImageX, + y: this.uiStyle.translateImageY + }) + .opacity(this.isRenderSpecialImage()) // 如果Image重新渲染,该函数将被调用 + } +} + +@Component +struct PageChild3 { + @ObjectLink uiStyle: UiStyle3 + + // 下面的函数用于显示组件是否被渲染 + private isRenderColumn(): number { + hilog.info(DOMAIN_NUMBER, TAG, 'Column is rendered'); + return 1; + } + + private isRenderStack(): number { + hilog.info(DOMAIN_NUMBER, TAG, 'Stack is rendered'); + return 1; + } + + private isRenderImage(): number { + hilog.info(DOMAIN_NUMBER, TAG, 'Image is rendered'); + return 1; + } + + private isRenderText(): number { + hilog.info(DOMAIN_NUMBER, TAG, 'Text is rendered'); + return 1; + } + + build() { + Column() { + SpecialImage({ + uiStyle: this.uiStyle + }) + Stack() { + Column() { + Image($r('app.media.startIcon')) // 此处'app.media.icon'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 + .opacity(this.uiStyle.alpha) + .scale({ + x: this.uiStyle.scaleX, + y: this.uiStyle.scaleY + }) + .padding(this.isRenderImage()) + .width(300) + .height(300) + } + .width('100%') + .position({ y: -80 }) + + Stack() { + Text('Hello World') + .fontColor('#182431') + .fontWeight(FontWeight.Medium) + .fontSize(this.uiStyle.fontSize) + .opacity(this.isRenderText()) + .margin({ top: 12 }) + } + .opacity(this.isRenderStack()) + .position({ + x: this.uiStyle.posX, + y: this.uiStyle.posY + }) + .width('100%') + .height('100%') + } + .margin({ top: 50 }) + .borderRadius(this.uiStyle.borderRadius) + .opacity(this.isRenderStack()) + .backgroundColor('FFFFFF') + .width(this.uiStyle.width) + .height(this.uiStyle.height) + .translate({ + x: this.uiStyle.translateX, + y: this.uiStyle.translateY + }) + + Column() { + Button('Move') + .width(312) + .fontSize(20) + .backgroundColor('#FF007DFF') + .margin({ bottom: 10 }) + .onClick(() => { + this.getUIContext().animateTo({ + duration: 500 + }, () => { + this.uiStyle.translateY = (this.uiStyle.translateY + 180) % 250; + }) + }) + Button('Scale') + .borderRadius(20) + .backgroundColor('#FF007DFF') + .fontSize(20) + .width(312) + .onClick(() => { + this.uiStyle.scaleX = (this.uiStyle.scaleX + 0.6) % 0.8; + }) + } + .position({ + y: 666 + }) + .height('100%') + .width('100%') + + } + .opacity(this.isRenderColumn()) + .width('100%') + .height('100%') + + } +} + +@Entry +@Component +struct Page3 { + @State uiStyle: UiStyle3 = new UiStyle3(); + + build() { + Stack() { + PageChild3({ + uiStyle: this.uiStyle + }) + } + .backgroundColor('#F1F3F5') + } +} +// [End StateArrayBig_start] \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayForeach.ets b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayForeach.ets new file mode 100644 index 0000000000000000000000000000000000000000..7a367d707d96e54392b7f41f32bf25e269844f09 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayForeach.ets @@ -0,0 +1,65 @@ +/* + * 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 StateArrayForeach_start] +import { hilog } from '@kit.PerformanceAnalysisKit'; +const DOMAIN_NUMBER: number = 0XFF00; +const TAG: string = '[EvtryAblity]'; + +@Observed +class StyleList12 extends Array { +}; + +@Observed +class TextStyles12 { + public fontSize: number; + + constructor(fontSize: number) { + this.fontSize = fontSize; + } +} + +@Entry +@Component +struct Page12 { + @State styleList: StyleList12 = new StyleList12(); + + aboutToAppear() { + for (let i = 15; i < 50; i++) { + this.styleList.push(new TextStyles12(i)); + } + } + + build() { + Column() { + Text('Font Size List') + .fontSize(50) + .onClick(() => { + for (let i = 0; i < this.styleList.length; i++) { + this.styleList[i].fontSize++; + } + hilog.info(DOMAIN_NUMBER, TAG, 'change font size'); + }) + List() { + ForEach(this.styleList, (item: TextStyles12) => { + ListItem() { + Text('Hello World') + .fontSize(item.fontSize) + } + }) + } + } + } +} +// [End StateArrayForeach_start] \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayForeach2.ets b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayForeach2.ets new file mode 100644 index 0000000000000000000000000000000000000000..cb7c5306710835a8bf358728cf61b54ab442ba82 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayForeach2.ets @@ -0,0 +1,74 @@ +/* + * 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 TextComponent13_start] +import { hilog } from '@kit.PerformanceAnalysisKit'; +const DOMAIN_NUMBER: number = 0XFF00; +const TAG: string = '[EvtryAblity]'; + +@Observed +class StyleList extends Array { +}; + +@Observed +class TextStyles13 { + public fontSize: number; + + constructor(fontSize: number) { + this.fontSize = fontSize; + } +} + +@Component +struct TextComponent13 { + @ObjectLink textStyle13: TextStyles13; + + build() { + Text('Hello World') + .fontSize(this.textStyle13.fontSize) + } +} + +@Entry +@Component +struct Page13 { + @State styleList: StyleList = new StyleList(); + + aboutToAppear() { + for (let i = 15; i < 50; i++) { + this.styleList.push(new TextStyles13(i)); + } + } + + build() { + Column() { + Text('Font Size List') + .fontSize(50) + .onClick(() => { + for (let i = 0; i < this.styleList.length; i++) { + this.styleList[i].fontSize++; + } + hilog.info(DOMAIN_NUMBER, TAG, 'change font size'); + }) + List() { + ForEach(this.styleList, (item: TextStyles13) => { + ListItem() { + TextComponent13({ textStyle13: item }) + } + }) + } + } + } +} +// [End TextComponent13_start] \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayInit.ets b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayInit.ets new file mode 100644 index 0000000000000000000000000000000000000000..8059a1fbea4da33cde4655f9dadf5fea5822609e --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayInit.ets @@ -0,0 +1,166 @@ +/* + * 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 StateArrayInit_start] +import { hilog } from '@kit.PerformanceAnalysisKit'; +const DOMAIN_NUMBER: number = 0XFF00; +const TAG: string = '[EvtryAblity]'; + +@Observed +class StateArrayInitChild { + public count: number; + + constructor(count: number) { + this.count = count + } +} + +@Observed +class StateArrayInitChildList extends Array { + constructor(children?: StateArrayInitChild[]) { + super(); + if (children) { + this.push(...children); + } + } +} +; + +@Observed +class StateArrayInitAncestor { + public childList: StateArrayInitChildList; + + constructor(childList: StateArrayInitChildList) { + this.childList = childList; + } + + public loadData() { + let tempList = + new StateArrayInitChildList([new StateArrayInitChild(1), new StateArrayInitChild(2), new StateArrayInitChild(3), + new StateArrayInitChild(4), new StateArrayInitChild(5)]); + this.childList = tempList; + } + + public clearData() { + this.childList = new StateArrayInitChildList(); + } +} + +@Component +struct StateArrayInit { + @Link childList: StateArrayInitChildList; + @ObjectLink stateArrayInitchild: StateArrayInitChild; + + build() { + Row() { + Text(this.stateArrayInitchild.count + '') + .height(70) + .fontSize(20) + .borderRadius({ topLeft: 6, topRight: 6 }) + .margin({ left: 50 }) + Button('X') + .id('X') + .backgroundColor(Color.Red) + .onClick(() => { + let index = this.childList.findIndex((item) => { + return item.count === this.stateArrayInitchild.count + }) + if (index !== -1) { + this.childList.splice(index, 1); + } + }) + .margin({ left: 200, right: 30 }) + } + .margin({ + top: 15, + left: 15, + right: 10, + bottom: 15 + }) + .borderRadius(6) + .backgroundColor(Color.Grey) + } +} + +@Component +struct StateArrayInitCompList { + @ObjectLink @Watch('changeChildList') stateArrayInitchildList: StateArrayInitChildList; + + changeChildList() { + hilog.info(DOMAIN_NUMBER, TAG, 'CompList ChildList change'); + } + + isRenderCompChild(index: number): number { + hilog.info(DOMAIN_NUMBER, TAG, 'Comp Child is render' + index); + return 1; + } + + build() { + Column() { + List() { + ForEach(this.stateArrayInitchildList, (item: StateArrayInitChild, index) => { + ListItem() { + StateArrayInit({ + childList: this.stateArrayInitchildList, + stateArrayInitchild: item + }) + .opacity(this.isRenderCompChild(index)) + } + }) + } + .height('70%') + } + } +} + +@Component +struct StateArrayInitCompAncestor { + @ObjectLink stateArrayInitancestor: StateArrayInitAncestor; + + build() { + Column() { + StateArrayInitCompList({ stateArrayInitchildList: this.stateArrayInitancestor.childList }) + Row() { + Button('Clear') + .onClick(() => { + this.stateArrayInitancestor.clearData() + }) + .width(100) + .margin({ right: 50 }) + Button('Recover') + .onClick(() => { + this.stateArrayInitancestor.loadData() + }) + .width(100) + } + } + } +} + +@Entry +@Component +struct StateArrayInitPage { + // [StartExclude StateArrayInit_start] + @State childList: StateArrayInitChildList = + new StateArrayInitChildList([new StateArrayInitChild(1), new StateArrayInitChild(2), new StateArrayInitChild(3), + new StateArrayInitChild(4), new StateArrayInitChild(5)]); + @State ancestor: StateArrayInitAncestor = new StateArrayInitAncestor(this.childList) + // [StartExclude StateArrayInit_end] + build() { + Column() { + StateArrayInitCompAncestor({ stateArrayInitancestor: this.ancestor }) + } + } +} +// [End StateArrayInit_start] \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayLazy.ets b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayLazy.ets new file mode 100644 index 0000000000000000000000000000000000000000..a5548327c970dd767aa4b481dec27a38afed2eb2 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayLazy.ets @@ -0,0 +1,151 @@ +/* + * 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 StateArrayLazy_start] +import { hilog } from '@kit.PerformanceAnalysisKit'; +const DOMAIN_NUMBER: number = 0XFF00; +const TAG: string = '[EvtryAblity]'; + +class BasicDataSource implements IDataSource { + private listeners: DataChangeListener[] = []; + private originDataArray: StringData2[] = []; + + public totalCount(): number { + return 0; + } + + public getData(index: number): StringData2 { + return this.originDataArray[index]; + } + + registerDataChangeListener(listener: DataChangeListener): void { + if (this.listeners.indexOf(listener) < 0) { + hilog.info(DOMAIN_NUMBER, TAG, 'add listener'); + this.listeners.push(listener); + } + } + + unregisterDataChangeListener(listener: DataChangeListener): void { + const pos = this.listeners.indexOf(listener); + if (pos >= 0) { + hilog.info(DOMAIN_NUMBER, TAG, 'remove listener'); + this.listeners.splice(pos, 1); + } + } + + notifyDataReload(): void { + this.listeners.forEach(listener => { + listener.onDataReloaded(); + }) + } + + notifyDataAdd(index: number): void { + this.listeners.forEach(listener => { + listener.onDataAdd(index); + }) + } + + notifyDataChange(index: number): void { + this.listeners.forEach(listener => { + listener.onDataChange(index); + }) + } + + notifyDataDelete(index: number): void { + this.listeners.forEach(listener => { + listener.onDataDelete(index); + }) + } + + notifyDataMove(from: number, to: number): void { + this.listeners.forEach(listener => { + listener.onDataMove(from, to); + }) + } +} + +class MyDataSource9 extends BasicDataSource { + private dataArray: StringData2[] = []; + + public totalCount(): number { + return this.dataArray.length; + } + + public getData(index: number): StringData2 { + return this.dataArray[index]; + } + + public addData(index: number, data: StringData2): void { + this.dataArray.splice(index, 0, data); + this.notifyDataAdd(index); + } + + public pushData(data: StringData2): void { + this.dataArray.push(data); + this.notifyDataAdd(this.dataArray.length - 1); + } + + public reloadData(): void { + this.notifyDataReload(); + } +} + +class StringData2 { + public message: string; + public imgSrc: Resource; + + constructor(message: string, imgSrc: Resource) { + this.message = message; + this.imgSrc = imgSrc; + } +} + +@Entry +@Component +struct MyComponent8 { + private data: MyDataSource9 = new MyDataSource9(); + + aboutToAppear() { + for (let i = 0; i <= 9; i++) { + // 此处'app.media.icon'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 + this.data.pushData(new StringData2(`Click to add ${i}`, $r('app.media.startIcon'))); + } + } + + build() { + List({ space: 3 }) { + LazyForEach(this.data, (item: StringData2, index: number) => { + ListItem() { + Column() { + Text(item.message).fontSize(20) + .onAppear(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'text appear:' + item.message); + }) + Image(item.imgSrc) + .width(100) + .height(100) + .onAppear(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'image appear'); + }) + }.margin({ left: 10, right: 10 }) + } + .onClick(() => { + item.message += '0'; + this.data.reloadData(); + }) + }, (item: StringData2, index: number) => JSON.stringify(item)) + }.cachedCount(5) + } +} +// [End StateArrayLazy_start] \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayLazy2.ets b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayLazy2.ets new file mode 100644 index 0000000000000000000000000000000000000000..9f6163854ee757d0740fd4a84bce393f4a7a9cdf --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayLazy2.ets @@ -0,0 +1,152 @@ +/* + * 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 StateArrayLazy2_start] +import { hilog } from '@kit.PerformanceAnalysisKit'; +const DOMAIN_NUMBER: number = 0XFF00; +const TAG: string = '[EvtryAblity]'; + +class BasicDataSource9 implements IDataSource { + private listeners: DataChangeListener[] = []; + private originDataArray: StringData[] = []; + + public totalCount(): number { + return 0; + } + + public getData(index: number): StringData { + return this.originDataArray[index]; + } + + registerDataChangeListener(listener: DataChangeListener): void { + if (this.listeners.indexOf(listener) < 0) { + hilog.info(DOMAIN_NUMBER, TAG, 'add listener'); + this.listeners.push(listener); + } + } + + unregisterDataChangeListener(listener: DataChangeListener): void { + const pos = this.listeners.indexOf(listener); + if (pos >= 0) { + hilog.info(DOMAIN_NUMBER, TAG, 'remove listener'); + this.listeners.splice(pos, 1); + } + } + + notifyDataReload(): void { + this.listeners.forEach(listener => { + listener.onDataReloaded(); + }) + } + + notifyDataAdd(index: number): void { + this.listeners.forEach(listener => { + listener.onDataAdd(index); + }) + } + + notifyDataChange(index: number): void { + this.listeners.forEach(listener => { + listener.onDataChange(index); + }) + } + + notifyDataDelete(index: number): void { + this.listeners.forEach(listener => { + listener.onDataDelete(index); + }) + } + + notifyDataMove(from: number, to: number): void { + this.listeners.forEach(listener => { + listener.onDataMove(from, to); + }) + } +} + +class MyDataSource extends BasicDataSource9 { + private dataArray: StringData[] = []; + + public totalCount(): number { + return this.dataArray.length; + } + + public getData(index: number): StringData { + return this.dataArray[index]; + } + + public addData(index: number, data: StringData): void { + this.dataArray.splice(index, 0, data); + this.notifyDataAdd(index); + } + + public pushData(data: StringData): void { + this.dataArray.push(data); + this.notifyDataAdd(this.dataArray.length - 1); + } +} + +@Observed +class StringData { + @Track public message: string; + @Track public imgSrc: Resource; + constructor(message: string, imgSrc: Resource) { + this.message = message; + this.imgSrc = imgSrc; + } +} + +@Entry +@Component +struct MyComponent9 { + @State data: MyDataSource = new MyDataSource(); + + aboutToAppear() { + for (let i = 0; i <= 9; i++) { + // 此处'app.media.icon'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 + this.data.pushData(new StringData(`Click to add ${i}`, $r('app.media.startIcon'))); + } + } + + build() { + List({ space: 3 }) { + LazyForEach(this.data, (item: StringData, index: number) => { + ListItem() { + ChildComponent({ data: item }) + } + .onClick(() => { + item.message += '0'; + }) + }, (item: StringData, index: number) => index.toString()) + }.cachedCount(5) + } +} + +@Component +struct ChildComponent { + @ObjectLink data: StringData + + build() { + Column() { + Text(this.data.message).fontSize(20) + .onAppear(() => { + hilog.info(DOMAIN_NUMBER, TAG, 'text appear:' + this.data.message); + }) + Image(this.data.imgSrc) + .width(100) + .height(100) + }.margin({ left: 10, right: 10 }) + } +} +// [End StateArrayLazy2_start] \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayLoadDate.ets b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayLoadDate.ets new file mode 100644 index 0000000000000000000000000000000000000000..8b28566738d364fc8fd200a5bf45e3746b7cadc1 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayLoadDate.ets @@ -0,0 +1,153 @@ +/* + * 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'; +const DOMAIN_NUMBER: number = 0XFF00; +const TAG: string = '[EvtryAblity]'; + +@Observed +class Child { + public count: number; + + constructor(count: number) { + this.count = count + } +} + +@Observed +class ChildList7 extends Array { + static from(children: Child[]): ChildList7 { + const list = new ChildList7(); + list.push(...children); + return list; + } +}; + +@Observed +class Ancestor7 { + public childList: ChildList7; + + constructor(childList: ChildList7) { + this.childList = childList; + } + + // [Start StateArrayLoadDate_start] + public loadData() { + const tempList = ChildList7.from([new Child(1), new Child(2), new Child(3), new Child(4), new Child(5)]); + this.childList = tempList; + } + // [End StateArrayLoadDate_start] + public clearData() { + this.childList = new ChildList7(); + } +} + +@Component +struct StateArrayLoadDate { + @Link childList: ChildList7; + @ObjectLink child: Child; + + build() { + Row() { + Text(this.child.count + '') + .height(70) + .fontSize(20) + .borderRadius({ topLeft: 6, topRight: 6 }) + .margin({ left: 50 }) + Button('X') + .backgroundColor(Color.Red) + .onClick(() => { + const index = this.childList.findIndex(item => item.count === this.child.count); + if (index !== -1) { + this.childList.splice(index, 1); + } + }) + .margin({ left: 200, right: 30 }) + } + .margin({ + top: 15, + left: 15, + right: 10, + bottom: 15 + }) + .borderRadius(6) + .backgroundColor(Color.Grey) + } +} + +@Component +struct CompList7 { + @ObjectLink @Watch('changeChildList') childList: ChildList7; + + changeChildList() { + hilog.info(DOMAIN_NUMBER, TAG, 'CompList ChildList changed'); + } + + isRenderCompChild(index: number): number { + hilog.info(DOMAIN_NUMBER, TAG, 'Comp Child rendered: ' + index); + return 1; + } + + build() { + Column() { + List() { + ForEach(this.childList, (item: Child, index) => { + ListItem() { + StateArrayLoadDate({ + childList: this.childList, + child: item + }) + .opacity(this.isRenderCompChild(index)) + } + }) + } + .height('70%') + } + } +} + +@Component +struct CompAncestor { + @ObjectLink ancestor7: Ancestor7; + + build() { + Column() { + CompList7({ childList: this.ancestor7.childList }) + Row() { + Button('Clear') + .onClick(() => this.ancestor7.clearData()) + .width(100) + .margin({ right: 50 }) + Button('Recover') + .onClick(() => this.ancestor7.loadData()) + .width(100) + } + } + } +} + +@Entry +@Component +struct StateArrayLoadDatePage { + @State childList: ChildList7 = ChildList7.from([ + new Child(1), new Child(2), new Child(3), new Child(4), new Child(5) + ]); + @State ancestor: Ancestor7 = new Ancestor7(this.childList) + + build() { + Column() { + CompAncestor({ ancestor7: this.ancestor }) + } + } +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayNo.ets b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayNo.ets new file mode 100644 index 0000000000000000000000000000000000000000..b683b66de069adc43e6300676596debba8f93a82 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayNo.ets @@ -0,0 +1,163 @@ +/* + * 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'; +const DOMAIN_NUMBER: number = 0XFF00; +const TAG: string = '[EvtryAblity]'; + +@Observed +class Child8 { + public count: number; + + constructor(count: number) { + this.count = count + } +} + +@Observed +class ChildList extends Array { +}; + +@Observed +class Ancestor { + public childList: ChildList; + + constructor(childList: ChildList) { + this.childList = childList; + } + + public loadData() { + let tempList = new ChildList(); + for (let i = 1; i < 6; i++) { + tempList.push(new Child8(i)); + } + this.childList = tempList; + } + + public clearData() { + this.childList = [] + } +} + +@Component +struct CompChild8 { + @Link childList: ChildList; + @ObjectLink Child8: Child8; + + build() { + Row() { + Text(this.Child8.count + '') + .height(70) + .fontSize(20) + .borderRadius({ + topLeft: 6, + topRight: 6 + }) + .margin({ left: 50 }) + Button('X') + .backgroundColor(Color.Red) + .onClick(() => { + let index = this.childList.findIndex((item) => { + return item.count === this.Child8.count + }) + if (index !== -1) { + this.childList.splice(index, 1); + } + }) + .margin({ + left: 200, + right: 30 + }) + } + .margin({ + top: 15, + left: 15, + right: 10, + bottom: 15 + }) + .borderRadius(6) + .backgroundColor(Color.Grey) + } +} + +@Component +struct CompList8 { + @ObjectLink @Watch('changeChildList') childList: ChildList; + + changeChildList() { + hilog.info(DOMAIN_NUMBER, TAG, 'CompList ChildList change'); + } + + isRenderCompChild(index: number): number { + hilog.info(DOMAIN_NUMBER, TAG, 'Comp Child is render' + index); + return 1; + } + + build() { + Column() { + List() { + ForEach(this.childList, (item: Child8, index) => { + ListItem() { + CompChild8({ + childList: this.childList, + Child8: item + }) + .opacity(this.isRenderCompChild(index)) + } + + }) + } + .height('70%') + } + } +} + +@Component +struct Ancestor8 { + @ObjectLink ancestor: Ancestor; + + build() { + Column() { + CompList8({ childList: this.ancestor.childList }) + Row() { + Button('Clear') + .onClick(() => { + this.ancestor.clearData() + }) + .width(100) + .margin({ right: 50 }) + Button('Recover') + .onClick(() => { + this.ancestor.loadData() + }) + .width(100) + } + } + } +} + +@Entry +@Component +struct Page8 { + // [Start StateArrayNo_start] + @State childList: ChildList = [new Child8(1), new Child8(2), new Child8(3), new Child8(4), new Child8(5)]; + @State ancestor: Ancestor = new Ancestor(this.childList) + // [End StateArrayNo_start] + build() { + Column() { + Ancestor8({ ancestor: this.ancestor }) + } + } +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayObserved.ets b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayObserved.ets new file mode 100644 index 0000000000000000000000000000000000000000..f8376befa380c476c03b2b8656f376822af11a9e --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayObserved.ets @@ -0,0 +1,161 @@ +/* + * 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 StateArrayObserve_start] +import { hilog } from '@kit.PerformanceAnalysisKit'; +const DOMAIN_NUMBER: number = 0XFF00; +const TAG: string = '[EvtryAblity]'; + +@Observed +class Child6 { + public count: number; + + constructor(count: number) { + this.count = count + } +} + +@Observed +class Child6List extends Array { +} +; + +@Observed +class Ancestor6 { + public childList: Child6List; + + constructor(childList: Child6List) { + this.childList = childList; + } + + public loadData() { + let tempList = [new Child6(1), new Child6(2), new Child6(3), new Child6(4), new Child6(5)]; + this.childList = tempList; + } + + public clearData() { + this.childList = [] + } +} + +@Component +struct CompChild6 { + @Link childList: Child6List; + @ObjectLink child: Child6; + + build() { + Row() { + Text(this.child.count + '') + .height(70) + .fontSize(20) + .borderRadius({ + topLeft: 6, + topRight: 6 + }) + .margin({ left: 50 }) + Button('X') + .backgroundColor(Color.Red) + .onClick(() => { + let index = this.childList.findIndex((item) => { + return item.count === this.child.count + }) + if (index !== -1) { + this.childList.splice(index, 1); + } + }) + .margin({ + left: 200, + right: 30 + }) + } + .margin({ + top: 15, + left: 15, + right: 10, + bottom: 15 + }) + .borderRadius(6) + .backgroundColor(Color.Grey) + } +} + +@Component +struct CompList6 { + @ObjectLink @Watch('changeChildList') Child6List: Child6List; + + changeChildList() { + hilog.info(DOMAIN_NUMBER, TAG, 'CompList ChildList change'); + } + + isRenderCompChild(index: number): number { + hilog.info(DOMAIN_NUMBER, TAG, 'Comp Child is render' + index); + return 1; + } + + build() { + Column() { + List() { + ForEach(this.Child6List, (item: Child6, index) => { + ListItem() { + CompChild6({ + childList: this.Child6List, + child: item + }) + .opacity(this.isRenderCompChild(index)) + } + + }) + } + .height('70%') + } + } +} + +@Component +struct CompAncestor6 { + @ObjectLink Ancestor6: Ancestor6; + + build() { + Column() { + CompList6({ Child6List: this.Ancestor6.childList }) + Row() { + Button('Clear') + .onClick(() => { + this.Ancestor6.clearData() + }) + .width(100) + .margin({ right: 50 }) + Button('Recover') + .onClick(() => { + this.Ancestor6.loadData() + }) + .width(100) + } + } + } +} + +@Entry +@Component +struct Page6 { + @State childList: Child6List = [new Child6(1), new Child6(2), new Child6(3), new Child6(4), new Child6(5)]; + @State ancestor: Ancestor6 = new Ancestor6(this.childList) + + build() { + Column() { + CompAncestor6({ Ancestor6: this.ancestor }) + } + } +} +// [End StateArrayObserve_start] \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayPrecise.ets b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayPrecise.ets new file mode 100644 index 0000000000000000000000000000000000000000..e9344e8f5a6fde31b158b92e6eb68dcdf6be0b88 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayPrecise.ets @@ -0,0 +1,248 @@ +/* + * 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 StateArrayPrecise_start] +import { hilog } from '@kit.PerformanceAnalysisKit'; +const DOMAIN_NUMBER: number = 0XFF00; +const TAG: string = '[EvtryAblity]'; + +@Observed +class NeedRenderImage { // 在同一组件中使用的属性可以划分为相同的类 + public translateImageX: number = 0; + public translateImageY: number = 0; + public imageWidth: number = 78; + public imageHeight: number = 78; +} + +@Observed +class NeedRenderScale { // 在一起使用的属性可以划分为相同的类 + public scaleX: number = 0.3; + public scaleY: number = 0.3; +} + +@Observed +class NeedRenderAlpha { // 在不同地方使用的属性可以划分为相同的类 + public alpha: number = 0.5; +} + +@Observed +class NeedRenderSize { // 在一起使用的属性可以划分为相同的类 + public width: number = 336; + public height: number = 178; +} + +@Observed +class NeedRenderPos { // 在一起使用的属性可以划分为相同的类 + public posX: number = 10; + public posY: number = 50; +} + +@Observed +class NeedRenderBorderRadius { // 在不同地方使用的属性可以划分为相同的类 + public borderRadius: number = 24; +} + +@Observed +class NeedRenderFontSize { // 在不同地方使用的属性可以划分为相同的类 + public fontSize: number = 20; +} + +@Observed +class NeedRenderTranslate { // 在一起使用的属性可以划分为相同的类 + public translateX: number = 0; + public translateY: number = 0; +} + +@Observed +class UiStyle4 { + // 使用NeedRenderxxx类 + public needRenderTranslate: NeedRenderTranslate = new NeedRenderTranslate(); + public needRenderFontSize: NeedRenderFontSize = new NeedRenderFontSize(); + public needRenderBorderRadius: NeedRenderBorderRadius = new NeedRenderBorderRadius(); + public needRenderPos: NeedRenderPos = new NeedRenderPos(); + public needRenderSize: NeedRenderSize = new NeedRenderSize(); + public needRenderAlpha: NeedRenderAlpha = new NeedRenderAlpha(); + public needRenderScale: NeedRenderScale = new NeedRenderScale(); + public needRenderImage: NeedRenderImage = new NeedRenderImage(); +} + +@Component +struct SpecialImage4 { + @ObjectLink uiStyle: UiStyle4; + @ObjectLink needRenderImage: NeedRenderImage // 从其父组件接收新类 + + private isRenderSpecialImage(): number { // 显示组件是否渲染的函数 + hilog.info(DOMAIN_NUMBER, TAG, 'SpecialImage is rendered'); + return 1; + } + + build() { + Image($r('app.media.background')) // 此处'app.media.icon'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 + .width(this.needRenderImage.imageWidth) // 使用this.needRenderImage.xxx + .height(this.needRenderImage.imageHeight) + .margin({ top: 20 }) + .translate({ + x: this.needRenderImage.translateImageX, + y: this.needRenderImage.translateImageY + }) + .opacity(this.isRenderSpecialImage()) // 如果Image重新渲染,该函数将被调用 + } +} + +@Component +struct PageChild4 { + @ObjectLink uiStyle: UiStyle4; + @ObjectLink needRenderTranslate: NeedRenderTranslate; // 从其父组件接收新定义的NeedRenderxxx类的实例 + @ObjectLink needRenderFontSize: NeedRenderFontSize; + @ObjectLink needRenderBorderRadius: NeedRenderBorderRadius; + @ObjectLink needRenderPos: NeedRenderPos; + @ObjectLink needRenderSize: NeedRenderSize; + @ObjectLink needRenderAlpha: NeedRenderAlpha; + @ObjectLink needRenderScale: NeedRenderScale; + + // 下面的函数用于显示组件是否被渲染 + private isRenderColumn(): number { + hilog.info(DOMAIN_NUMBER, TAG, 'Column is rendered'); + return 1; + } + + private isRenderStack(): number { + hilog.info(DOMAIN_NUMBER, TAG, 'Stack is rendered'); + return 1; + } + + private isRenderImage(): number { + hilog.info(DOMAIN_NUMBER, TAG, 'Image is rendered'); + return 1; + } + + private isRenderText(): number { + hilog.info(DOMAIN_NUMBER, TAG, 'Text is rendered'); + return 1; + } + + build() { + Column() { + SpecialImage4({ + uiStyle: this.uiStyle, + needRenderImage: this.uiStyle.needRenderImage // 传递给子组件 + }) + Stack() { + Column() { + Image($r('app.media.background')) // 此处'app.media.icon'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 + .opacity(this.needRenderAlpha.alpha) + .scale({ + x: this.needRenderScale.scaleX, // 使用this.needRenderXxx.xxx + y: this.needRenderScale.scaleY + }) + .padding(this.isRenderImage()) + .width(300) + .height(300) + } + .width('100%') + .position({ y: -80 }) + + Stack() { + Text('Hello World') + .fontColor('#182431') + .fontWeight(FontWeight.Medium) + .fontSize(this.needRenderFontSize.fontSize) + .opacity(this.isRenderText()) + .margin({ top: 12 }) + } + .opacity(this.isRenderStack()) + .position({ + x: this.needRenderPos.posX, + y: this.needRenderPos.posY + }) + .width('100%') + .height('100%') + } + .margin({ top: 50 }) + .borderRadius(this.needRenderBorderRadius.borderRadius) + .opacity(this.isRenderStack()) + .backgroundColor('#FFFFFF') + .width(this.needRenderSize.width) + .height(this.needRenderSize.height) + .translate({ + x: this.needRenderTranslate.translateX, + y: this.needRenderTranslate.translateY + }) + + Column() { + Button('Move') + .width(312) + .fontSize(20) + .backgroundColor('#FF007DFF') + .margin({ bottom: 10 }) + .onClick(() => { + this.getUIContext().animateTo({ + duration: 500 + }, () => { + this.needRenderTranslate.translateY = (this.needRenderTranslate.translateY + 180) % 250; + }) + }) + Button('Scale') + .borderRadius(20) + .backgroundColor('#FF007DFF') + .fontSize(20) + .width(312) + .margin({ bottom: 10 }) + .onClick(() => { + this.needRenderScale.scaleX = (this.needRenderScale.scaleX + 0.6) % 0.8; + }) + Button('Change Image') + .borderRadius(20) + .backgroundColor('#FF007DFF') + .fontSize(20) + .width(312) + .onClick(() => { // 在父组件中,仍使用 this.uiStyle.endRenderXxx.xxx 更改属性 + this.uiStyle.needRenderImage.imageWidth = (this.uiStyle.needRenderImage.imageWidth + 30) % 160; + this.uiStyle.needRenderImage.imageHeight = (this.uiStyle.needRenderImage.imageHeight + 30) % 160; + }) + } + .position({ + y: 616 + }) + .height('100%') + .width('100%') + } + .opacity(this.isRenderColumn()) + .width('100%') + .height('100%') + } +} + +@Entry +@Component +struct Page4 { + @State uiStyle: UiStyle4 = new UiStyle4(); + + build() { + Stack() { + PageChild4({ + uiStyle: this.uiStyle, + needRenderTranslate: this.uiStyle.needRenderTranslate, // 传递needRenderxxx类给子组件 + needRenderFontSize: this.uiStyle.needRenderFontSize, + needRenderBorderRadius: this.uiStyle.needRenderBorderRadius, + needRenderPos: this.uiStyle.needRenderPos, + needRenderSize: this.uiStyle.needRenderSize, + needRenderAlpha: this.uiStyle.needRenderAlpha, + needRenderScale: this.uiStyle.needRenderScale + }) + } + .backgroundColor('#F1F3F5') + } +} +// [End StateArrayPrecise_start] \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayTrack.ets b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayTrack.ets new file mode 100644 index 0000000000000000000000000000000000000000..b0e9f2fd424257cf3d634b1b84e360abd461887a --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayTrack.ets @@ -0,0 +1,183 @@ +/* + * 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 StateArrayTrack_start] +import { hilog } from '@kit.PerformanceAnalysisKit'; +const DOMAIN_NUMBER: number = 0XFF00; +const TAG: string = '[EvtryAblity]'; + +@Observed +class UiStyle5 { + @Track public translateX: number = 0; + @Track public translateY: number = 0; + @Track public scaleX: number = 0.3; + @Track public scaleY: number = 0.3; + @Track public width: number = 336; + @Track public height: number = 178; + @Track public posX: number = 10; + @Track public posY: number = 50; + @Track public alpha: number = 0.5; + @Track public borderRadius: number = 24; + @Track public imageWidth: number = 78; + @Track public imageHeight: number = 78; + @Track public translateImageX: number = 0; + @Track public translateImageY: number = 0; + @Track public fontSize: number = 20; +} + +@Component +struct SpecialImage5 { + @ObjectLink uiStyle: UiStyle5; + + private isRenderSpecialImage(): number { // 显示组件是否渲染的函数 + hilog.info(DOMAIN_NUMBER, TAG, 'SpecialImage is rendered'); + return 1; + } + + build() { + Image($r('app.media.startIcon')) // 此处'app.media.icon'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 + .width(this.uiStyle.imageWidth) + .height(this.uiStyle.imageHeight) + .margin({ top: 20 }) + .translate({ + x: this.uiStyle.translateImageX, + y: this.uiStyle.translateImageY + }) + .opacity(this.isRenderSpecialImage()) // 如果Image重新渲染,该函数将被调用 + } +} + +@Component +struct Page5Child { + @ObjectLink uiStyle: UiStyle5 + + // 下面的函数用于显示组件是否被渲染 + private isRenderColumn(): number { + hilog.info(DOMAIN_NUMBER, TAG, 'Column is rendered'); + return 1; + } + + private isRenderStack(): number { + hilog.info(DOMAIN_NUMBER, TAG, 'Stack is rendered'); + return 1; + } + + private isRenderImage(): number { + hilog.info(DOMAIN_NUMBER, TAG, 'Image is rendered'); + return 1; + } + + private isRenderText(): number { + hilog.info(DOMAIN_NUMBER, TAG, 'Text is rendered'); + return 1; + } + + build() { + Column() { + SpecialImage5({ + uiStyle: this.uiStyle + }) + Stack() { + Column() { + Image($r('app.media.foreground')) // 此处'app.media.icon'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。 + .opacity(this.uiStyle.alpha) + .scale({ + x: this.uiStyle.scaleX, + y: this.uiStyle.scaleY + }) + .padding(this.isRenderImage()) + .width(300) + .height(300) + } + .width('100%') + .position({ y: -80 }) + + Stack() { + Text('Hello World') + .fontColor('#182431') + .fontWeight(FontWeight.Medium) + .fontSize(this.uiStyle.fontSize) + .opacity(this.isRenderText()) + .margin({ top: 12 }) + } + .opacity(this.isRenderStack()) + .position({ + x: this.uiStyle.posX, + y: this.uiStyle.posY + }) + .width('100%') + .height('100%') + } + .margin({ top: 50 }) + .borderRadius(this.uiStyle.borderRadius) + .opacity(this.isRenderStack()) + .backgroundColor('#FFFFFF') + .width(this.uiStyle.width) + .height(this.uiStyle.height) + .translate({ + x: this.uiStyle.translateX, + y: this.uiStyle.translateY + }) + + Column() { + Button('Move') + .width(312) + .fontSize(20) + .backgroundColor('#FF007DFF') + .margin({ bottom: 10 }) + .onClick(() => { + this.getUIContext().animateTo({ + duration: 500 + }, () => { + this.uiStyle.translateY = (this.uiStyle.translateY + 180) % 250; + }) + }) + Button('Scale') + .borderRadius(20) + .backgroundColor('#FF007DFF') + .fontSize(20) + .width(312) + .onClick(() => { + this.uiStyle.scaleX = (this.uiStyle.scaleX + 0.6) % 0.8; + }) + } + .position({ + y: 666 + }) + .height('100%') + .width('100%') + + } + .opacity(this.isRenderColumn()) + .width('100%') + .height('100%') + + } +} + +@Entry +@Component +struct Page5 { + @State uiStyle: UiStyle5 = new UiStyle5(); + + build() { + Stack() { + SpecialImage5({ + uiStyle: this.uiStyle + }) + } + .backgroundColor('#F1F3F5') + } +} +// [End StateArrayTrack_start] \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayUpdate.ets b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayUpdate.ets new file mode 100644 index 0000000000000000000000000000000000000000..918855d1b42e1f168abd2cdb9895a5dea58b4677 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/ets/pages/statemanagementguide/StateArrayUpdate.ets @@ -0,0 +1,119 @@ +/* + * 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 Information_start] +import { hilog } from '@kit.PerformanceAnalysisKit'; +const DOMAIN_NUMBER: number = 0XFF00; +const TAG: string = '[EvtryAblity]'; + +@Observed +class InfoList extends Array { +}; + +@Observed +class Info { + public ids: number; + public age: number; + public gender: string; + + constructor() { + this.ids = Math.floor(Math.random() * 1000); + this.age = Math.floor(Math.random() * 100 % 40); + this.gender = Math.floor(Math.random() * 100) % 2 == 0 ? 'Male' : 'Female'; + } +} + +@Component +struct Information { + @ObjectLink info: Info; + @State index: number = 0; + + isRenderText(index: number): number { + hilog.info(DOMAIN_NUMBER, TAG, `index ${index} is rendered`); + return 1; + } + + build() { + Row() { + Text('id: ' + this.info.ids) + .fontSize(20) + .margin({ + left: 30, + right: 5 + }) + Text('age: ' + this.info.age) + .fontSize(20) + .margin({ + left: 5, + right: 5 + }) + .position({ x: 100 }) + .opacity(this.isRenderText(this.index)) + .onClick(() => { + this.info.age++; + }) + Text('gender: ' + this.info.gender) + .margin({ + left: 5, + right: 5 + }) + .position({ x: 180 }) + .fontSize(20) + } + } +} + +@Entry +@Component +struct Page2 { + @State infoList: InfoList = new InfoList(); + @State items: string[] = []; + + aboutToAppear() { + this.items.push('Head'); + this.items.push('List'); + for (let i = 0; i < 20; i++) { + this.infoList.push(new Info()); + } + } + + build() { + Row() { + Column() { + ForEach(this.items, (item: string) => { + if (item == 'Head') { + Text('Personal Info') + .fontSize(40) + } else if (item == 'List') { + List() { + ForEach(this.infoList, (info: Info, index) => { + ListItem() { + Information({ + info: info, + index: index + }) + } + .margin({ + top: 5, + bottom: 5 + }) + }) + } + } + }) + } + } + } +} +// [End Information_start] \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/module.json5 b/ArkUIKit/statemanagementproject/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d6017727d3774aa400c6a205adc8a1f626576a7e --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/module.json5 @@ -0,0 +1,62 @@ +/* + * 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. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": ["default"], + "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": [ + "ohos.want.action.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/ArkUIKit/statemanagementproject/entry/src/main/resources/base/element/color.json b/ArkUIKit/statemanagementproject/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ArkUIKit/statemanagementproject/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/ArkUIKit/statemanagementproject/entry/src/main/resources/base/element/float.json b/ArkUIKit/statemanagementproject/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/ArkUIKit/statemanagementproject/entry/src/main/resources/base/element/string.json b/ArkUIKit/statemanagementproject/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a1ffc37336fdff53dbed7876082d63655f789aa7 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/resources/base/element/string.json @@ -0,0 +1,21 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + }, + { + "name": "state_layout", + "value": "状态布局" + } + + ] +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/resources/base/media/background.png b/ArkUIKit/statemanagementproject/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..eeb110e3bb2f0607b3b8e0c30ae6a3e93d53e8d7 Binary files /dev/null and b/ArkUIKit/statemanagementproject/entry/src/main/resources/base/media/background.png differ diff --git a/ArkUIKit/statemanagementproject/entry/src/main/resources/base/media/foreground.png b/ArkUIKit/statemanagementproject/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..3063e3569b2ba2febffffd855539841a73b84860 Binary files /dev/null and b/ArkUIKit/statemanagementproject/entry/src/main/resources/base/media/foreground.png differ diff --git a/ArkUIKit/statemanagementproject/entry/src/main/resources/base/media/layered_image.json b/ArkUIKit/statemanagementproject/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ArkUIKit/statemanagementproject/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/ArkUIKit/statemanagementproject/entry/src/main/resources/base/media/startIcon.png b/ArkUIKit/statemanagementproject/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..a31c7f86b9157290e9278a80f48ff93b61b5a60d Binary files /dev/null and b/ArkUIKit/statemanagementproject/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ArkUIKit/statemanagementproject/entry/src/main/resources/base/profile/backup_config.json b/ArkUIKit/statemanagementproject/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/resources/base/profile/main_pages.json b/ArkUIKit/statemanagementproject/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..76846d0177e364f52cd01b849a7cbf8a55728e19 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,19 @@ +{ + "src": [ + "pages/Index", + "pages/statemanagementguide/StateArray", + "pages/statemanagementguide/StateArrayUpdate", + "pages/statemanagementguide/StateArrayBig", + "pages/statemanagementguide/StateArrayPrecise", + "pages/statemanagementguide/StateArrayTrack", + "pages/statemanagementguide/StateArrayObserved", + "pages/statemanagementguide/StateArrayLoadDate", + "pages/statemanagementguide/StateArrayInit", + "pages/statemanagementguide/StateArrayNo", + "pages/statemanagementguide/StateArrayLazy", + "pages/statemanagementguide/StateArrayLazy2", + "pages/statemanagementguide/StateArrayForeach", + "pages/statemanagementguide/StateArrayForeach2" + + ] +} diff --git a/ArkUIKit/statemanagementproject/entry/src/main/resources/dark/element/color.json b/ArkUIKit/statemanagementproject/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/main/resources/rawfile/customFont.ttf b/ArkUIKit/statemanagementproject/entry/src/main/resources/rawfile/customFont.ttf new file mode 100644 index 0000000000000000000000000000000000000000..b347ed51f4ce85fe56d09766d0a0a4410b828850 Binary files /dev/null and b/ArkUIKit/statemanagementproject/entry/src/main/resources/rawfile/customFont.ttf differ diff --git a/ArkUIKit/statemanagementproject/entry/src/main/syscap.json b/ArkUIKit/statemanagementproject/entry/src/main/syscap.json new file mode 100644 index 0000000000000000000000000000000000000000..7cd3c5bcea6d2676dd4097e7eaf5ef9effdff67c --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/main/syscap.json @@ -0,0 +1,14 @@ +{ + "devices": { + "general": ["default"], + "custom": [ + { + "xts": [ + "SystemCapability.ArkUI.ArkUI.Full", + "SystemCapability.ArkUI.ArkUI.Lite", + "SystemCapability.ArkUI.ArkUI.Circle" + ] + } + ] + } +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/mock/mock-config.json5 b/ArkUIKit/statemanagementproject/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/mock/mock-config.json5 @@ -0,0 +1,16 @@ +/* + * 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. + */ +{ +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/ohosTest/ets/test/Ability.test.ets b/ArkUIKit/statemanagementproject/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7f30942b81554a399e89aa253c7089eca4f8d8d1 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,49 @@ +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/ohosTest/ets/test/List.test.ets b/ArkUIKit/statemanagementproject/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ea9d700671a22264785621d3b14834aaec604e7 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +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. + */ +import abilityTest from './Ability.test'; +import StateManagementGuide from './StateManagementGuide.test'; + + +export default function testsuite() { + abilityTest(); + StateManagementGuide(); +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/ohosTest/ets/test/StateManagementGuide.test.ets b/ArkUIKit/statemanagementproject/entry/src/ohosTest/ets/test/StateManagementGuide.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..deaf958de82d5b159e5af5d8d68e60b1f6595fcd --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/ohosTest/ets/test/StateManagementGuide.test.ets @@ -0,0 +1,307 @@ +/* + * 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 { beforeAll, describe, expect, it, Level, TestType, Size } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; +import router from '@ohos.router'; + + +const delegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let driver: Driver; +let want: Want; + + +export default function StateManagementGuide() { + describe('StateManagementGuide', () => { + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + driver = Driver.create(); + await driver.delayMs(1000); + + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }); + + /* + * @tc.number : StateArray_001 + * @tc.name : testStateArray + * @tc.desc : 测试数据状态管理将简单属性数组合并成对象数组,配合ForEach进行使用 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testStateArray', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, + async (done: Function) => { + let driver = Driver.create(); + await driver.delayMs(1000); + await router.pushUrl({ url: 'pages/statemanagementguide/StateArray' }) + await driver.delayMs(2000); + await driver.pressBack(); + await driver.delayMs(1000); + done(); + }); + + /* + * @tc.number : StateArrayUpdate_001 + * @tc.name : testStateArrayUpdate + * @tc.desc : 测试减少“冗余刷新”,将属性数组转变为对象数组,配合自定义组件,实现精准控制更新范围 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testStateArrayUpdate', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, + async (done: Function) => { + let driver = Driver.create(); + await driver.delayMs(1000); + await router.pushUrl({ url: 'pages/statemanagementguide/StateArrayUpdate' }) + await driver.delayMs(2000); + await driver.pressBack(); + await driver.delayMs(1000); + done(); + }); + + /* + * @tc.number : StateArrayBig_001 + * @tc.name : testStateArrayBig + * @tc.desc : 测试定义一个大的对象,其中包含了很多样式相关的属性,并且在父子组件间传递这个对象,将其中的属性绑定在组件上 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testStateArrayBig', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, + async (done: Function) => { + let driver = Driver.create(); + await driver.delayMs(1000); + await router.pushUrl({ url: 'pages/statemanagementguide/StateArrayBig' }) + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('Move')); + await text.click(); + await driver.pressBack(); + await driver.delayMs(1000); + done(); + }); + + /* + * @tc.number : StateArrayPrecise_001 + * @tc.name : testStateArrayPrecise + * @tc.desc : 测试定义一个大的对象,其中包含了很多样式相关的属性,并且在父子组件间传递这个对象,将其中的属性绑定在组件上 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('testStateArrayPrecise', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, + async (done: Function) => { + let driver = Driver.create(); + await driver.delayMs(1000); + await router.pushUrl({ url: 'pages/statemanagementguide/StateArrayPrecise' }) + await driver.delayMs(2000); + await driver.pressBack(); + await driver.delayMs(1000); + done(); + }); + + /* + * @tc.number : StateArrayTrack_001 + * @tc.name : testStateArrayTrack + * @tc.desc : 测试使用@Track装饰器则无需做属性拆分,也能达到同样控制组件更新范围的作用。 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('StateArrayTrack', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, + async (done: Function) => { + let driver = Driver.create(); + await driver.delayMs(1000); + await router.pushUrl({ url: 'pages/statemanagementguide/StateArrayTrack' }) + await driver.delayMs(2000); + await driver.pressBack(); + await driver.delayMs(1000); + done(); + }); + + + /* + * @tc.number : StateArrayObserved_001 + * @tc.name : testStateArrayObserved + * @tc.desc : 测试使用@Observed装饰或被声明为状态变量的类对象绑定组件 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('StateArrayObserved', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, + async (done: Function) => { + let driver = Driver.create(); + await driver.delayMs(1000); + await router.pushUrl({ url: 'pages/statemanagementguide/StateArrayObserved' }) + await driver.delayMs(2000); + await driver.delayMs(2000); + const text = await driver.findComponent(ON.text('X')); + await text.click(); + await driver.pressBack(); + await driver.delayMs(1000); + done(); + }); + + /* + * @tc.number : StateArrayLoadDate_001 + * @tc.name : testStateArrayLoadDate + * @tc.desc : 测试childList重新赋值时,是通过Ancestor对象的方法loadData。 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('StateArrayLoadDate', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, + async (done: Function) => { + let driver = Driver.create(); + await driver.delayMs(1000); + await router.pushUrl({ url: 'pages/statemanagementguide/StateArrayLoadDate' }) + await driver.delayMs(2000); + const text = await driver.findComponent(ON.text('X')); + await text.click(); + await driver.pressBack(); + await driver.delayMs(1000); + done(); + }); + /* + * @tc.number : StateArrayNo_001 + * @tc.name : testStateArrayNo + * @tc.desc : 测试UI能够正常的刷新 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('StateArrayNo', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, + async (done: Function) => { + let driver = Driver.create(); + await driver.delayMs(1000); + await router.pushUrl({ url: 'pages/statemanagementguide/StateArrayNo' }) + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('X')); + await text.click(); + await driver.delayMs(2000); + await driver.pressBack(); + await driver.delayMs(1000); + done(); + }); + + /* +* @tc.number : StateArrayLazy_001 +* @tc.name : testStateArrayLazy +* @tc.desc : 测试减少使用LazyForEach的重建机制刷新UI +* @tc.size : MediumTest +* @tc.type : Function +* @tc.level : Level 1 +*/ + it('StateArrayLazy', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, + async (done: Function) => { + let driver = Driver.create(); + await driver.delayMs(1000); + await router.pushUrl({ url: 'pages/statemanagementguide/StateArrayLazy' }) + await driver.delayMs(1000); + await driver.delayMs(2000); + await driver.pressBack(); + await driver.delayMs(1000); + done(); + }); + + /* +* @tc.number : StateArrayLazy2_001 +* @tc.name : testStateArrayLazy2 +* @tc.desc : 测试使用状态变量来触发LazyForEach中的组件刷新,这就需要使用自定义组件。 +* @tc.size : MediumTest +* @tc.type : Function +* @tc.level : Level 1 +*/ + it('StateArrayLazy2', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, + async (done: Function) => { + let driver = Driver.create(); + await driver.delayMs(1000); + await router.pushUrl({ url: 'pages/statemanagementguide/StateArrayLazy2' }) + await driver.delayMs(1000); + await driver.delayMs(2000); + await driver.pressBack(); + await driver.delayMs(1000); + done(); + }); + + /* + * @tc.number : StateArrayForeach_001 + * @tc.name : testStateArrayForeach + * @tc.desc : 测试在ForEach中使用自定义组件搭配对象数组 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('StateArrayForeach', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, + async (done: Function) => { + let driver = Driver.create(); + await driver.delayMs(1000); + await router.pushUrl({ url: 'pages/statemanagementguide/StateArrayForeach' }) + await driver.delayMs(1000); + await driver.delayMs(2000); + await driver.pressBack(); + await driver.delayMs(1000); + done(); + }); + + /* + * @tc.number : StateArrayForeach2_001 + * @tc.name : testStateArrayForeach2 + * @tc.desc : 测试需要使用自定义组件,配合@ObjectLink来实现观测的能力 + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('StateArrayForeach2', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, + async (done: Function) => { + let driver = Driver.create(); + await driver.delayMs(1000); + await router.pushUrl({ url: 'pages/statemanagementguide/StateArrayForeach2' }) + await driver.delayMs(1000); + await driver.delayMs(2000); + await driver.pressBack(); + await driver.delayMs(1000); + done(); + }); + + + + /* +* @tc.number : StateArrayInit_001 +* @tc.name : testStateArrayInit +* @tc.desc : 测试在Page中初始化定义childList的时候,也可以@State childList进行初始化的 +* @tc.size : MediumTest +* @tc.type : Function +* @tc.level : Level 1 +*/ + it('testStateArrayInit', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL1, + async (done: Function) => { + let driver = Driver.create(); + await driver.delayMs(1000); + await router.pushUrl({ url: 'pages/statemanagementguide/StateArrayInit' }) + await driver.delayMs(2000); + await driver.pressBack(); + await driver.delayMs(1000); + done(); + }); + }); +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/ohosTest/module.json5 b/ArkUIKit/statemanagementproject/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d1eecaf5751793a78878b4ee4ba9f35a56f07953 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/ohosTest/module.json5 @@ -0,0 +1,23 @@ +/* + * 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. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": ["default"], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ArkUIKit/statemanagementproject/entry/src/ohosTest/syscap.json b/ArkUIKit/statemanagementproject/entry/src/ohosTest/syscap.json new file mode 100644 index 0000000000000000000000000000000000000000..7cd3c5bcea6d2676dd4097e7eaf5ef9effdff67c --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/ohosTest/syscap.json @@ -0,0 +1,14 @@ +{ + "devices": { + "general": ["default"], + "custom": [ + { + "xts": [ + "SystemCapability.ArkUI.ArkUI.Full", + "SystemCapability.ArkUI.ArkUI.Lite", + "SystemCapability.ArkUI.ArkUI.Circle" + ] + } + ] + } +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/test/List.test.ets b/ArkUIKit/statemanagementproject/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * 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 localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/entry/src/test/LocalUnit.test.ets b/ArkUIKit/statemanagementproject/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/ArkUIKit/statemanagementproject/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,47 @@ +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/hvigor/hvigor-config.json5 b/ArkUIKit/statemanagementproject/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3b057578a1bb4d591ee53054e39ab0154fc2e43a --- /dev/null +++ b/ArkUIKit/statemanagementproject/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * 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. + */ +{ + "modelVersion": "6.0.0", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | "ultrafine" | 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 */ + // "optimizationStrategy": "memory" /* Define the optimization strategy. Value: [ "memory" | "performance" ]. Default: "memory" */ + }, + "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/ArkUIKit/statemanagementproject/hvigorfile.ts b/ArkUIKit/statemanagementproject/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..ae9086af35844176c08f1be3772d081d95d267c6 --- /dev/null +++ b/ArkUIKit/statemanagementproject/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * 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 { 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. */ +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/oh-package.json5 b/ArkUIKit/statemanagementproject/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b13b6c7075b3b6c4d7190a8f656568a3d387277d --- /dev/null +++ b/ArkUIKit/statemanagementproject/oh-package.json5 @@ -0,0 +1,26 @@ +/* + * 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. + */ +{ + "modelVersion": "6.0.0", + "description": "Please describe the basic information.", + "dependencies": { + "@ohos/lottie": "^2.0.24" + }, + "devDependencies": { + "@ohos/hypium": "1.0.24", + "@ohos/hamock": "1.0.0" + }, + "dynamicDependencies": {} +} \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/ohosTest.md b/ArkUIKit/statemanagementproject/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..e2d2cf0ce212330cc17daa6d49265948b1d76577 --- /dev/null +++ b/ArkUIKit/statemanagementproject/ohosTest.md @@ -0,0 +1,19 @@ +# ArkUI多种布局组件 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|---------------------------------------------------------------------| -------------- |---------------------------|------| :------- | -------- | +| 测试将简单属性数组合并成对象数组 | 设备正常运行 | 进入示例页面,push页面,然后返回 | 页面跳转正常 | 是 | Pass | +| 测试“冗余刷新”,需要将属性数组转变为对象数组,配合自定义组件,实现精准控制更新范围 | 设备正常运行 | 进入示例页面,push页面,然后返回 | 页面跳转正常 | 是 | Pass | +| 测试将复杂大对象拆分成多个小对象的集合 | 设备正常运行 | 进入示例页面,push页面,点击MOVE,然后返回 | 页面跳转正常 | 是 | Pass | +| 测试推荐将一个复杂大对象拆分成多个小对象的集合,在保留原有代码结构的基础上,减少“冗余刷新”,实现精准控制组件的更新范围 | 设备正常运行 | 进入示例页面,push页面,点击MOVE,然后返回 | 页面跳转正常 | 是 | Pass | +| 测试使用@Track装饰器则无需做属性拆分,也能达到同样控制组件更新范围的作用 | 设备正常运行 | 进入各个示例页面,push页面,然后返回 | 页面跳转正常 | 是 | Pass | +| 测试使用@Observed装饰或被声明为状态变量的类对象绑定组件 | 设备正常运行 | 进入各个示例页面,点击'x',然后返回 | 页面跳转正常 | 是 | Pass | +| 测试数据源childList重新赋值时,是通过Ancestor对象的方法loadData。 | 设备正常运行 | 进入各个示例页面,push页面,然后返回 | 页面跳转正常 | 是 | Pass | +| 测试在Page中初始化定义childList的时候,也是@State childList去进行初始化的。 | 设备正常运行 | 进入各个示例页面,push页面,然后返回 | 页面跳转正常 | 是 | Pass | +| 测试将具有观测能力的类对象绑定组件,来确保当改变这些类对象的内容时,UI能够正常的刷新。 | 设备正常运行 | 进入各个示例页面,push页面,然后返回 | 页面跳转正常 | 是 | Pass | +| 测试减少使用LazyForEach的重建机制刷新UI | 设备正常运行 | 进入各个示例页面,push页面,然后返回 | 页面跳转正常 | 是 | Pass | +| 测试使用状态变量来触发LazyForEach中的组件刷新,需要使用自定义组件。 | 设备正常运行 | 进入各个示例页面,push页面,然后返回 | 页面跳转正常 | 是 | Pass | +| 测试使用对象数组和ForEach结合起来使用 | 设备正常运行 | 进入各个示例页面,push页面,然后返回 | 页面跳转正常 | 是 | Pass | +| 测试使用自定义组件,配合@ObjectLink来实现观测的能力 | 设备正常运行 | 进入各个示例页面,push页面,然后返回 | 页面跳转正常 | 是 | Pass | \ No newline at end of file diff --git a/ArkUIKit/statemanagementproject/screenshots/device/image1.png b/ArkUIKit/statemanagementproject/screenshots/device/image1.png new file mode 100644 index 0000000000000000000000000000000000000000..d68a368512437281ecb949e518f675e6e1fb230d Binary files /dev/null and b/ArkUIKit/statemanagementproject/screenshots/device/image1.png differ diff --git a/ArkUIKit/statemanagementproject/screenshots/device/image2.png b/ArkUIKit/statemanagementproject/screenshots/device/image2.png new file mode 100644 index 0000000000000000000000000000000000000000..babb06944d6bfadf0bb105e5e32f84b9ba784996 Binary files /dev/null and b/ArkUIKit/statemanagementproject/screenshots/device/image2.png differ diff --git a/ArkUIKit/statemanagementproject/screenshots/device/image3.png b/ArkUIKit/statemanagementproject/screenshots/device/image3.png new file mode 100644 index 0000000000000000000000000000000000000000..07f2fede623c8dfc8188b27312d66153a5102385 Binary files /dev/null and b/ArkUIKit/statemanagementproject/screenshots/device/image3.png differ diff --git a/ArkUIKit/statemanagementproject/screenshots/device/image4.png b/ArkUIKit/statemanagementproject/screenshots/device/image4.png new file mode 100644 index 0000000000000000000000000000000000000000..1cad2790dc091b307558aa6cd6c87fc3389f4d30 Binary files /dev/null and b/ArkUIKit/statemanagementproject/screenshots/device/image4.png differ