From 2617df3c1a12300cf003cd134487658debcdf742 Mon Sep 17 00:00:00 2001 From: zgf Date: Wed, 17 Jul 2024 15:39:03 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E9=80=82=E9=85=8DComponentV2=E8=A3=85?= =?UTF-8?q?=E9=A5=B0=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zgf --- CHANGELOG.md | 6 ++ entry/src/main/ets/pages/Index.ets | 39 ++++------ entry/src/main/ets/pages/TypeCustomDialog.ets | 74 +++++++++++++------ library/oh-package.json5 | 2 +- .../main/ets/components/RoundedImageView.ets | 4 +- sharedlibrary/src/main/ets/pages/Index.ets | 39 ++++------ .../src/main/ets/pages/TypeCustomDialog.ets | 74 +++++++++++++------ 7 files changed, 143 insertions(+), 95 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c22c304..168aa7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.1.0 +- 适配V2装饰器 + +## 2.0.2 +- 发布2.0.2正式版本 + ## 2.0.2-rc.0 - RoundedImageView.Model类 1.新增setContext(context:common.UIAbilityContext)接口,在hsp场景下需要传入正确的context才能保证后续获取资源代码正常运行,对于非HSP场景无影响可以不传。 diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 90fa48a..cb4ca53 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -19,7 +19,7 @@ import { RoundedImageView,RoundedImageName, ScaleType, TileMode, SrcType, FileUt import router from '@ohos.router' @Entry -@Component +@ComponentV2 struct Index { private picIdxArr: number [] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] private colorIdxArr: number [] = [0, 1, 2, 3, 4, 5, 6] @@ -30,11 +30,6 @@ struct Index { private uriFile: string = this.uriFolder + "/" + "photo1.jpg" private viewModels: RoundedImageName.Model [] = []; private scroller: Scroller = new Scroller() - private dialogController: CustomDialogController = new CustomDialogController({ - alignment: DialogAlignment.Top, - builder: TypeCustomDialog({ typeValue: $typeValue }), - autoCancel: true - }) private rectPictureItems: PictureItem [] = [ { src: $r('app.media.photo1'), @@ -793,21 +788,8 @@ struct Index { padding: 0 }, ] - @State @Watch("typeValueChanged") typeValue: string = 'Bitmap' - - aboutToAppear() { - this.initViewModels() - this.typeValueChanged() - this.initUri() - } - - private initViewModels(): void { - let viewModelsLength = Math.max(this.picIdxArr.length, this.colorIdxArr.length) - for (let index = 0; index < viewModelsLength; index++) { - this.viewModels.push(new RoundedImageName.Model) - } - } - + @Local typeValue: string = 'Bitmap' + @Monitor("typeValue") private typeValueChanged(): void { if (this.typeValue == 'Bitmap') { this.updateViewModels(this.rectPictureItems) @@ -822,7 +804,18 @@ struct Index { } this.scroller.scrollTo({ xOffset: 0, yOffset: 0, animation: { duration: 2000, curve: Curve.Ease } }) } + aboutToAppear() { + this.initViewModels() + this.typeValueChanged() + this.initUri() + } + private initViewModels(): void { + let viewModelsLength = Math.max(this.picIdxArr.length, this.colorIdxArr.length) + for (let index = 0; index < viewModelsLength; index++) { + this.viewModels.push(new RoundedImageName.Model) + } + } private updateViewModels(pictureItem: PictureItem[]) { pictureItem.forEach((val, idx) => { @@ -866,9 +859,7 @@ struct Index { }) Column() { Column() { - Image($r('app.media.down')).width(30).height(30).position({ x: -30, y: 5 }).onClick(() => { - this.dialogController.open() - }) + TypeCustomDialog({typeValue: this.typeValue!!}) Text(' select:' + this.typeValue).fontSize(30) }.margin(15) diff --git a/entry/src/main/ets/pages/TypeCustomDialog.ets b/entry/src/main/ets/pages/TypeCustomDialog.ets index ae9cd9c..49b77d9 100644 --- a/entry/src/main/ets/pages/TypeCustomDialog.ets +++ b/entry/src/main/ets/pages/TypeCustomDialog.ets @@ -12,33 +12,63 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +export class CustomDialog { + private static instance: CustomDialog | null = null + public promptAction: PromptAction | undefined = undefined + public contextNode: ComponentContent> | undefined = undefined + public typeValue: string = "" + public static getInstance() { + if (CustomDialog.instance == null) { + CustomDialog.instance = new instance() + } + return CustomDialog.instance + } +} +@Builder +function buildText(params:Array){ + Row() { + Scroll() { + List({ space: 10, initialIndex: 0 }) { + ForEach(params, (item:string) => { + ListItem() { + Text(item) + .width('100%') + .height(20) + .fontSize(20) + .textAlign(TextAlign.Start) + .backgroundColor(0xFFFFFF) + .onClick(() => { + CustomDialog.getInstance().typeValue = item + CustomDialog.getInstance().promptAction?.closeCustomDialog(CustomDialog.getInstance().contextNode) + }) + } + }, (item:string) => item) + }.backgroundColor(Color.White).width(200).padding(20) + } + } +} -@CustomDialog +@ComponentV2 export struct TypeCustomDialog { - private controller?: CustomDialogController private typeArr: string[] = ['Bitmap', 'Ovals', 'Color', 'Background', 'SVG'] - @Link private typeValue: string + @Param typeValue: string + @Envet $typeValue: (val: string) => void = (val:string) => {} build() { - Row() { - Scroll() { - List({ space: 10, initialIndex: 0 }) { - ForEach(this.typeArr, (item:string) => { - ListItem() { - Text(item) - .width('100%') - .height(20) - .fontSize(20) - .textAlign(TextAlign.Start) - .backgroundColor(0xFFFFFF) - .onClick(() => { - this.typeValue = item - this.controller?.close(); - }) - } - }, (item:string) => item) - }.backgroundColor(Color.White).width(200).padding(20) + Image($r('app.media.down')).width(30).height(30).position({ x: -30, y: 5 }).onClick(() => { + let uiContext = this.getUIContext(); + let promptAction = uiContext.getPromptAction() + CustomDialog.getInstance().promptAction = promptAction + let contextNode = new ComponentContent(uiContext ,wrapBuilder(buildText),this.typeArr) + CustomDialog.getInstance().contextNode = contextNode + try { + promptAction.openCustomDialog(contextNode,{alignment: DialogAlignment.Center , onDisappear:()=>{ + this.$typeValue(CustomDialog.getInstance().typeValue) + }}) + } catch(error) { + let message = (err as BusinessError).message + let code = (err as BusinessError).code } - } + }) } } \ No newline at end of file diff --git a/library/oh-package.json5 b/library/oh-package.json5 index c504120..90563bd 100644 --- a/library/oh-package.json5 +++ b/library/oh-package.json5 @@ -12,7 +12,7 @@ "description": "RoundedImageView支持许多附加功能,包括椭圆、圆角矩形、ScaleTypes 和 TileModes", "main": "index.ets", "repository": "https://gitee.com/openharmony-sig/RoundedImageView", - "version": "2.0.2-rc.0", + "version": "", "dependencies": { "@ohos/svg": "2.1.1-rc.4" } diff --git a/library/src/main/ets/components/RoundedImageView.ets b/library/src/main/ets/components/RoundedImageView.ets index b61b99e..092bf31 100644 --- a/library/src/main/ets/components/RoundedImageView.ets +++ b/library/src/main/ets/components/RoundedImageView.ets @@ -22,9 +22,9 @@ import { GlobalContext } from './GlobalContext'; import common from '@ohos.app.ability.common'; -@Component +@ComponentV2 export struct RoundedImageView { - @State model: RoundedImageName.Model = new RoundedImageName.Model() + @Param model: RoundedImageName.Model = new RoundedImageName.Model() private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) private bottomLayerContext: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) diff --git a/sharedlibrary/src/main/ets/pages/Index.ets b/sharedlibrary/src/main/ets/pages/Index.ets index b304ae4..260b4a9 100644 --- a/sharedlibrary/src/main/ets/pages/Index.ets +++ b/sharedlibrary/src/main/ets/pages/Index.ets @@ -20,7 +20,7 @@ import common from '@ohos.app.ability.common' import display from '@ohos.display' @Entry -@Component +@ComponentV2 struct Index { private picIdxArr: number [] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] private colorIdxArr: number [] = [0, 1, 2, 3, 4, 5, 6] @@ -31,11 +31,6 @@ struct Index { private uriFile: string = this.uriFolder + "/" + "photo1.jpg" private viewModels: RoundedImageName.Model [] = []; private scroller: Scroller = new Scroller() - private dialogController: CustomDialogController = new CustomDialogController({ - alignment: DialogAlignment.Top, - builder: TypeCustomDialog({ typeValue: $typeValue }), - autoCancel: true - }) private rectPictureItems: PictureItem [] = [ { src: $r('app.media.photo1'), @@ -794,21 +789,8 @@ struct Index { padding: 0 }, ] - @State @Watch("typeValueChanged") typeValue: string = 'Bitmap' - - aboutToAppear() { - this.initViewModels() - this.typeValueChanged() - this.initUri() - } - - private initViewModels(): void { - let viewModelsLength = Math.max(this.picIdxArr.length, this.colorIdxArr.length) - for (let index = 0; index < viewModelsLength; index++) { - this.viewModels.push(new RoundedImageName.Model) - } - } - + @Local typeValue: string = 'Bitmap' + @Monitor("typeValue") private typeValueChanged(): void { if (this.typeValue == 'Bitmap') { this.updateViewModels(this.rectPictureItems) @@ -823,7 +805,18 @@ struct Index { } this.scroller.scrollTo({ xOffset: 0, yOffset: 0, animation: { duration: 2000, curve: Curve.Ease } }) } + aboutToAppear() { + this.initViewModels() + this.typeValueChanged() + this.initUri() + } + private initViewModels(): void { + let viewModelsLength = Math.max(this.picIdxArr.length, this.colorIdxArr.length) + for (let index = 0; index < viewModelsLength; index++) { + this.viewModels.push(new RoundedImageName.Model) + } + } private updateViewModels(pictureItem: PictureItem[]) { pictureItem.forEach((val, idx) => { @@ -862,9 +855,7 @@ struct Index { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Column() { Column() { - Image($r('app.media.down')).width(30).height(30).position({ x: -30, y: 5 }).onClick(() => { - this.dialogController.open() - }) + TypeCustomDialog({typeValue: this.typeValue!!}) Text(' select:' + this.typeValue).fontSize(30) }.margin(15) diff --git a/sharedlibrary/src/main/ets/pages/TypeCustomDialog.ets b/sharedlibrary/src/main/ets/pages/TypeCustomDialog.ets index ae9cd9c..00fac23 100644 --- a/sharedlibrary/src/main/ets/pages/TypeCustomDialog.ets +++ b/sharedlibrary/src/main/ets/pages/TypeCustomDialog.ets @@ -12,33 +12,63 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +export class CustomDialog { + private static instance: CustomDialog | null = null + public promptAction: PromptAction | undefined = undefined + public contextNode: ComponentContent> | undefined = undefined + public typeValue: string = "" + public static getInstance() { + if (CustomDialog.instance == null) { + CustomDialog.instance = new instance() + } + return CustomDialog.instance + } +} +@Builder +function buildText(params:Array){ + Row() { + Scroll() { + List({ space: 10, initialIndex: 0 }) { + ForEach(params, (item:string) => { + ListItem() { + Text(item) + .width('100%') + .height(20) + .fontSize(20) + .textAlign(TextAlign.Start) + .backgroundColor(0xFFFFFF) + .onClick(() => { + CustomDialog.getInstance().typeValue = item + CustomDialog.getInstance().promptAction?.closeCustomDialog(CustomDialog.getInstance().contextNode) + }) + } + }, (item:string) => item) + }.backgroundColor(Color.White).width(200).padding(20) + } + } +} -@CustomDialog +@ComponentV2 export struct TypeCustomDialog { - private controller?: CustomDialogController private typeArr: string[] = ['Bitmap', 'Ovals', 'Color', 'Background', 'SVG'] - @Link private typeValue: string + @Param typeValue: string + @Envet $typeValue: (val: string) => void = (val:string) => {} build() { - Row() { - Scroll() { - List({ space: 10, initialIndex: 0 }) { - ForEach(this.typeArr, (item:string) => { - ListItem() { - Text(item) - .width('100%') - .height(20) - .fontSize(20) - .textAlign(TextAlign.Start) - .backgroundColor(0xFFFFFF) - .onClick(() => { - this.typeValue = item - this.controller?.close(); - }) - } - }, (item:string) => item) - }.backgroundColor(Color.White).width(200).padding(20) + Image($r('app.media.down')).width(30).height(30).position({ x: -30, y: 5 }).onClick(() => { + let uiContext = this.getUIContext(); + let promptAction = uiContext.getPromptAction() + CustomDialog.getInstance().promptAction = promptAction + let contextNode = new ComponentContent(uiContext ,wrapBuilder(buildText),this.typeArr) + CustomDialog.getInstance().contextNode = contextNode + try { + promptAction.openCustomDialog(contextNode,{alignment: DialogAlignment.Center , onDisappear:()=>{ + this.$typeValue(CustomDialog.getInstance().typeValue) + }}) + } catch(error) { + let message = (err as BusinessError).message + let code = (err as BusinessError).code } - } + }) } } \ No newline at end of file -- Gitee From 4e24b7ec82dc7fc6ace8584a917e34ece6760e15 Mon Sep 17 00:00:00 2001 From: zgf Date: Thu, 18 Jul 2024 11:01:50 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E9=80=82=E9=85=8DComponentV2=E8=A3=85?= =?UTF-8?q?=E9=A5=B0=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zgf --- entry/src/main/ets/pages/TypeCustomDialog.ets | 15 +++++++++------ .../src/main/ets/pages/TypeCustomDialog.ets | 15 +++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/entry/src/main/ets/pages/TypeCustomDialog.ets b/entry/src/main/ets/pages/TypeCustomDialog.ets index 49b77d9..f01c955 100644 --- a/entry/src/main/ets/pages/TypeCustomDialog.ets +++ b/entry/src/main/ets/pages/TypeCustomDialog.ets @@ -12,6 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { BusinessError } from "@kit.BasicServicesKit" +import { PromptAction } from "@kit.ArkUI" + export class CustomDialog { private static instance: CustomDialog | null = null public promptAction: PromptAction | undefined = undefined @@ -19,7 +22,7 @@ export class CustomDialog { public typeValue: string = "" public static getInstance() { if (CustomDialog.instance == null) { - CustomDialog.instance = new instance() + CustomDialog.instance = new CustomDialog() } return CustomDialog.instance } @@ -51,8 +54,8 @@ function buildText(params:Array){ @ComponentV2 export struct TypeCustomDialog { private typeArr: string[] = ['Bitmap', 'Ovals', 'Color', 'Background', 'SVG'] - @Param typeValue: string - @Envet $typeValue: (val: string) => void = (val:string) => {} + @Param typeValue: string = "" + @Event $typeValue: (val: string) => void = (val:string) => {} build() { Image($r('app.media.down')).width(30).height(30).position({ x: -30, y: 5 }).onClick(() => { @@ -62,12 +65,12 @@ export struct TypeCustomDialog { let contextNode = new ComponentContent(uiContext ,wrapBuilder(buildText),this.typeArr) CustomDialog.getInstance().contextNode = contextNode try { - promptAction.openCustomDialog(contextNode,{alignment: DialogAlignment.Center , onDisappear:()=>{ + promptAction.openCustomDialog(contextNode,{alignment: DialogAlignment.Center , onDidDisappear:()=>{ this.$typeValue(CustomDialog.getInstance().typeValue) }}) } catch(error) { - let message = (err as BusinessError).message - let code = (err as BusinessError).code + let message = (error as BusinessError).message + let code = (error as BusinessError).code } }) } diff --git a/sharedlibrary/src/main/ets/pages/TypeCustomDialog.ets b/sharedlibrary/src/main/ets/pages/TypeCustomDialog.ets index 00fac23..0c36916 100644 --- a/sharedlibrary/src/main/ets/pages/TypeCustomDialog.ets +++ b/sharedlibrary/src/main/ets/pages/TypeCustomDialog.ets @@ -12,6 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { BusinessError } from "@kit.BasicServicesKit" +import { PromptAction } from "@kit.ArkUI" + export class CustomDialog { private static instance: CustomDialog | null = null public promptAction: PromptAction | undefined = undefined @@ -19,7 +22,7 @@ export class CustomDialog { public typeValue: string = "" public static getInstance() { if (CustomDialog.instance == null) { - CustomDialog.instance = new instance() + CustomDialog.instance = new CustomDialog() } return CustomDialog.instance } @@ -51,8 +54,8 @@ function buildText(params:Array){ @ComponentV2 export struct TypeCustomDialog { private typeArr: string[] = ['Bitmap', 'Ovals', 'Color', 'Background', 'SVG'] - @Param typeValue: string - @Envet $typeValue: (val: string) => void = (val:string) => {} + @Param typeValue: string = "" + @Event $typeValue: (val: string) => void = (val:string) => {} build() { Image($r('app.media.down')).width(30).height(30).position({ x: -30, y: 5 }).onClick(() => { @@ -62,12 +65,12 @@ export struct TypeCustomDialog { let contextNode = new ComponentContent(uiContext ,wrapBuilder(buildText),this.typeArr) CustomDialog.getInstance().contextNode = contextNode try { - promptAction.openCustomDialog(contextNode,{alignment: DialogAlignment.Center , onDisappear:()=>{ + promptAction.openCustomDialog(contextNode,{alignment: DialogAlignment.Center , onDidDisappear:()=>{ this.$typeValue(CustomDialog.getInstance().typeValue) }}) } catch(error) { - let message = (err as BusinessError).message - let code = (err as BusinessError).code + let message = (error as BusinessError).message + let code = (error as BusinessError).code } }) } -- Gitee From 3eac82980726db0a8a63ab6d3512c8642ef3dfc2 Mon Sep 17 00:00:00 2001 From: zgf Date: Mon, 22 Jul 2024 14:49:21 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E9=80=82=E9=85=8DComponentV2=E8=A3=85?= =?UTF-8?q?=E9=A5=B0=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zgf --- build-profile.json5 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-profile.json5 b/build-profile.json5 index 618cbd8..b05e097 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -4,8 +4,8 @@ { "name": "default", "signingConfig": "default", - "compileSdkVersion": 10, - "compatibleSdkVersion": 10, + "compileSdkVersion": 12, + "compatibleSdkVersion": 12, "runtimeOS": "OpenHarmony" } ] -- Gitee From 2aebdfd59e69feda0181583d4a66b9afe86ea80b Mon Sep 17 00:00:00 2001 From: zgf Date: Tue, 23 Jul 2024 16:24:14 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E9=80=82=E9=85=8DComponentV2=E8=A3=85?= =?UTF-8?q?=E9=A5=B0=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zgf --- entry/src/main/ets/pages/TypeCustomDialog.ets | 2 +- sharedlibrary/src/main/ets/pages/TypeCustomDialog.ets | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/entry/src/main/ets/pages/TypeCustomDialog.ets b/entry/src/main/ets/pages/TypeCustomDialog.ets index f01c955..7bf7c74 100644 --- a/entry/src/main/ets/pages/TypeCustomDialog.ets +++ b/entry/src/main/ets/pages/TypeCustomDialog.ets @@ -13,7 +13,7 @@ * limitations under the License. */ import { BusinessError } from "@kit.BasicServicesKit" -import { PromptAction } from "@kit.ArkUI" +import { ComponentContent,PromptAction } from "@kit.ArkUI" export class CustomDialog { private static instance: CustomDialog | null = null diff --git a/sharedlibrary/src/main/ets/pages/TypeCustomDialog.ets b/sharedlibrary/src/main/ets/pages/TypeCustomDialog.ets index 0c36916..4615ae1 100644 --- a/sharedlibrary/src/main/ets/pages/TypeCustomDialog.ets +++ b/sharedlibrary/src/main/ets/pages/TypeCustomDialog.ets @@ -13,7 +13,7 @@ * limitations under the License. */ import { BusinessError } from "@kit.BasicServicesKit" -import { PromptAction } from "@kit.ArkUI" +import { ComponentContent,PromptAction } from "@kit.ArkUI" export class CustomDialog { private static instance: CustomDialog | null = null -- Gitee