diff --git a/AppScope/app.json5 b/AppScope/app.json5 index f4f2da05979d4421b3ab5cc3cc7c1d145b655ea3..782c962c737a0fe8b549a1ce5a1e4c0b69a4ff7a 100644 --- a/AppScope/app.json5 +++ b/AppScope/app.json5 @@ -3,7 +3,7 @@ "bundleName": "com.example.roundimageview", "vendor": "example", "versionCode": 1000003, - "versionName": "1.0.4", + "versionName": "2.0.1", "icon": "$media:app_icon", "label": "$string:app_name", "distributedNotificationEnabled": true diff --git a/CHANGELOG.md b/CHANGELOG.md index 4577b7f345b06cdd256496f15c1ca24f95d7ecea..60a5d4005dae5345a1561ea95caa87f1380e479f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.1 +- ArkTs语法适配 +- 接口使用方式变更:GlobalContext替代globalThis + ## 2.0.0 - 适配DevEco Studio 版本:DevEco Studio 版本:4.0 Canary1(4.0.0.112), SDK: API10 (4.0.7.3) diff --git a/OAT.xml b/OAT.xml index 30f618aba685a2fe76a813d047b64e2c7a474a2d..0b8bc9ea1607af47d01427ae377a95069f98cc49 100644 --- a/OAT.xml +++ b/OAT.xml @@ -3,11 +3,15 @@ + + + + diff --git a/README.md b/README.md index 2aea48d26f0adcbfdba6216b867aada544af3c34..b52b27ee6111849b293f309b3f3dc4e1ce9055b1 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ OpenHarmony ohpm 环境配置等更多内容,请参考[如何安装 OpenHarmon ## 约束与限制 在下述版本验证通过: -- DevEco Studio 版本:4.0 Canary1(4.0.0.112), SDK: API10 (4.0.7.3)。 +- DevEco Studio: 4.0(4.0.3.512),SDK: API10(4.0.10.9) ## 目录结构 @@ -152,6 +152,7 @@ OpenHarmony ohpm 环境配置等更多内容,请参考[如何安装 OpenHarmon | |---- ScaleType.ts # ScaleType枚举 | |---- SrcType.ts # SrcType枚举 | |---- TileMode.ts # TileMode枚举 +| |---- GlobalContext.ts # GlobalContext替代globalThis | |---- README.md # 安装使用方法 ``` diff --git a/RoundedImageView/index.ets b/RoundedImageView/index.ets index 50b4fa9dd6f44e31aae5a951f2ddc9e288cf6c53..300ad87071ee509f9f833e6e869b18b6e67be993 100644 --- a/RoundedImageView/index.ets +++ b/RoundedImageView/index.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -export { default as RoundedImageView } from './src/main/ets/components/RoundedImageView' +export { RoundedImageName,RoundedImageView } from './src/main/ets/components/RoundedImageView' export { default as ScaleType } from './src/main/ets/components/ScaleType' @@ -22,3 +22,5 @@ export { default as TileMode } from './src/main/ets/components/TileMode' export { default as SrcType } from './src/main/ets/components/SrcType' export { default as FileUtils } from './src/main/ets/components/FileUtils' + +export { GlobalContext } from './src/main/ets/components/GlobalContext' diff --git a/RoundedImageView/oh-package.json5 b/RoundedImageView/oh-package.json5 index 5ebfbbc389a0892c5e49f0ef6f0a2ab8a8e2ab7e..205e21a5dcacf803b629880a334b4e520557b625 100644 --- a/RoundedImageView/oh-package.json5 +++ b/RoundedImageView/oh-package.json5 @@ -12,8 +12,8 @@ "description": "RoundedImageView支持许多附加功能,包括椭圆、圆角矩形、ScaleTypes 和 TileModes", "main": "index", "repository": "https://gitee.com/openharmony-sig/RoundedImageView", - "version": "2.0.0", + "version": "2.0.1", "dependencies": { "@ohos/svg": "2.0.0" } -} \ No newline at end of file +} diff --git a/RoundedImageView/src/main/ets/components/FileUtils.ts b/RoundedImageView/src/main/ets/components/FileUtils.ts index 080bbff871259ee5f8bfdd6dfd09091e0b800503..2b9805dd6a03ea9ba77e79e12b14d96ef5d0b6fd 100644 --- a/RoundedImageView/src/main/ets/components/FileUtils.ts +++ b/RoundedImageView/src/main/ets/components/FileUtils.ts @@ -58,7 +58,7 @@ class FileUtils { /** * 创建文件夹 */ - createFolder(path: string) { + createFolder(path: string):void { //创建文件夹 if (!this.existFolder(path)) { fileio.mkdirSync(path) diff --git a/RoundedImageView/src/main/ets/components/GlobalContext.ts b/RoundedImageView/src/main/ets/components/GlobalContext.ts new file mode 100644 index 0000000000000000000000000000000000000000..0595a2e943beeff6c4383bee2dc0bfce3d90754c --- /dev/null +++ b/RoundedImageView/src/main/ets/components/GlobalContext.ts @@ -0,0 +1,37 @@ +// @ts-nocheck +/* + * Copyright (C) 2022 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 GlobalContext { + private constructor() {} + private static instance: GlobalContext; + private _objects = new Map(); + + public static getContext(): GlobalContext { + if (!GlobalContext.instance) { + GlobalContext.instance = new GlobalContext(); + } + return GlobalContext.instance; + } + + getObject(value: string):Object { + return this._objects.get(value); + } + + setObject(key: string, objectClass: Object): void { + this._objects.set(key, objectClass); + } + +} \ No newline at end of file diff --git a/RoundedImageView/src/main/ets/components/PixelMapUtils.ts b/RoundedImageView/src/main/ets/components/PixelMapUtils.ts index d534c6daa94a3c6851f224a43075b2ad68775933..6af1b5f14d71afd37a550cb5aa0abd33ad84d0dd 100644 --- a/RoundedImageView/src/main/ets/components/PixelMapUtils.ts +++ b/RoundedImageView/src/main/ets/components/PixelMapUtils.ts @@ -15,14 +15,16 @@ */ import image from '@ohos.multimedia.image'; -import SrcType from './srctype'; -import DownloadUtils from './downloadutils'; +import SrcType from './SrcType'; +import DownloadUtils from './DownloadUtils'; +import { GlobalContext } from './GlobalContext'; class PixelMapUtils { - public static createPixelMap(src: string | Resource | ArrayBuffer, srcType: SrcType, callback: (pixelMap: image.PixelMap, width: number, height: number, error?: Error) => void): void { + public static createPixelMap(src: string | Resource | ArrayBuffer, srcType: SrcType | null, callback: (pixelMap: image.PixelMap, width: number, height: number, error?: Error) => void): void { + let context:Context = GlobalContext.getContext().getObject("context") as Context switch (srcType) { case SrcType.MEDIA: //media相关数据 - globalThis.resourceManager.getMediaContent(src.id, (error, value) => { + context.resourceManager.getMediaContent(src.id, (error, value) => { if (error != null) { console.log("error is " + error); } else if(value){ @@ -31,7 +33,7 @@ class PixelMapUtils { }) break case SrcType.RAWFILE: //本地rawfile相关数据 - globalThis.resourceManager.getRawFileContent(src, (error, value) => { + context.resourceManager.getRawFileContent(src, (error, value) => { if (error != null) { console.log("error is " + error); } else if(value){ @@ -43,10 +45,9 @@ class PixelMapUtils { this.callbackPixelMap(src, callback) break case SrcType.URL: //url相关数据 - let that = this new DownloadUtils().loadData(src, (arrayBuffer, error) => { if (!error) { - that.callbackPixelMap(arrayBuffer, callback) + this.callbackPixelMap(arrayBuffer, callback) } }) break diff --git a/RoundedImageView/src/main/ets/components/RoundedImageView.ets b/RoundedImageView/src/main/ets/components/RoundedImageView.ets index 643417c30fceaf15ea0ac301446043bc132f57b8..30cea36799feeda6856c2eab9ac018b89767e8fb 100644 --- a/RoundedImageView/src/main/ets/components/RoundedImageView.ets +++ b/RoundedImageView/src/main/ets/components/RoundedImageView.ets @@ -14,23 +14,25 @@ */ import { SVGImageView } from '@ohos/svg'; -import PixelMapUtils from './pixelmaputils'; -import ScaleType from './scaletype'; -import TileMode from './tilemode'; -import SrcType from './srctype'; +import PixelMapUtils from './PixelMapUtils'; +import ScaleType from './ScaleType'; +import TileMode from './TileMode'; +import SrcType from './SrcType'; +import { GlobalContext } from './GlobalContext'; + @Component -struct RoundedImageView { - @State model: RoundedImageView.Model = new RoundedImageView.Model() +export struct RoundedImageView { + @State 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) - private img: PixelMap - private srcWidth: number - private srcHeight: number + private img: PixelMap | null = null + private srcWidth: number = 0; + private srcHeight: number = 0; private minScale: number = 1 - private scaleW: number - private scaleH: number + private scaleW: number = 0; + private scaleH: number = 0; private svgImageViewModel: SVGImageView.SVGImageViewModel = new SVGImageView.SVGImageViewModel() public aboutToAppear() { @@ -63,33 +65,35 @@ struct RoundedImageView { } setImage() { - switch (this.model.scaleType) { - case ScaleType.FIT_START: - this.context.drawImage(this.img, 0, 0, this.srcWidth, this.srcHeight) - break - case ScaleType.FIT_END: - this.context.drawImage(this.img, (this.model.uiWidth - this.model.padding * 2 - this.srcWidth * this.minScale) / (this.minScale * 1), (this.model.uiHeight - this.model.padding * 2 - this.srcHeight * this.minScale) / (this.minScale * 1), this.srcWidth, this.srcHeight) - break - case ScaleType.FIT_CENTER: - this.context.drawImage(this.img, (this.model.uiWidth - this.model.padding * 2 - this.srcWidth * this.minScale) / (this.minScale * 2), (this.model.uiHeight - this.model.padding * 2 - this.srcHeight * this.minScale) / (this.minScale * 2), this.srcWidth, this.srcHeight) - break - case ScaleType.CENTER: - this.context.drawImage(this.img, (this.model.uiWidth - this.model.padding * 2 - this.srcWidth) / 2, (this.model.uiHeight - this.model.padding * 2 - this.srcHeight) / 2, this.srcWidth, this.srcHeight) - break - case ScaleType.CENTER_CROP: - this.context.drawImage(this.img, (this.model.uiWidth - this.model.padding * 2 - this.srcWidth * this.minScale) / (this.minScale * 2), (this.model.uiHeight - this.model.padding * 2 - this.srcHeight * this.minScale) / (this.minScale * 2), this.srcWidth, this.srcHeight) - break - case ScaleType.FIT_XY: - if (this.model.tileMode == TileMode.REPEAT || this.model.tileMode == TileMode.MIRROR) { - this.context.restore() - this.setTileMode() - } else { + if (!!this.img) { + switch (this.model.scaleType) { + case ScaleType.FIT_START: this.context.drawImage(this.img, 0, 0, this.srcWidth, this.srcHeight) - } - break - case ScaleType.CENTER_INSIDE: - this.context.drawImage(this.img, (this.model.uiWidth - this.model.padding * 2 - this.srcWidth * this.minScale) / (this.minScale * 2), (this.model.uiHeight - this.model.padding * 2 - this.srcHeight * this.minScale) / (this.minScale * 2), this.srcWidth, this.srcHeight) - break + break + case ScaleType.FIT_END: + this.context.drawImage(this.img, (this.model.uiWidth - this.model.padding * 2 - this.srcWidth * this.minScale) / (this.minScale * 1), (this.model.uiHeight - this.model.padding * 2 - this.srcHeight * this.minScale) / (this.minScale * 1), this.srcWidth, this.srcHeight) + break + case ScaleType.FIT_CENTER: + this.context.drawImage(this.img, (this.model.uiWidth - this.model.padding * 2 - this.srcWidth * this.minScale) / (this.minScale * 2), (this.model.uiHeight - this.model.padding * 2 - this.srcHeight * this.minScale) / (this.minScale * 2), this.srcWidth, this.srcHeight) + break + case ScaleType.CENTER: + this.context.drawImage(this.img, (this.model.uiWidth - this.model.padding * 2 - this.srcWidth) / 2, (this.model.uiHeight - this.model.padding * 2 - this.srcHeight) / 2, this.srcWidth, this.srcHeight) + break + case ScaleType.CENTER_CROP: + this.context.drawImage(this.img, (this.model.uiWidth - this.model.padding * 2 - this.srcWidth * this.minScale) / (this.minScale * 2), (this.model.uiHeight - this.model.padding * 2 - this.srcHeight * this.minScale) / (this.minScale * 2), this.srcWidth, this.srcHeight) + break + case ScaleType.FIT_XY: + if (this.model.tileMode == TileMode.REPEAT || this.model.tileMode == TileMode.MIRROR) { + this.context.restore() + this.setTileMode() + } else { + this.context.drawImage(this.img, 0, 0, this.srcWidth, this.srcHeight) + } + break + case ScaleType.CENTER_INSIDE: + this.context.drawImage(this.img, (this.model.uiWidth - this.model.padding * 2 - this.srcWidth * this.minScale) / (this.minScale * 2), (this.model.uiHeight - this.model.padding * 2 - this.srcHeight * this.minScale) / (this.minScale * 2), this.srcWidth, this.srcHeight) + break + } } } @@ -189,22 +193,28 @@ struct RoundedImageView { this.context.scale(-1, -1) } } - this.context.drawImage(this.img, indexW * this.srcWidth, indexH * this.srcHeight, this.srcWidth, this.srcHeight) - this.context.restore() + if(!!this.img){ + this.context.drawImage(this.img, indexW * this.srcWidth, indexH * this.srcHeight, this.srcWidth, this.srcHeight) + this.context.restore() + } } } this.context.restore() } private getSvgData(callback: (svgData: Uint8Array) => void) { + let context:Context = GlobalContext.getContext().getObject("context") as Context + switch (this.model.srcType) { case SrcType.MEDIA: - globalThis.resourceManager.getMedia(this.model.src, (error, value) => { - callback(value); - }) + let mediaSrc:Resource = this.model.src as Resource + context.resourceManager.getMediaContent(mediaSrc.id, (error:Error, value:Uint8Array) => { + callback(value); + }) break case SrcType.RAWFILE: - globalThis.resourceManager.getRawFile(this.model.src, (error, value) => { + let rawfileSrc:string = this.model.src as string + context.resourceManager.getRawFileContent(rawfileSrc, (error:Error, value:Uint8Array) => { callback(value); }) break @@ -214,9 +224,9 @@ struct RoundedImageView { private drawBitmap() { if (this.model.getIsSvg()) { this.getSvgData(svgData => { - this.svgImageViewModel.getSVGPixelMap(svgData).then(pixmap => { + this.svgImageViewModel.getSVGPixelMap(svgData).then((pixmap:PixelMap) => { this.img = pixmap; - this.img.getImageInfo().then(imageInfo => { + this.img?.getImageInfo().then(imageInfo => { this.srcWidth = imageInfo.size.width this.srcHeight = imageInfo.size.height this.scaleW = (this.model.uiWidth - this.model.padding * 2) / this.srcWidth @@ -264,9 +274,9 @@ struct RoundedImageView { private async drawOvals() { if (this.model.getIsSvg()) { this.getSvgData(svgData => { - this.svgImageViewModel.getSVGPixelMap(svgData).then(pixmap => { + this.svgImageViewModel.getSVGPixelMap(svgData).then((pixmap:PixelMap) => { this.img = pixmap; - this.img.getImageInfo().then(imageInfo => { + this.img?.getImageInfo().then(imageInfo => { this.srcWidth = imageInfo.size.width this.srcHeight = imageInfo.size.height this.scaleW = (this.model.uiWidth - this.model.padding * 2) / this.srcWidth @@ -421,7 +431,7 @@ struct RoundedImageView { .height(this.model.uiHeight) .onReady(() => { let that = this - let timeoutID = setTimeout(function () { + let timeoutID = setTimeout( () => { that.drawBitmap() clearTimeout(timeoutID) }, 100); @@ -431,28 +441,28 @@ struct RoundedImageView { } } -namespace RoundedImageView { +export namespace RoundedImageName { export class Model { - src: string | Resource | ArrayBuffer; - srcType: SrcType - isSvg: boolean - typeValue: string - uiWidth: number - uiHeight: number - backgroundColor: string | CanvasGradient | CanvasPattern - tileMode: TileMode - scaleType: ScaleType - cornerRadius: number - borderWidth: number - borderColor: string | CanvasGradient | CanvasPattern - padding: number - colorWidth: number - colorHeight: number + src: string | ArrayBuffer | Resource = '' + srcType: SrcType | null = null + isSvg: boolean = false + typeValue: string = ''; + uiWidth: number = 0; + uiHeight: number = 0; + backgroundColor: string | CanvasGradient | CanvasPattern = '' + tileMode: TileMode | null = null + scaleType: ScaleType | null = null + cornerRadius: number = 0; + borderWidth: number = 0; + borderColor: string | CanvasGradient | CanvasPattern = '' + padding: number = 0; + colorWidth: number = 0; + colorHeight: number = 0; constructor() { } - setImageSrc(src: string | Resource | ArrayBuffer): Model { + setImageSrc(src: string | ArrayBuffer | Resource): Model { this.src = src; return this; } @@ -461,13 +471,15 @@ namespace RoundedImageView { return this.src; } - setSrcType(srcType: SrcType): Model { + setSrcType(srcType: SrcType | null): Model { this.srcType = srcType; return this; } - getSrcType(): SrcType { - return this.srcType; + getSrcType(): SrcType | void { + if(this.srcType !== null){ + return this.srcType; + } } setIsSvg(isSvg: boolean): Model { @@ -511,17 +523,21 @@ namespace RoundedImageView { return this; } - getScaleType(): ScaleType { - return this.scaleType; + getScaleType(): ScaleType| void { + if(this.scaleType !== null){ + return this.scaleType; + } } - setTileModeXY(tileMode: TileMode): Model { + setTileModeXY(tileMode: TileMode | null): Model { this.tileMode = tileMode; return this; } - getTileModeXY(): TileMode { - return this.tileMode; + getTileModeXY(): TileMode | void{ + if( this.tileMode !== null){ + return this.tileMode; + } } setBackgroundColor(backgroundColor: string | CanvasGradient | CanvasPattern): Model { @@ -589,4 +605,3 @@ namespace RoundedImageView { } } -export default RoundedImageView; diff --git a/build-profile.json5 b/build-profile.json5 index 696f607ccceac71162523d4037b72c8afa2f2847..416203c8d8248a6c21dad6e3e8cf6f91d495b483 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -1,11 +1,12 @@ { "app": { - "compileSdkVersion": 9, - "compatibleSdkVersion": 9, "products": [ { "name": "default", "signingConfig": "default", + "compileSdkVersion": 10, + "compatibleSdkVersion": 10, + "runtimeOS": "OpenHarmony" } ] }, diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 index 13fe9c24aea7db3d0ac6704e8ca9bb10dd52ff6b..cf9f48985f3daf123b949a666dbc753e624fbd62 100644 --- a/entry/oh-package.json5 +++ b/entry/oh-package.json5 @@ -4,8 +4,8 @@ "name": "entry", "description": "example description", "repository": {}, - "version": "2.0.0", + "version": "2.0.1", "dependencies": { - "@ohos/roundedimageview": "file:../Roundedimageview" + "@ohos/roundedimageview": "file:../RoundedImageView" } -} \ No newline at end of file +} diff --git a/entry/src/main/ets/entryability/EntryAbility.ts b/entry/src/main/ets/entryability/EntryAbility.ets similarity index 78% rename from entry/src/main/ets/entryability/EntryAbility.ts rename to entry/src/main/ets/entryability/EntryAbility.ets index aa6d4cbc50aabc29972b00dbbc934d338328f5cc..2c58572d30fa62fbbb818561e326d5a540ed37d2 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ts +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -17,17 +17,19 @@ import UIAbility from '@ohos.app.ability.UIAbility'; import hilog from '@ohos.hilog'; import window from '@ohos.window'; import display from '@ohos.display'; +import { GlobalContext } from '@ohos/roundedimageview'; +import Want from '@ohos.app.ability.Want'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; export default class EntryAbility extends UIAbility { - onCreate(want, launchParam) { + onCreate(want:Want, launchParam:AbilityConstant.LaunchParam) { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); - globalThis.abilityWant = want; - globalThis.globalFilesDir = this.context.filesDir let displayWH = display.getDefaultDisplaySync() - globalThis.deviceW = displayWH.width; - globalThis.deviceH = displayWH.height; - globalThis.resourceManager = this.context.resourceManager; - globalThis.context = this.context + GlobalContext.getContext().setObject("abilityWant", want); + GlobalContext.getContext().setObject("globalFilesDir", this.context.filesDir); + GlobalContext.getContext().setObject("deviceW", displayWH.width); + GlobalContext.getContext().setObject("deviceH", displayWH.height); + GlobalContext.getContext().setObject("context", this.context); } onDestroy() { diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index a3a2e119a79ff36ea64e965997f253d09c33cf23..67f6a25ee1adc7ed297e44e0537b05260d10ff5a 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -15,18 +15,19 @@ import { PictureItem } from './PictureItem' import { TypeCustomDialog } from './TypeCustomDialog' -import { RoundedImageView, ScaleType, TileMode, SrcType, FileUtils } from '@ohos/roundedimageview' +import { RoundedImageView,RoundedImageName, ScaleType, TileMode, SrcType, FileUtils, GlobalContext } from '@ohos/roundedimageview' @Entry @Component 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] - private uiWidth: number = px2vp(globalThis.deviceW * 0.9) + private uiWidth: number = px2vp((GlobalContext.getContext().getObject("deviceW") as number) * 0.9) private uiHeight: number = px2vp(500) - private uriFolder: string = globalThis.globalFilesDir + "/" + "uriFolder" + + private uriFolder: string = (GlobalContext.getContext().getObject("globalFilesDir") as string) + "/" + "uriFolder" private uriFile: string = this.uriFolder + "/" + "photo1.jpg" - private viewModels: RoundedImageView.Model [] = []; + private viewModels: RoundedImageName.Model [] = []; private scroller: Scroller = new Scroller() private dialogController: CustomDialogController = new CustomDialogController({ alignment: DialogAlignment.Top, @@ -45,7 +46,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -62,7 +63,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor:'', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -79,7 +80,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -96,7 +97,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -113,7 +114,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -130,7 +131,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -147,7 +148,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -164,7 +165,7 @@ struct Index { tileMode: TileMode.REPEAT, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -181,7 +182,7 @@ struct Index { tileMode: TileMode.CLAMP, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -198,7 +199,7 @@ struct Index { tileMode: TileMode.MIRROR, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -217,7 +218,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 0, borderWidth: 10, borderColor: '#317AF7', @@ -234,7 +235,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 0, borderWidth: 10, borderColor: '#317AF7', @@ -251,7 +252,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 0, borderWidth: 10, borderColor: '#317AF7', @@ -268,7 +269,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 0, borderWidth: 10, borderColor: '#317AF7', @@ -285,7 +286,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 0, borderWidth: 10, borderColor: '#317AF7', @@ -302,7 +303,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 0, borderWidth: 10, borderColor: '#317AF7', @@ -319,7 +320,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 0, borderWidth: 10, borderColor: '#317AF7', @@ -336,7 +337,7 @@ struct Index { tileMode: TileMode.REPEAT, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 0, borderWidth: 10, borderColor: '#317AF7', @@ -353,7 +354,7 @@ struct Index { tileMode: TileMode.CLAMP, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 0, borderWidth: 10, borderColor: '#317AF7', @@ -370,7 +371,7 @@ struct Index { tileMode: TileMode.MIRROR, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 0, borderWidth: 10, borderColor: '#317AF7', @@ -379,7 +380,7 @@ struct Index { ] private colorItems: PictureItem [] = [ { - src: null, + src: '', srcType: null, isSvg: false, primaryTitle: 'Color', @@ -396,7 +397,7 @@ struct Index { padding: 0 }, { - src: null, + src: '', srcType: null, isSvg: false, primaryTitle: 'Color', @@ -413,7 +414,7 @@ struct Index { padding: 0 }, { - src: null, + src: '', srcType: null, isSvg: false, primaryTitle: 'Color', @@ -430,7 +431,7 @@ struct Index { padding: 0 }, { - src: null, + src: '', srcType: null, isSvg: false, primaryTitle: 'Color', @@ -447,7 +448,7 @@ struct Index { padding: 0 }, { - src: null, + src: '', srcType: null, isSvg: false, primaryTitle: 'Color', @@ -464,7 +465,7 @@ struct Index { padding: 0 }, { - src: null, + src: '', srcType: null, isSvg: false, primaryTitle: 'Color', @@ -481,7 +482,7 @@ struct Index { padding: 0 }, { - src: null, + src: '', srcType: null, isSvg: false, primaryTitle: 'Color', @@ -682,7 +683,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -699,7 +700,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -716,7 +717,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -733,7 +734,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -750,7 +751,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -767,7 +768,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -784,7 +785,7 @@ struct Index { tileMode: null, uiWidth: this.uiWidth, uiHeight: this.uiHeight, - backgroundColor: null, + backgroundColor: '', cornerRadius: 25, borderWidth: 10, borderColor: '#317AF7', @@ -801,8 +802,8 @@ struct Index { private initViewModels(): void { let viewModelsLength = Math.max(this.picIdxArr.length, this.colorIdxArr.length) - for (var index = 0; index < viewModelsLength; index++) { - this.viewModels.push(new RoundedImageView.Model) + for (let index = 0; index < viewModelsLength; index++) { + this.viewModels.push(new RoundedImageName.Model) } } @@ -844,8 +845,8 @@ struct Index { } private initUri() { - FileUtils.getInstance().createFolder(this.uriFolder) - globalThis.resourceManager.getMedia($r('app.media.photo1').id, (error, value) => { + FileUtils.getInstance().createFolder(this.uriFolder); + (GlobalContext.getContext().getObject("context") as Context).resourceManager.getMedia($r('app.media.photo1').id, (error: Error, value: Uint8Array) => { FileUtils.getInstance().writePic(this.uriFile, value.buffer) }) } @@ -863,35 +864,35 @@ struct Index { Scroll(this.scroller) { List({ space: 10, initialIndex: 0 }) { if (this.typeValue == 'Bitmap') { - ForEach(this.picIdxArr, (item) => { + ForEach(this.picIdxArr, (item:number) => { ListItem() { this.ViewItem(this.viewModels[item], this.rectPictureItems[item]) }.editable(false) - }, item => item) + }, (item:string) => item) } else if (this.typeValue == 'Ovals') { - ForEach(this.picIdxArr, (item) => { + ForEach(this.picIdxArr, (item:number) => { ListItem() { this.ViewItem(this.viewModels[item], this.ovalPictureItems[item]) }.editable(false) - }, item => item) + }, (item:string) => item) } else if (this.typeValue == 'Color') { - ForEach(this.colorIdxArr, (item) => { + ForEach(this.colorIdxArr, (item:number) => { ListItem() { this.ViewItem(this.viewModels[item], this.colorItems[item]) }.editable(false) - }, item => item) + }, (item:string) => item) } else if (this.typeValue == 'Background') { - ForEach(this.picIdxArr, (item) => { + ForEach(this.picIdxArr, (item:number) => { ListItem() { this.ViewItem(this.viewModels[item], this.backgroundColorItems[item]) }.editable(false) - }, item => item) + }, (item:string) => item) } else if (this.typeValue == 'SVG') { - ForEach(this.colorIdxArr, (item) => { + ForEach(this.colorIdxArr, (item:number) => { ListItem() { this.ViewItem(this.viewModels[item], this.svgItems[item]) }.editable(false) - }, item => item) + }, (item:string) => item) } } } @@ -904,7 +905,7 @@ struct Index { } } - @Builder ViewItem(roundedImageViewModel: RoundedImageView.Model, pictureItem: PictureItem) { + @Builder ViewItem(roundedImageViewModel: RoundedImageName.Model, pictureItem: PictureItem) { Column({ space: 5 }) { RoundedImageView({ model: roundedImageViewModel }) Column() { diff --git a/entry/src/main/ets/pages/PictureItem.ets b/entry/src/main/ets/pages/PictureItem.ets index c2bf923368886d6f9c2b8acbc1f3a99afd5eed1f..fe48f81e9573c6e3a8b6b581f54d63811e351edd 100644 --- a/entry/src/main/ets/pages/PictureItem.ets +++ b/entry/src/main/ets/pages/PictureItem.ets @@ -13,18 +13,18 @@ * limitations under the License. */ -import { ScaleType, TileMode, SrcType } from '@ohos/roundedimageview/' +import { ScaleType, TileMode, SrcType } from '@ohos/roundedimageview' export interface PictureItem { src: string | Resource | ArrayBuffer - srcType: SrcType + srcType: SrcType | null isSvg: boolean primaryTitle: string secondTitle: string scaleTypeName: string scaleType: ScaleType - tileMode: TileMode + tileMode: TileMode | null uiWidth: number uiHeight: number backgroundColor: string | CanvasGradient | CanvasPattern diff --git a/entry/src/main/ets/pages/TypeCustomDialog.ets b/entry/src/main/ets/pages/TypeCustomDialog.ets index 3b2fd3bb8b3004184f2cccfe4b1043dc1cc70c24..ae9cd9c8f897a7d2095599d74e07614edff442b3 100644 --- a/entry/src/main/ets/pages/TypeCustomDialog.ets +++ b/entry/src/main/ets/pages/TypeCustomDialog.ets @@ -15,7 +15,7 @@ @CustomDialog export struct TypeCustomDialog { - private controller: CustomDialogController + private controller?: CustomDialogController private typeArr: string[] = ['Bitmap', 'Ovals', 'Color', 'Background', 'SVG'] @Link private typeValue: string @@ -23,7 +23,7 @@ export struct TypeCustomDialog { Row() { Scroll() { List({ space: 10, initialIndex: 0 }) { - ForEach(this.typeArr, (item) => { + ForEach(this.typeArr, (item:string) => { ListItem() { Text(item) .width('100%') @@ -33,10 +33,10 @@ export struct TypeCustomDialog { .backgroundColor(0xFFFFFF) .onClick(() => { this.typeValue = item - this.controller.close(); + this.controller?.close(); }) } - }, item => item) + }, (item:string) => item) }.backgroundColor(Color.White).width(200).padding(20) } } diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 index a811626e8b8d6a819161b3583cd1947c0b642fc3..42c5c72e4857e23b119f3c1cdad1eda32ddd1e96 100644 --- a/entry/src/main/module.json5 +++ b/entry/src/main/module.json5 @@ -20,7 +20,7 @@ "abilities": [ { "name": "EntryAbility", - "srcEntrance": "./ets/entryability/EntryAbility.ts", + "srcEntrance": "./ets/entryability/EntryAbility.ets", "description": "$string:EntryAbility_desc", "icon": "$media:icon", "label": "$string:EntryAbility_label", diff --git a/entry/src/ohosTest/ets/test/Ability.test.ets b/entry/src/ohosTest/ets/test/Ability.test.ets index c5767a5830e22e85288e24acb79493f14cb8d318..a7a68e9ec2e25102175788bbbcbc7d8fc3ede427 100644 --- a/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/entry/src/ohosTest/ets/test/Ability.test.ets @@ -17,27 +17,27 @@ import hilog from '@ohos.hilog'; import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' export default function abilityTest() { - describe('ActsAbilityTest', function () { + describe('ActsAbilityTest', () => { // Defines a test suite. Two parameters are supported: test suite name and test suite function. - beforeAll(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(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(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(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, 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' diff --git a/entry/src/ohosTest/ets/testability/TestAbility.ets b/entry/src/ohosTest/ets/testability/TestAbility.ets index 63b809e424e9b75401c9a32cf2160f145e1fb902..d3c905d5c2119eeacf531fe44752daf1b24837f1 100644 --- a/entry/src/ohosTest/ets/testability/TestAbility.ets +++ b/entry/src/ohosTest/ets/testability/TestAbility.ets @@ -19,18 +19,15 @@ import hilog from '@ohos.hilog'; import { Hypium } from '@ohos/hypium'; import testsuite from '../test/List.test'; import window from '@ohos.window'; - +import Want from '@ohos.app.ability.Want'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; export default class TestAbility extends UIAbility { - onCreate(want, launchParam) { + onCreate(want:Want, launchParam:AbilityConstant.LaunchParam) { hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate'); hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? ''); - var abilityDelegator: any - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var abilityDelegatorArguments: any - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!'); - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + Hypium.hypiumTest(AbilityDelegatorRegistry.getAbilityDelegator(), AbilityDelegatorRegistry.getArguments(), testsuite) } onDestroy() { diff --git a/hvigor/hvigor-config.json5 b/hvigor/hvigor-config.json5 index ff688122467308d3cd299c5b2f36be03fb84f4b0..e75281b258e8cec776a34fd96a3c117c58afb9cb 100644 --- a/hvigor/hvigor-config.json5 +++ b/hvigor/hvigor-config.json5 @@ -1,6 +1,6 @@ { - "hvigorVersion": "2.0.0", + "hvigorVersion": "3.0.2", "dependencies": { - "@ohos/hvigor-ohos-plugin": "2.0.0" + "@ohos/hvigor-ohos-plugin": "3.0.2" } -} +} \ No newline at end of file diff --git a/hvigorw b/hvigorw new file mode 100644 index 0000000000000000000000000000000000000000..54aadd226b453397860013d328fd01031648fc31 --- /dev/null +++ b/hvigorw @@ -0,0 +1,48 @@ +#!/bin/bash + +# ---------------------------------------------------------------------------- +# Hvigor startup script, version 1.0.0 +# +# Required ENV vars: +# ------------------ +# NODE_HOME - location of a Node home dir +# or +# Add /usr/local/nodejs/bin to the PATH environment variable +# ---------------------------------------------------------------------------- + +HVIGOR_APP_HOME=$(dirname $(readlink -f $0)) +HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js +warn() { + echo "" + echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m" +} + +error() { + echo "" + echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m" +} + +fail() { + error "$@" + exit 1 +} + +# Determine node to start hvigor wrapper script +if [ -n "${NODE_HOME}" ];then + EXECUTABLE_NODE="${NODE_HOME}/bin/node" + if [ ! -x "$EXECUTABLE_NODE" ];then + fail "ERROR: NODE_HOME is set to an invalid directory,check $NODE_HOME\n\nPlease set NODE_HOME in your environment to the location where your nodejs installed" + fi +else + EXECUTABLE_NODE="node" + which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path" +fi + +# Check hvigor wrapper script +if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then + fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}" +fi + +# start hvigor-wrapper script +exec "${EXECUTABLE_NODE}" \ + "${HVIGOR_WRAPPER_SCRIPT}" "$@" diff --git a/hvigorw.bat b/hvigorw.bat new file mode 100644 index 0000000000000000000000000000000000000000..29196b4d4e82f370133574d33636bdf9c7440a0b --- /dev/null +++ b/hvigorw.bat @@ -0,0 +1,57 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Hvigor startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js +set NODE_EXE=node.exe + +goto start + +:start +@rem Find node.exe +if defined NODE_HOME goto findNodeFromNodeHome + +%NODE_EXE% --version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH. +echo. +echo Please set the NODE_HOME variable in your environment to match the +echo location of your NodeJs installation. + +goto fail + +:findNodeFromNodeHome +set NODE_HOME=%NODE_HOME:"=% +set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE% + +if exist "%NODE_EXE_PATH%" goto execute +echo. +echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH. +echo. +echo Please set the NODE_HOME variable in your environment to match the +echo location of your NodeJs installation. + +goto fail + +:execute +@rem Execute hvigor +"%NODE_EXE%" %WRAPPER_MODULE_PATH% %* + +:fail +exit /b 1 diff --git a/oh-package.json5 b/oh-package.json5 index 5797065f8d7420c3ef96827e88e96f951ac01647..aed62c9e2b2e2f89d4c138129c06da1ec83e8a54 100644 --- a/oh-package.json5 +++ b/oh-package.json5 @@ -6,6 +6,6 @@ "name": "roundimageview", "description": "example description", "repository": {}, - "version": "2.0.0", + "version": "2.0.1", "dependencies": {} -} \ No newline at end of file +}