【每日学点鸿蒙知识】关于热修复、图片预览、多个@State刷新性能问题等

发布于:2025-02-10 ⋅ 阅读:(79) ⋅ 点赞:(0)

1、是否推荐使用bm quickfix制造修复包?

官方文档文档中显示:快速修复补丁安装bm quickfix -a -f /data/app/有两个问题:

  1. hqf文件如何制作的文档没有找到。
  2. hqf 是不是新版本和旧版本的差分包咨询场景描述:app可以在运行过程中修复部分bug功能,是不是可以用上吗的bm quickfix命令来修复,是否有相关的参考文档?

当前不推荐手动制作HQF包,推荐使用热重载能力:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-hot-reload-0000001527628941-V5?catalogVersion=V5

2、如何实现图片预览?

如何实现点击图片放大并支持收拾缩放?

@Entry
@Component
struct Index {
  @State visible: Visibility = Visibility.None
  @State scaleValue: number = 1
  @State pinchValue: number = 1
  @State pinchX: number = 0
  @State pinchY: number = 0
  @State count: number = 0
  @State offsetX: number = 0
  @State offsetY: number = 0
  @State positionX: number = 0
  @State positionY: number = 0

  build() {
    Stack() {
      Row() {
        Column() {
          Image($r('app.media.icon'))
            .width(100)
            .height(100)
            .onClick(() => {
              console.log("hit me!")
              if (this.visible == Visibility.Visible) {
                this.visible = Visibility.None
              } else {
                this.visible = Visibility.Visible
              }
            })
        }
        .width('100%')
        .justifyContent(FlexAlign.Center)
        .alignItems(HorizontalAlign.Center)
      }
      .height('100%')


      Text('')
        .onClick(() => {
          if (this.visible == Visibility.Visible) {
            this.visible = Visibility.None
          } else {
            this.visible = Visibility.Visible
          }
        })
        .width('100%')
        .height('100%')// 透明度可以自己调节一下
        .opacity(0.16)
        .backgroundColor(0x000000)
        .visibility(this.visible)

      Column() {
        Image($r('app.media.icon'))
          .width(300)
          .height(300)
          .draggable(false)
          .visibility(this.visible)
          .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 })
          .translate({ x: this.offsetX, y: this.offsetY, z: 0 })
          .gesture(
            GestureGroup(GestureMode.Parallel,
              PinchGesture({ fingers: 2 })
                .onActionStart((event?: GestureEvent) => {
                  console.info('Pinch start')
                })
                .onActionUpdate((event?: GestureEvent) => {
                  if (event) {
                    this.scaleValue = this.pinchValue * event.scale
                    this.pinchX = event.pinchCenterX
                    this.pinchY = event.pinchCenterY
                  }
                })
                .onActionEnd(() => {
                  this.pinchValue = this.scaleValue
                  console.info('Pinch end')
                }),

              PanGesture()
                .onActionUpdate((event?: GestureEvent) => {
                  if (event) {
                    this.offsetX = this.positionX + event.offsetX
                    this.offsetY = this.positionY + event.offsetY
                  }
                  console.info('pan update')
                })
                .onActionEnd(() => {
                  this.positionX = this.offsetX
                  this.positionY = this.offsetY
                  console.info('pan end')
                })
            )
          )
      }
    }
  }
}

3、connection模块中netlost和netUnavailable的作用?

  • netlost事件为网络状态丢失的监听,如:wifi / 移动网络断开时。
  • netUnavailable事件监听为网络连接成功但是发生异常无法正常访问浏览器的场景。

4、安装报错 错误码code: 9568347 error: install parse native so failed.如何处理?

参考官方文档排查:
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/bm-tool-V5#%E5%AE%89%E8%A3%85hap%E6%97%B6%E6%8F%90%E7%A4%BAcode9568347-error-install-parse-native-so-failed%E9%94%99%E8%AF%AF

5、一个自定义组件内某一时机批量刷新多个@State修饰的状态变量,是否会影响性能?

比如一个自定义的Component,有20个@State修饰的变量,每个State都定义了相关更新接口,外部某个时机,会批量更新这些State,调用每个State的更新接口,会不会导致频繁更新Component组件,导致性能问题?

同时对多个State接口更新不会导致性能问题,因为每个@State都要有去更新UI的能力,一次性批量的修改不会导致一个组件被反复刷多次,在一个Vsync内,对同一个组件的多次标脏只刷新一次。


网站公告

今日签到

点亮在社区的每一天
去签到