forked from floraachy/ImageKnife
1.更新readme.md
2.更新hvigor-ohos-plugin版本由2.0.0到2.4.2 Signed-off-by: 李艺为 <liyiwei18@h-partners.com>
This commit is contained in:
parent
8494070fb0
commit
9bf705c711
|
@ -1,4 +1,10 @@
|
||||||
/node_modules
|
/node_modules
|
||||||
/local.properties
|
/local.properties
|
||||||
/.idea
|
/.idea
|
||||||
**/build
|
**/build
|
||||||
|
/oh_modules/
|
||||||
|
/.hvigor/
|
||||||
|
/oh-package-lock.json5
|
||||||
|
/.clangd
|
||||||
|
/.clang-format
|
||||||
|
/.clang-tidy
|
||||||
|
|
77
README.md
77
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
|
```typescript
|
||||||
import AbilityStage from "@ohos.application.AbilityStage"
|
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||||
import {ImageKnife} from '@ohos/imageknife'
|
import window from '@ohos.window';
|
||||||
|
import { ImageKnife } from '@ohos/imageknife'
|
||||||
|
|
||||||
export default class MyAbilityStage extends AbilityStage {
|
export default class EntryAbility extends UIAbility {
|
||||||
onCreate() {
|
onCreate(want, launchParam) {
|
||||||
// 初始化全局ImageKnife实例,在AbilityStage.ts中调用ImageKnife.with(this.context)进行初始化
|
globalThis.ImageKnife = ImageKnife.with(this.context);
|
||||||
globalThis.ImageKnife = ImageKnife.with(this.context)
|
}
|
||||||
}
|
|
||||||
}
|
onWindowStageCreate(windowStage: window.WindowStage) {
|
||||||
|
windowStage.loadContent('pages/Index', (err, data) => {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### 1.加载普通图片
|
### 1.加载普通图片
|
||||||
|
@ -42,30 +63,30 @@ export default class MyAbilityStage extends AbilityStage {
|
||||||
接下来我们来写个简单实例看看:
|
接下来我们来写个简单实例看看:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/imageknife'
|
||||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
|
||||||
@Entry
|
@Entry
|
||||||
@Component
|
@Component
|
||||||
struct Index {
|
struct Index {
|
||||||
@State imageKnifeOption1: ImageKnifeOption =
|
@State message: string = 'Hello World'
|
||||||
{ // 加载一张本地的jpg资源(必选)
|
@State option: ImageKnifeOption = {
|
||||||
loadSrc: $r('app.media.jpgSample'),
|
loadSrc: $r('app.media.icon')
|
||||||
// 占位图使用本地资源icon_loading(可选)
|
}
|
||||||
placeholderSrc: $r('app.media.icon_loading'),
|
|
||||||
// 失败占位图使用本地资源icon_failed(可选)
|
build() {
|
||||||
errorholderSrc: $r('app.media.icon_failed')
|
Row() {
|
||||||
};
|
Column() {
|
||||||
build() {
|
Text(this.message)
|
||||||
Scroll() {
|
.fontSize(50)
|
||||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
.fontWeight(FontWeight.Bold)
|
||||||
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 })
|
ImageKnifeComponent({ imageKnifeOption: this.option })
|
||||||
.width(300) // 自定义组件支持通用属性链式调用,可以直接设置宽高
|
.width(300)
|
||||||
.height(300)
|
.height(300)
|
||||||
}
|
}
|
||||||
}
|
.width('100%')
|
||||||
.width('100%')
|
}
|
||||||
.height('100%')
|
.height('100%')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
"name": "default",
|
"name": "default",
|
||||||
"signingConfig": "default"
|
"signingConfig": "default"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"signingConfigs": []
|
||||||
},
|
},
|
||||||
"modules": [
|
"modules": [
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
/node_modules
|
/node_modules
|
||||||
/.preview
|
/.preview
|
||||||
/build
|
/build
|
||||||
|
/oh_modules/
|
||||||
|
/oh-package-lock.json5
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"hvigorVersion": "2.0.0",
|
"hvigorVersion": "2.4.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ohos/hvigor-ohos-plugin": "2.0.0"
|
"@ohos/hvigor-ohos-plugin": "2.4.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
/node_modules
|
/node_modules
|
||||||
/.preview
|
/.preview
|
||||||
/build
|
/build
|
||||||
|
/oh_modules/
|
||||||
|
/oh-package-lock.json5
|
||||||
|
|
Loading…
Reference in New Issue