diff --git a/CHANGELOG.md b/CHANGELOG.md index c22c304e16cd57d390cc83c947074113bdfa94fa..168aa7fde412878ab6ad7d32687681843f000e40 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/build-profile.json5 b/build-profile.json5 index 618cbd82ba3cb97e20647737de2ca1c2c28d2e02..b05e0977ff3bab1f2c31aad4fb7c8573f1b6895d 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" } ] diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 90fa48aefdb891afd9a91ff44f921e868afed8ae..cb4ca53b5c6142b5c2f0b978b764fb326a598aa6 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 ae9cd9c8f897a7d2095599d74e07614edff442b3..7bf7c7466aed35520b652c84d66862365a1bbdb2 100644 --- a/entry/src/main/ets/pages/TypeCustomDialog.ets +++ b/entry/src/main/ets/pages/TypeCustomDialog.ets @@ -12,33 +12,66 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { BusinessError } from "@kit.BasicServicesKit" +import { ComponentContent,PromptAction } from "@kit.ArkUI" -@CustomDialog +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 CustomDialog() + } + 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) + } + } +} + +@ComponentV2 export struct TypeCustomDialog { - private controller?: CustomDialogController private typeArr: string[] = ['Bitmap', 'Ovals', 'Color', 'Background', 'SVG'] - @Link private typeValue: string + @Param typeValue: string = "" + @Event $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 , onDidDisappear:()=>{ + this.$typeValue(CustomDialog.getInstance().typeValue) + }}) + } catch(error) { + let message = (error as BusinessError).message + let code = (error as BusinessError).code } - } + }) } } \ No newline at end of file diff --git a/library/oh-package.json5 b/library/oh-package.json5 index c50412086ce3afcf2a0a744d5029cc46e8cb92fb..90563bd31718a947849482610851da66a083cea2 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 b61b99e7b3955493401a25c06bd7b0687dfef3d6..092bf31cbc1a45755523092507dfcb653560b300 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 b304ae4ee0ab727d1b36e043a50aa6cda11a7416..260b4a905b8aa67da07f74d21f9230e4eaa8cb4c 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 ae9cd9c8f897a7d2095599d74e07614edff442b3..4615ae153372f0f66456f0451b3910a61c095048 100644 --- a/sharedlibrary/src/main/ets/pages/TypeCustomDialog.ets +++ b/sharedlibrary/src/main/ets/pages/TypeCustomDialog.ets @@ -12,33 +12,66 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { BusinessError } from "@kit.BasicServicesKit" +import { ComponentContent,PromptAction } from "@kit.ArkUI" -@CustomDialog +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 CustomDialog() + } + 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) + } + } +} + +@ComponentV2 export struct TypeCustomDialog { - private controller?: CustomDialogController private typeArr: string[] = ['Bitmap', 'Ovals', 'Color', 'Background', 'SVG'] - @Link private typeValue: string + @Param typeValue: string = "" + @Event $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 , onDidDisappear:()=>{ + this.$typeValue(CustomDialog.getInstance().typeValue) + }}) + } catch(error) { + let message = (error as BusinessError).message + let code = (error as BusinessError).code } - } + }) } } \ No newline at end of file