Compare commits

..

2 Commits

Author SHA1 Message Date
zgf c12c727311
Pre Merge pull request !436 from zgf/master 2024-11-29 10:26:58 +00:00
zgf e475dcd30a 修改ImageKnifeComponent组件pixel Map初始值以及修复多张错误图不显示
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2024-11-29 18:26:46 +08:00
4 changed files with 130 additions and 35 deletions

View File

@ -2,7 +2,6 @@
- Enhance: ImageFit.Auto support adaptive height after component width change - Enhance: ImageFit.Auto support adaptive height after component width change
- Fix bug: call onLoadStart 2 times(import from 3.2.0-rc.0) - Fix bug: call onLoadStart 2 times(import from 3.2.0-rc.0)
- Change the initial value of the PixelMap component of ImageKnife to ImageContent EMPTY - Change the initial value of the PixelMap component of ImageKnife to ImageContent EMPTY
- Fix bug: Multiple images failed to load simultaneously, error image not displayed(import from 3.2.0-rc.4)
## 3.2.0-rc.4 ## 3.2.0-rc.4
- Support ICO format images - Support ICO format images

View File

@ -12,24 +12,27 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { ImageKnifeComponent } from '@ohos/libraryimageknife'; import { ImageKnifeComponent,ImageKnifeOption } from '@ohos/libraryimageknife';
import { CommonDataSource } from './model/CommonDataSource' import { CommonDataSource } from './model/CommonDataSource'
@Entry @Entry
@Component @Component
struct MultipleImageCallBack { struct MultipleImageCallBack {
@State hotCommendList: CommonDataSource<string> = new CommonDataSource<string>([]) @State hotCommendList: CommonDataSource<string> = new CommonDataSource<string>([])
@State componentIndex: number = 0
@State startIndex: number = 0 @State startIndex: number = 0
@State successIndex: number = 0 @State successIndex: number = 0
@State failIndex: number = 0 @State failIndex: number = 0
@State cancelIndex: number = 0 @State cancelJobIndex: number = 0
@State cancelLoadIndex: number = 0
@State memoryIndex: number = 0 @State memoryIndex: number = 0
@State fileCacheIndex: number = 0 @State fileCacheIndex: number = 0
@State netIndex: number = 0 @State netIndex: number = 0
@State checkText: string = ''
private data: Array<string> = [] private data: Array<string> = []
aboutToAppear(): void { aboutToAppear(): void {
for (let index = 0; index < 30; index++) { for (let index = 0; index < 100; index++) {
this.data.push(`https://img-blog.csdn.net/20140514114029140?${index}`) this.data.push(`https://img-blog.csdn.net/20140514114029140?${index}`)
} }
this.hotCommendList.addData(this.hotCommendList.totalCount(), this.data) this.hotCommendList.addData(this.hotCommendList.totalCount(), this.data)
@ -37,22 +40,48 @@ struct MultipleImageCallBack {
build() { build() {
Column() { Column() {
Column(){ Row() {
Text('开始回调:' + this.startIndex) Column() {
Text('成功回调:' + this.successIndex) Text('图片总数:' + this.componentIndex)
Text('失败回调:' + this.failIndex) Text('开始回调:' + this.startIndex)
Text('取消回调:' + this.cancelIndex) Text('成功回调:' + this.successIndex)
Text('内存数量:' + this.memoryIndex) Text('失败回调:' + this.failIndex)
Text('文件数量:' + this.fileCacheIndex) Text('队列取消回调:' + this.cancelJobIndex)
Text('网络数量:' + this.netIndex) Text('加载取消回调:' + this.cancelLoadIndex)
} Text('内存数量:' + this.memoryIndex)
Text('文件数量:' + this.fileCacheIndex)
Text('网络数量:' + this.netIndex)
}.width('50%')
Column() {
Button('check')
.onClick(()=>{
this.checkText = ''
if (this.componentIndex !== this.startIndex + this.cancelJobIndex) {
this.checkText = this.checkText + '图片总数!=开始+队列取消,'
}
if(this.startIndex !== this.successIndex + this.failIndex + this.cancelLoadIndex) {
this.checkText = this.checkText + '开始回调!=成功+失败+加载取消,'
}
if(this.successIndex !== this.memoryIndex + this.fileCacheIndex + this.netIndex) {
this.checkText = this.checkText + '成功回调!=内存+文件+网络,'
}
if(this.componentIndex !== this.successIndex + this.failIndex + this.cancelJobIndex + this.cancelLoadIndex) {
this.checkText = this.checkText + '图片总数!=成功+失败+加载取消+队列取消,'
}
if(this.checkText == '') {
this.checkText = 'check正确'
}
})
Text(this.checkText)
}.width('50%')
}.width('100%')
Column() { Column() {
WaterFlow() { WaterFlow() {
LazyForEach(this.hotCommendList, (item: string,index: number) => { LazyForEach(this.hotCommendList, (item: string,index: number) => {
FlowItem() { FlowItem() {
Column() { Column() {
Text(index + '') Text(index + '')
ImageKnifeComponent({ ImageComponent({
imageKnifeOption: { imageKnifeOption: {
loadSrc: item, loadSrc: item,
placeholderSrc: $r('app.media.loading'), placeholderSrc: $r('app.media.loading'),
@ -78,18 +107,24 @@ struct MultipleImageCallBack {
this.failIndex++ this.failIndex++
console.log('image load multiple loadFail:' + this.failIndex) console.log('image load multiple loadFail:' + this.failIndex)
}, },
onLoadCancel:()=>{ onLoadCancel:(message,request)=>{
this.cancelIndex++ let flag = request?.imageKnifeData?.type ? true : false
console.log('image load multiple loadCancel:' + this.cancelIndex) if (flag) {
this.cancelLoadIndex++
} else {
this.cancelJobIndex++
}
console.log('image load multiple cancelJobIndex:' + this.cancelJobIndex,'cancelLoadIndex' + this.cancelLoadIndex)
} }
} }
} },index:this.componentIndex
}).width('50%').height(160) }).width('50%').height(160)
} }
}.height(200) }.height(200)
.backgroundColor('#95efd2') .backgroundColor('#95efd2')
}, (item: string) => item) }, (item: string) => item)
} }
.cachedCount(0)
.columnsTemplate('1fr 1fr') .columnsTemplate('1fr 1fr')
.columnsGap(10) .columnsGap(10)
.rowsGap(5) .rowsGap(5)
@ -100,4 +135,17 @@ struct MultipleImageCallBack {
}.width('100%') }.width('100%')
.height('100%') .height('100%')
} }
}
@Component
struct ImageComponent {
@State imageKnifeOption: ImageKnifeOption = new ImageKnifeOption()
@Link index: number
aboutToAppear(): void {
this.index++
}
build() {
ImageKnifeComponent({
imageKnifeOption: this.imageKnifeOption
})
}
} }

View File

@ -12,34 +12,62 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { ImageKnifeComponent } from '@ohos/libraryimageknife'; import { ImageKnifeComponent,ImageKnifeOption } from '@ohos/libraryimageknife';
import { CommonDataSource } from './model/CommonDataSource' import { CommonDataSource } from './model/CommonDataSource'
@Entry @Entry
@Component @Component
struct SingleImageCallBack { struct SingleImageCallBack {
@State hotCommendList: CommonDataSource<string> = new CommonDataSource<string>([]) @State hotCommendList: CommonDataSource<string> = new CommonDataSource<string>([])
@State componentIndex: number = 0
@State startIndex: number = 0 @State startIndex: number = 0
@State successIndex: number = 0 @State successIndex: number = 0
@State failIndex: number = 0 @State failIndex: number = 0
@State cancelIndex: number = 0 @State cancelJobIndex: number = 0
@State cancelLoadIndex: number = 0
@State memoryIndex: number = 0 @State memoryIndex: number = 0
@State fileCacheIndex: number = 0 @State fileCacheIndex: number = 0
@State netIndex: number = 0 @State netIndex: number = 0
@State checkText: string = ''
build() { build() {
Column() { Column() {
Row() {
Column() {
Text('图片总数:' + this.componentIndex)
Text('开始回调:' + this.startIndex)
Text('成功回调:' + this.successIndex)
Text('失败回调:' + this.failIndex)
Text('队列取消回调:' + this.cancelJobIndex)
Text('加载取消回调:' + this.cancelLoadIndex)
Text('内存数量:' + this.memoryIndex)
Text('文件数量:' + this.fileCacheIndex)
Text('网络数量:' + this.netIndex)
}.width('50%')
Column() {
Button('check')
.onClick(()=>{
this.checkText = ''
if (this.componentIndex !== this.startIndex + this.cancelJobIndex) {
this.checkText = this.checkText + '图片总数!=开始+队列取消,'
}
if(this.startIndex !== this.successIndex + this.failIndex + this.cancelLoadIndex) {
this.checkText = this.checkText + '开始回调!=成功+失败+加载取消,'
}
if(this.successIndex !== this.memoryIndex + this.fileCacheIndex + this.netIndex) {
this.checkText = this.checkText + '成功回调!=内存+文件+网络,'
}
if(this.componentIndex !== this.successIndex + this.failIndex + this.cancelJobIndex + this.cancelLoadIndex) {
this.checkText = this.checkText + '图片总数!=成功+失败+加载取消+队列取消,'
}
if(this.checkText == '') {
this.checkText = 'check正确'
}
})
Text(this.checkText)
}.width('50%')
}.width('100%')
Column() { Column() {
Text('开始回调:' + this.startIndex) ImageComponent({
Text('成功回调:' + this.successIndex)
Text('失败回调:' + this.failIndex)
Text('取消回调:' + this.cancelIndex)
Text('内存数量:' + this.memoryIndex)
Text('文件数量:' + this.fileCacheIndex)
Text('网络数量:' + this.netIndex)
}
Column() {
ImageKnifeComponent({
imageKnifeOption: { imageKnifeOption: {
loadSrc: 'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp', loadSrc: 'https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp',
placeholderSrc: $r('app.media.loading'), placeholderSrc: $r('app.media.loading'),
@ -65,16 +93,34 @@ struct SingleImageCallBack {
this.failIndex++ this.failIndex++
console.log('image load multiple loadFail:' + this.failIndex) console.log('image load multiple loadFail:' + this.failIndex)
}, },
onLoadCancel: () => { onLoadCancel: (message,request) => {
this.cancelIndex++ let flag = request?.imageKnifeData?.type ? true : false
console.log('image load multiple loadCancel:' + this.cancelIndex) if (flag) {
this.cancelLoadIndex++
} else {
this.cancelJobIndex++
}
console.log('image load multiple cancelJobIndex:' + this.cancelJobIndex,'cancelLoadIndex' + this.cancelLoadIndex)
} }
} }
} },index:this.componentIndex
}).width(300).height(300) }).width(300).height(300)
} }
.height('80%') .height('80%')
}.width('100%') }.width('100%')
.height('100%') .height('100%')
} }
}
@Component
struct ImageComponent {
@State imageKnifeOption: ImageKnifeOption = new ImageKnifeOption()
@Link index: number
aboutToAppear(): void {
this.index++
}
build() {
ImageKnifeComponent({
imageKnifeOption: this.imageKnifeOption
})
}
} }

View File

@ -150,6 +150,8 @@ export struct ImageKnifeComponent {
return //针对reuse场景不显示历史图片 return //针对reuse场景不显示历史图片
} }
this.pixelMap = pixelMap this.pixelMap = pixelMap
LogUtil.debug('image load showPixelMap:' + this.request?.imageKnifeOption.loadSrc + ', componentId = ' +
this.getUniqueId() + ',size:' + JSON.stringify(size))
if (typeof this.pixelMap !== 'string') { if (typeof this.pixelMap !== 'string') {
if (this.imageKnifeOption.objectFit === ImageFit.Auto && this.isImageFitAutoResize == false) { if (this.imageKnifeOption.objectFit === ImageFit.Auto && this.isImageFitAutoResize == false) {
this.adaptiveHeight = this.currentWidth * size.height / size.width this.adaptiveHeight = this.currentWidth * size.height / size.width