From 9bf705c7114e32238a123461c45eafd2a125d7d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=89=BA=E4=B8=BA?= Date: Thu, 3 Aug 2023 11:52:25 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=9B=B4=E6=96=B0readme.md=202.=E6=9B=B4?= =?UTF-8?q?=E6=96=B0hvigor-ohos-plugin=E7=89=88=E6=9C=AC=E7=94=B12.0.0?= =?UTF-8?q?=E5=88=B02.4.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李艺为 --- .gitignore | 8 +++- README.md | 77 ++++++++++++++++++++++++-------------- build-profile.json5 | 3 +- entry/.gitignore | 4 +- hvigor/hvigor-config.json5 | 6 +-- imageknife/.gitignore | 4 +- 6 files changed, 67 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 39187eb..0b73d89 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,10 @@ /node_modules /local.properties /.idea -**/build \ No newline at end of file +**/build +/oh_modules/ +/.hvigor/ +/oh-package-lock.json5 +/.clangd +/.clang-format +/.clang-tidy diff --git a/README.md b/README.md index df7372f..1b318ab 100644 --- a/README.md +++ b/README.md @@ -22,19 +22,40 @@ ohpm install @ohos/imageknife ``` ## 使用说明 +### 0.依赖配置 -1.在AbilityStage.ts中,初始化全局ImageKnife实例。 +0.1.在项目中entry/oh-package.json5中做如下修改,然后点击Sync Now: +```json5 +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "@ohos/imageknife": "^2.0.2" + } +} +``` + +0.2.在entry\src\main\ets\entryability\EntryAbility.ts中做如下配置初始化全局ImageKnife实例: ```typescript -import AbilityStage from "@ohos.application.AbilityStage" -import {ImageKnife} from '@ohos/imageknife' +import UIAbility from '@ohos.app.ability.UIAbility'; +import window from '@ohos.window'; +import { ImageKnife } from '@ohos/imageknife' -export default class MyAbilityStage extends AbilityStage { - onCreate() { - // 初始化全局ImageKnife实例,在AbilityStage.ts中调用ImageKnife.with(this.context)进行初始化 - globalThis.ImageKnife = ImageKnife.with(this.context) - } - } +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + globalThis.ImageKnife = ImageKnife.with(this.context); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent('pages/Index', (err, data) => { + }); + } +} ``` ### 1.加载普通图片 @@ -42,30 +63,30 @@ export default class MyAbilityStage extends AbilityStage { 接下来我们来写个简单实例看看: ```typescript -import {ImageKnifeComponent} from '@ohos/imageknife' -import {ImageKnifeOption} from '@ohos/imageknife' +import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife' + @Entry @Component struct Index { - @State imageKnifeOption1: ImageKnifeOption = - { // 加载一张本地的jpg资源(必选) - loadSrc: $r('app.media.jpgSample'), - // 占位图使用本地资源icon_loading(可选) - placeholderSrc: $r('app.media.icon_loading'), - // 失败占位图使用本地资源icon_failed(可选) - errorholderSrc: $r('app.media.icon_failed') - }; - build() { - Scroll() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { - ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 }) - .width(300) // 自定义组件支持通用属性链式调用,可以直接设置宽高 + @State message: string = 'Hello World' + @State option: ImageKnifeOption = { + loadSrc: $r('app.media.icon') + } + +build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + ImageKnifeComponent({ imageKnifeOption: this.option }) + .width(300) .height(300) } - } - .width('100%') - .height('100%') - } +.width('100%') +} +.height('100%') +} } ``` diff --git a/build-profile.json5 b/build-profile.json5 index 46629bc..0ac1294 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -7,7 +7,8 @@ "name": "default", "signingConfig": "default" } - ] + ], + "signingConfigs": [] }, "modules": [ { diff --git a/entry/.gitignore b/entry/.gitignore index 4f9a973..f8fba9f 100644 --- a/entry/.gitignore +++ b/entry/.gitignore @@ -1,3 +1,5 @@ /node_modules /.preview -/build \ No newline at end of file +/build +/oh_modules/ +/oh-package-lock.json5 diff --git a/hvigor/hvigor-config.json5 b/hvigor/hvigor-config.json5 index ff68812..ec2a3ae 100644 --- a/hvigor/hvigor-config.json5 +++ b/hvigor/hvigor-config.json5 @@ -1,6 +1,6 @@ { - "hvigorVersion": "2.0.0", + "hvigorVersion": "2.4.2", "dependencies": { - "@ohos/hvigor-ohos-plugin": "2.0.0" + "@ohos/hvigor-ohos-plugin": "2.4.2" } -} +} \ No newline at end of file diff --git a/imageknife/.gitignore b/imageknife/.gitignore index 4f9a973..f8fba9f 100644 --- a/imageknife/.gitignore +++ b/imageknife/.gitignore @@ -1,3 +1,5 @@ /node_modules /.preview -/build \ No newline at end of file +/build +/oh_modules/ +/oh-package-lock.json5