From 5cff8c864e6ec6c39a1c4afe176357fa929ebe31 Mon Sep 17 00:00:00 2001 From: "@feng-yu4279" Date: Wed, 28 May 2025 17:16:24 +0800 Subject: [PATCH] =?UTF-8?q?feat=20(=E6=A0=87=E8=AF=86):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20ComponentEncapsulation=20=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/CommonComponent.ets | 4 ++-- entry/src/main/ets/pages/ComponentFactory.ets | 6 +++--- entry/src/main/ets/pages/DialogComponent.ets | 12 ++++++------ entry/src/main/ets/view/CustomImageText.ets | 4 ++-- entry/src/main/ets/view/FactoryMap.ets | 10 +++++----- entry/src/main/resources/en_US/element/string.json | 4 ---- entry/src/main/resources/zh_CN/element/string.json | 4 ---- 7 files changed, 18 insertions(+), 26 deletions(-) diff --git a/entry/src/main/ets/pages/CommonComponent.ets b/entry/src/main/ets/pages/CommonComponent.ets index 9e4776f..3557ab6 100644 --- a/entry/src/main/ets/pages/CommonComponent.ets +++ b/entry/src/main/ets/pages/CommonComponent.ets @@ -23,7 +23,7 @@ export function CommonComponentBuilder() { } @Entry - // [Start common_component] +// [Start common_component1] @Component struct CommonComponent { imageAttribute: ImageModifier = new ImageModifier(330, 330); @@ -48,7 +48,7 @@ struct CommonComponent { .title(getResourceString($r('app.string.common'), this)) } } -// [End common_component] +// [End common_component1] // [Start my_button1] //Provider customizes and exports components diff --git a/entry/src/main/ets/pages/ComponentFactory.ets b/entry/src/main/ets/pages/ComponentFactory.ets index a732807..9437de8 100644 --- a/entry/src/main/ets/pages/ComponentFactory.ets +++ b/entry/src/main/ets/pages/ComponentFactory.ets @@ -29,17 +29,17 @@ export function ComponentFactoryBuilder() { } @Entry - // [Start component_factory] +// [Start component_factory] @Component struct ComponentFactory { build() { NavDestination() { - Column({ space: CommonConstants.BUTTON_SPACING }) { + Column({ space: 12 }) { // myRadio and myCheckbox are WrappedBuilder objects obtained from the component factory. myRadio.builder(); myCheckbox.builder(); } - .width(CommonConstants.ONE_HUNDRED_PERCENT) + .width('100%') .padding($r('app.float.padding')) } .title(getResourceString($r('app.string.factory'), this)) diff --git a/entry/src/main/ets/pages/DialogComponent.ets b/entry/src/main/ets/pages/DialogComponent.ets index a6051b0..c22dc20 100644 --- a/entry/src/main/ets/pages/DialogComponent.ets +++ b/entry/src/main/ets/pages/DialogComponent.ets @@ -23,7 +23,7 @@ export function DialogComponentBuilder() { } @Builder export function buildText(_obj: Object) { - Column({ space: CommonConstants.ROW_SPACING }) { + Column({ space: 16 }) { Text($r('app.string.tips')) .fontSize($r('app.float.font_size_l')) .fontWeight(FontWeight.Bold) @@ -34,12 +34,12 @@ export function buildText(_obj: Object) { .fontColor($r('app.color.blue')) .backgroundColor(Color.White) .margin({ right: $r('app.float.margin_right') }) - .width(CommonConstants.BUTTON_WIDTH) + .width('42%') .onClick(() => { PopViewUtils.closePopView(); }) Button($r('app.string.confirm')) - .width(CommonConstants.BUTTON_WIDTH) + .width('42%') .onClick(() => { PopViewUtils.closePopView(); }) @@ -62,7 +62,7 @@ struct DialogComponent { NavDestination() { Column() { Button('Click me') - .width(CommonConstants.ONE_HUNDRED_PERCENT) + .width('100%') .onClick(() => { PopViewUtils.showPopView(wrapBuilder(buildText), new Object(), { alignment: DialogAlignment.Center }); }) @@ -73,8 +73,8 @@ struct DialogComponent { right: $r('app.float.padding'), bottom: $r('app.float.padding') }) - .width(CommonConstants.ONE_HUNDRED_PERCENT) - .height(CommonConstants.ONE_HUNDRED_PERCENT) + .width('100%') + .height('100%') } .title(getResourceString($r('app.string.dialog'), this)) } diff --git a/entry/src/main/ets/view/CustomImageText.ets b/entry/src/main/ets/view/CustomImageText.ets index 1a3279f..7e6c400 100644 --- a/entry/src/main/ets/view/CustomImageText.ets +++ b/entry/src/main/ets/view/CustomImageText.ets @@ -22,7 +22,7 @@ export struct CustomImageText { @Prop text: string; build() { - Column({ space: CommonConstants.BUTTON_SPACING }) { + Column({ space: 12 }) { Image($r('app.media.image')) .attributeModifier(this.imageAttribute) Text('Scenery') @@ -53,7 +53,7 @@ struct MyButton { @Component struct Index { build() { - MyButton({ text: String($r('app.string.click')), stateEffect: true }) + MyButton({ text: 'Click with animation', stateEffect: true }) } } // [End index] \ No newline at end of file diff --git a/entry/src/main/ets/view/FactoryMap.ets b/entry/src/main/ets/view/FactoryMap.ets index 7a41ffb..6a992ef 100644 --- a/entry/src/main/ets/view/FactoryMap.ets +++ b/entry/src/main/ets/view/FactoryMap.ets @@ -24,14 +24,14 @@ function myRadio() { .margin({ right: $r('app.float.margin_right') }) Text('man') } - .width(CommonConstants.ONE_HUNDRED_PERCENT) + .width('100%') Row() { Radio({ value: '0', group: 'radioGroup' }) .margin({ right: $r('app.float.margin_right') }) Text('woman') } - .width(CommonConstants.ONE_HUNDRED_PERCENT) + .width('100%') } @Builder @@ -45,7 +45,7 @@ function myCheckBox() { Text('all') .margin({ left: $r('app.float.margin_right') }) } - .width(CommonConstants.ONE_HUNDRED_PERCENT) + .width('100%') Row() { Checkbox({ name: '1', group: 'checkboxGroup' }) @@ -53,7 +53,7 @@ function myCheckBox() { .margin({ right: $r('app.float.margin_right') }) Text('text1') } - .width(CommonConstants.ONE_HUNDRED_PERCENT) + .width('100%') Row() { Checkbox({ name: '0', group: 'checkboxGroup' }) @@ -61,7 +61,7 @@ function myCheckBox() { .margin({ right: $r('app.float.margin_right') }) Text('text2') } - .width(CommonConstants.ONE_HUNDRED_PERCENT) + .width('100%') } // [End my_radio] diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json index 86e9f1d..8d61c21 100644 --- a/entry/src/main/resources/en_US/element/string.json +++ b/entry/src/main/resources/en_US/element/string.json @@ -51,10 +51,6 @@ { "name": "checkbox", "value": "CheckBox" - }, - { - "name": "click", - "value": "CheckBox" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json index 7d20e07..82248c1 100644 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -51,10 +51,6 @@ { "name": "checkbox", "value": "复选框" - }, - { - "name": "click", - "value": "点击带有动效" } ] } \ No newline at end of file -- Gitee