diff --git a/ArkUI/StateManagement/entry/src/main/ets/components/ButtonComponent.ets b/ArkUI/StateManagement/entry/src/main/ets/components/ButtonComponent.ets deleted file mode 100644 index f0f49c598ff2dfd5b8df47d15a349a867b84af18..0000000000000000000000000000000000000000 --- a/ArkUI/StateManagement/entry/src/main/ets/components/ButtonComponent.ets +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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. - */ - -@Component -export struct ButtonComponent { - build() { - Button('Click Me') - .width(100) - .height(40) - } -} \ No newline at end of file diff --git a/ArkUI/StateManagement/entry/src/main/ets/components/ListItemComponent.ets b/ArkUI/StateManagement/entry/src/main/ets/components/ListItemComponent.ets deleted file mode 100644 index acfa0a158bc7c486e02e363e84acb40b769b34f9..0000000000000000000000000000000000000000 --- a/ArkUI/StateManagement/entry/src/main/ets/components/ListItemComponent.ets +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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. - */ - -@Component -export struct ListItemComponent { - @Prop myItem: string = '' - @Prop index: number = 0 - - build() { - Text(`${this.index + 1}. ${this.myItem}`) - .fontSize(16) - } -} \ No newline at end of file diff --git a/ArkUI/StateManagement/entry/src/main/ets/pages/Index.ets b/ArkUI/StateManagement/entry/src/main/ets/pages/Index.ets index 8e2d24ad42693fc877d51bb7820f0a9da68fa135..633adadd00282a226ff7901c1d9e32a19e85d144 100644 --- a/ArkUI/StateManagement/entry/src/main/ets/pages/Index.ets +++ b/ArkUI/StateManagement/entry/src/main/ets/pages/Index.ets @@ -1,22 +1,40 @@ +/* + * 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. + */ + @Entry @Component struct Index { - @State message: string = 'Hello World'; + private buttonList: string[] = + Array.from({ length: 12 }, (_: number, i: number) => `Segment${i + 1}`); + @Provide("appPathStack") appPathStack: NavPathStack = new NavPathStack(); + @Provide("discoverPathStack") discoverPathStack: NavPathStack = new NavPathStack(); build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize($r('app.float.page_text_font_size')) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } - }) - .onClick(() => { - this.message = 'Welcome'; - }) + Navigation(this.appPathStack) { + List({ space: 12 }) { + ForEach(this.buttonList, (item: string) => { + ListItem() { + Button(item).onClick(() => this.appPathStack.pushPathByName(item, null)); + } + }, (item: string) => item) + } + .width('100%') + .height('100%') + .alignListItem(ListItemAlign.Center) } + .mode(NavigationMode.Stack) .height('100%') .width('100%') } diff --git a/ArkUI/StateManagement/entry/src/main/ets/segment/segment.ets b/ArkUI/StateManagement/entry/src/main/ets/segment/segment.ets index fde767c64ebf30f881a594acbaee02ffef6e90dd..90d01106be3521aba361fb5f63de6decafa920f4 100644 --- a/ArkUI/StateManagement/entry/src/main/ets/segment/segment.ets +++ b/ArkUI/StateManagement/entry/src/main/ets/segment/segment.ets @@ -12,13 +12,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +@Builder +export function Segment01Builder() { + NavDestination(){ + MyComponent() + } +} // [Start Counter_example1_start] @Observed class Translate { translateX: number = 20; } -@Entry + @Component struct MyComponent { @State translateObj: Translate = new Translate(); // The variable translateObj is not associated with any UI component and should not be defined as a state variable diff --git a/ArkUI/StateManagement/entry/src/main/ets/segment/segment10.ets b/ArkUI/StateManagement/entry/src/main/ets/segment/segment10.ets index 27bc225f4a39705e8bd1d37bec5cea9d4d33f9e2..a0763e90c13a47f0817efe4ec9d4934eef9ccf9e 100644 --- a/ArkUI/StateManagement/entry/src/main/ets/segment/segment10.ets +++ b/ArkUI/StateManagement/entry/src/main/ets/segment/segment10.ets @@ -13,8 +13,13 @@ * limitations under the License. */ +@Builder +export function Segment10Builder() { + NavDestination(){ + Index() + } +} // [Start Counter_example5] -@Entry @Component struct Index { @State currentIndex: number = 0; // The subscript of the currently selected list item diff --git a/ArkUI/StateManagement/entry/src/main/ets/segment/segment11.ets b/ArkUI/StateManagement/entry/src/main/ets/segment/segment11.ets index e2c9d6895726ae0d1483c8dd0d7a10ba566fc574..e611c0d9f6abcb1b87b978219a50cdd98e9935b5 100644 --- a/ArkUI/StateManagement/entry/src/main/ets/segment/segment11.ets +++ b/ArkUI/StateManagement/entry/src/main/ets/segment/segment11.ets @@ -13,6 +13,12 @@ * limitations under the License. */ +@Builder +export function Segment11Builder() { + NavDestination(){ + UseWatchListener() + } +} // [Start Case7] @Entry @Component @@ -21,7 +27,7 @@ struct UseWatchListener { private listData: string[] = []; aboutToAppear(): void { for (let i = 0; i < 10; i++) { - this.listData.push(`组件 ${i}`); + this.listData.push(`${i}`); } } build() { diff --git a/ArkUI/StateManagement/entry/src/main/ets/segment/segment12.ets b/ArkUI/StateManagement/entry/src/main/ets/segment/segment12.ets index 9ef38fd4d76bf0986507701ae8f47f6f9a80d5e6..07d106c3f27da228fb75c780475ba5e06e78a4ac 100644 --- a/ArkUI/StateManagement/entry/src/main/ets/segment/segment12.ets +++ b/ArkUI/StateManagement/entry/src/main/ets/segment/segment12.ets @@ -14,8 +14,8 @@ */ // [Start Case8] -import { ButtonComponent } from '../components/ButtonComponent'; -import { ListItemComponent } from '../components/ListItemComponent'; +import { ButtonComponent } from '../segment/segment13'; +import { ListItemComponent } from '../segment/segment14'; @Entry @Component struct UseEmitterPublish { @@ -42,4 +42,10 @@ struct UseEmitterPublish { } } } -// [End Case8] \ No newline at end of file +// [End Case8] +@Builder +export function Segment12Builder() { + NavDestination(){ + UseEmitterPublish() + } +} \ No newline at end of file diff --git a/ArkUI/StateManagement/entry/src/main/ets/segment/segment2.ets b/ArkUI/StateManagement/entry/src/main/ets/segment/segment2.ets index 23d25fc5861500d14f90743d567cf188cd678cd0..d7d88d7929bb146ed9d5bde52fa93a6d7a800992 100644 --- a/ArkUI/StateManagement/entry/src/main/ets/segment/segment2.ets +++ b/ArkUI/StateManagement/entry/src/main/ets/segment/segment2.ets @@ -12,13 +12,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +@Builder +export function Segment02Builder() { + NavDestination(){ + MyComponent() + } +} // [Start Counter_example2_start] @Observed class Translate { translateX: number = 20; } -@Entry + @Component struct MyComponent { @State translateObj: Translate = new Translate(); diff --git a/ArkUI/StateManagement/entry/src/main/ets/segment/segment3.ets b/ArkUI/StateManagement/entry/src/main/ets/segment/segment3.ets index 1f6928ee67f18ab2e2bc947f8312d42b689d1fc9..833ab40910d6fb4154911c9c20c40591c9b9b503 100644 --- a/ArkUI/StateManagement/entry/src/main/ets/segment/segment3.ets +++ b/ArkUI/StateManagement/entry/src/main/ets/segment/segment3.ets @@ -13,12 +13,18 @@ * limitations under the License. */ +@Builder +export function Segment03Builder() { + NavDestination(){ + UnnecessaryState1() + } +} // [Start Case1_start] @Observed class Translate { translateX: number = 20; } -@Entry + @Component struct UnnecessaryState1 { @State translateObj: Translate = new Translate(); // If there are both read and write operations and a Button component is associated with it, it is recommended to use state variables. diff --git a/ArkUI/StateManagement/entry/src/main/ets/segment/segment4.ets b/ArkUI/StateManagement/entry/src/main/ets/segment/segment4.ets index ba2122d21d81ab7253b021ccf7c0d1796c40c616..21f5a4df2ffd5e877f367455afc9c85307a896f9 100644 --- a/ArkUI/StateManagement/entry/src/main/ets/segment/segment4.ets +++ b/ArkUI/StateManagement/entry/src/main/ets/segment/segment4.ets @@ -12,9 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +@Builder +export function Segment04Builder() { + NavDestination(){ + Index() + } +} // [Start counter_example] -@Entry + @Component struct Index { @State message: string = ''; diff --git a/ArkUI/StateManagement/entry/src/main/ets/segment/segment5.ets b/ArkUI/StateManagement/entry/src/main/ets/segment/segment5.ets index ee6d62517b706c6795e58ab97c199d20acc759ee..c05f303c48e006387e25e7fd6ec90aa48174cfc2 100644 --- a/ArkUI/StateManagement/entry/src/main/ets/segment/segment5.ets +++ b/ArkUI/StateManagement/entry/src/main/ets/segment/segment5.ets @@ -12,7 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +@Builder +export function Segment05Builder() { + NavDestination(){ + UnnecessaryState2() + } +} // [Start Case2_start] @Entry @Component diff --git a/ArkUI/StateManagement/entry/src/main/ets/segment/segment6.ets b/ArkUI/StateManagement/entry/src/main/ets/segment/segment6.ets index cc4621e3a842be9489707e4749a8fc9a65556110..42beb0647c32f1c87f156443ab02d8c01cb687d7 100644 --- a/ArkUI/StateManagement/entry/src/main/ets/segment/segment6.ets +++ b/ArkUI/StateManagement/entry/src/main/ets/segment/segment6.ets @@ -12,6 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +@Builder +export function Segment06Builder() { + NavDestination(){ + UserInfoView() + } +} interface IUserAccountRepository { getUserData(): Promise; diff --git a/ArkUI/StateManagement/entry/src/main/ets/segment/segment7.ets b/ArkUI/StateManagement/entry/src/main/ets/segment/segment7.ets index 07cb23d602e5071e2a0d132678b9d6bea9626a32..4e6961c9a3ec328f373b0c61f1913aae8a27340c 100644 --- a/ArkUI/StateManagement/entry/src/main/ets/segment/segment7.ets +++ b/ArkUI/StateManagement/entry/src/main/ets/segment/segment7.ets @@ -12,7 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +@Builder +export function Segment07Builder() { + NavDestination(){ + ArticleCardView() + } +} interface IUserAccountRepository { getUserData(): Promise; } diff --git a/ArkUI/StateManagement/entry/src/main/ets/segment/segment8.ets b/ArkUI/StateManagement/entry/src/main/ets/segment/segment8.ets index 4f7782befb479101dce067e42a4bd3083881a629..f00b3af02224556ee3cf6123002aecb91fe3f5ee 100644 --- a/ArkUI/StateManagement/entry/src/main/ets/segment/segment8.ets +++ b/ArkUI/StateManagement/entry/src/main/ets/segment/segment8.ets @@ -12,7 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +@Builder +export function Segment08Builder() { + NavDestination(){ + ArticleCardView() + } +} @Component struct ActionButtonView { imgResource: Resource = $r("app.media.icon"); diff --git a/ArkUI/StateManagement/entry/src/main/ets/segment/segment9.ets b/ArkUI/StateManagement/entry/src/main/ets/segment/segment9.ets index 11f4c70b62e6f9f79079049a3a62a2bd76eafe6a..f436e5dcbb18765cb254671541778d2463123fa5 100644 --- a/ArkUI/StateManagement/entry/src/main/ets/segment/segment9.ets +++ b/ArkUI/StateManagement/entry/src/main/ets/segment/segment9.ets @@ -12,6 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +@Builder +export function Segment09Builder() { + NavDestination() { + DiscoverView() + } +} export class LearningResource { id: string = ""; @@ -29,9 +35,9 @@ interface GeneratedTypeLiteralInterface_1 { @Component struct HotFeedsView { @Prop hotFeedList: never[] = []; - @Prop showMore: () => void = () => { + showMore: () => void = () => { }; - @Prop handleClick: (item: LearningResource) => void = () => { + handleClick: (item: LearningResource) => void = () => { }; build() { @@ -42,7 +48,7 @@ struct HotFeedsView { @Component struct TechArticlesView { @Prop articlesDataSource: never[] = []; - @Prop handleClick: (item: LearningResource) => void = () => { + handleClick: (item: LearningResource) => void = () => { }; build() { @@ -54,7 +60,7 @@ struct TechArticlesView { @Component export struct DiscoverView { // [StartExclude Case6] - private jumpList(): void { + private jumpList = () => { } @State hotFeedList: never[] = []; @State articlesDataSource: never[] = []; @@ -64,6 +70,7 @@ export struct DiscoverView { @Consume('appPathStack') appPathStack: NavPathStack; @Consume('discoverPathStack') discoverPathStack: NavPathStack; @StorageProp('currentBreakpoint') currentBreakpoint: string = 'BreakpointTypeEnum.MD'; + // 5.Centralize the jump processing logic of the 3 components in the parent component jumpDetail(item: LearningResource): void { if (this.currentBreakpoint === 'BreakpointTypeEnum.LG') { @@ -72,6 +79,7 @@ export struct DiscoverView { this.appPathStack.pushPathByName('articleDetail', item); } } + build() { // [StartExclude Case6] Column() { @@ -88,7 +96,7 @@ export struct DiscoverView { Column({ space: CommonConstants.SPACE_12 }) { HotFeedsView({ hotFeedList: this.hotFeedList, - showMore: () => this.jumpList(), + showMore: this.jumpList, // 3.Information list component passes in the logic handler function of the parent component handleClick: (item: LearningResource) => this.jumpDetail(item) }) @@ -113,6 +121,7 @@ struct BannerView { // 6.The rotatoire component receives the logic handler passed to it by the parent component. handleClick: (item: LearningResource) => void = () => { }; + build() { Swiper(this.swiperController) { ForEach(this.swiperData, (item: LearningResource) => { @@ -123,7 +132,7 @@ struct BannerView { .height(55) // Set the border radius to 5vp .borderRadius($r('app.float.component_radius')) - // 7.When clicking on an image, call the received function to process the logic + // 7.When clicking on an image, call the received function to process the logic .onClick(() => this.handleClick(item)) } // ... diff --git a/ArkUI/StateManagement/entry/src/main/module.json5 b/ArkUI/StateManagement/entry/src/main/module.json5 index ad219d733f6afa5ea07f85f580208b08cc3b9041..e3043e123012d257b0cbe3486df843e11a205aa9 100644 --- a/ArkUI/StateManagement/entry/src/main/module.json5 +++ b/ArkUI/StateManagement/entry/src/main/module.json5 @@ -10,6 +10,7 @@ "deliveryWithInstall": true, "installationFree": false, "pages": "$profile:main_pages", + "routerMap": "$profile:route_map", "abilities": [ { "name": "EntryAbility", diff --git a/FitForDarkMode/README.md b/FitForDarkMode/README.md new file mode 100644 index 0000000000000000000000000000000000000000..43e47c2fdb2a7f171534494be253547d5b547b85 --- /dev/null +++ b/FitForDarkMode/README.md @@ -0,0 +1,19 @@ +# 实现深色模式功能 + +### 简介 + +本示例采用深色模式适配相关技术,确保应用在系统深浅色模式切换时界面效果美观自然,实现颜色资源适配、媒体资源适配、状态栏适配等。应用内还提供用户可控的深浅色模式开关,满足用户个性化需求,实现应用在不同模式下的深浅色切换。 + +### 相关权限 + +不涉及 + +### 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:华为手机。 + +2.HarmonyOS系统:HarmonyOS 5.0.5 Release及以上。 + +3.DevEco Studio版本:DevEco Studio 5.0.5 Release及以上。 + +4.HarmonyOS SDK版本:HarmonyOS 5.0.5 Release SDK及以上。 \ No newline at end of file diff --git a/FitForDarkMode/build-profile.json5 b/FitForDarkMode/build-profile.json5 index bf6e5574af2ddbc5f7b830d86d2b7143a445d064..9e87e7e6f19020fe21192844709f192cec80fd44 100644 --- a/FitForDarkMode/build-profile.json5 +++ b/FitForDarkMode/build-profile.json5 @@ -5,8 +5,8 @@ { "name": "default", "signingConfig": "default", - "targetSdkVersion": "5.1.0(18)", - "compatibleSdkVersion": "5.1.0(18)", + "targetSdkVersion": "5.0.5(17)", + "compatibleSdkVersion": "5.0.5(17)", "runtimeOS": "HarmonyOS", "buildOption": { "strictMode": { diff --git a/FitForDarkMode/entry/src/main/ets/pages/FitDarkIcon.ets b/FitForDarkMode/entry/src/main/ets/pages/FitDarkIcon.ets index b916e6b24ca01403fc7d26e7c0ba0e42ab7d0095..67e0b8281d9ff3ce1518a3b82610584966f0282c 100644 --- a/FitForDarkMode/entry/src/main/ets/pages/FitDarkIcon.ets +++ b/FitForDarkMode/entry/src/main/ets/pages/FitDarkIcon.ets @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + // [Start media_start] @Component struct Home { diff --git a/FitForDarkMode/entry/src/main/ets/pages/Index.ets b/FitForDarkMode/entry/src/main/ets/pages/Index.ets index 8e2d24ad42693fc877d51bb7820f0a9da68fa135..d66ea72c2cb5ef3a3dffb32f40d4ea74ac14ec84 100644 --- a/FitForDarkMode/entry/src/main/ets/pages/Index.ets +++ b/FitForDarkMode/entry/src/main/ets/pages/Index.ets @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ @Entry @Component struct Index {