HarmonyOS 使用全局 @Builder 应用 crash

使用全局 @Builder 应用 crash

crash 结果:Cannot read property observeComponentCreation2 of undefined

复现代码:

https://gitee.com/smarthane/appupdate

仓库中 Index.ets 替换为如下内容,运行后点击 测试弹窗 应用 crash

import { AppUpdateDialogModel, AppUpdateHelper, DialogStyleEnum } from '@smarthane/appupdate'
import promptAction from '@ohos.promptAction'
import { TitleBar } from '@smarthane/titlebar'
import { common } from '@kit.AbilityKit'

const uiContext = getContext(this) as common.UIAbilityContext

/**
 * 自定布局输入弹窗
 */
@Builder
function builderCustomDialogInputView() {
  Column() {
    Column({ space: '10vp' }) {
      Text('这是提示输入的标题')
        .fontSize('15fp')
        .fontColor(Color.Black)
        .textAlign(TextAlign.Start)
        .fontWeight(FontWeight.Bold)

      TextInput({ placeholder: '这是提示文本' })
        .fontSize('12fp')
        .fontColor(Color.Black)
        .textAlign(TextAlign.Start)
        .fontWeight(FontWeight.Regular)
        .placeholderFont({
          size: '12fp'
        })
        .height('40vp')
        .margin({
          left: '5vp',
          right: '5vp'
        })
        .onChange((value: string) => {
          console.info(value);
        })
        .onFocus(() => {
          console.info('获取焦点');
        })

      Row() {
        Button('取消', { type: ButtonType.Normal, stateEffect: true })
          .fontColor(Color.White)
          .fontSize('13fp')
          .width('50%')
          .backgroundColor('#dcdcdc')
          .onClick(() => {
            AppUpdateHelper.hideDialog();
          })
          .borderRadius({
            bottomLeft: '5vp',
          })
        Button('确定', { type: ButtonType.Normal, stateEffect: true })
          .fontColor(Color.White)
          .fontSize('13fp')
          .width('50%')
          .backgroundColor('#fff13737')
          .onClick(() => {
            AppUpdateHelper.hideDialog();
          })
          .borderRadius({
            bottomRight: '5vp'
          })
      }
      .justifyContent(FlexAlign.SpaceBetween)
      .width("100%")
      .borderRadius({
        bottomLeft: '5vp',
        bottomRight: '5vp'
      })
    }
    .alignItems(HorizontalAlign.Center)
    .width('100%')
    .backgroundColor(Color.White)
    .borderRadius('5vp')
    .margin({
      top: '15vp'
    })
  }
  .width('80%')
  .borderRadius('5vp')
  .backgroundColor(Color.White)
}

@Entry
@Component
struct Index {
  private mDefaultTitle: string = "是否升级到1.0.5版本";
  private mDefaultSubTitle: string = "新版本大小:6M";
  private mDefaultUpdateContent: string = "1.全新升级,让您的体验更上一层楼,尽在本次产品升级中。\n2.超越旧版,全新升级,为您带来更出色的体验。\n3.HarmonyOS来了!“鸿”鹄志远,一举千里。承“蒙”厚爱,不负期待。\n4.每一次升级,都是对完美的追求。本次全新升级,更是如此。";
  @State mTitleModel: TitleBar.Model = new TitleBar.Model()
    .setOnLeftClickListener(async () => {
      let a = await AppUpdateHelper.getVersionName();
      let b = await AppUpdateHelper.getVersionCode();
      promptAction.showToast({
        message: `点击了左边返回按钮${a}-${b}`,
        duration: 2000
      })
    })
    .setTitleName("应用版本升级弹窗")

  build() {
    Column() {
      TitleBar({ model: this.mTitleModel })
      Column() {
        Text("测试弹窗").onClick(() => {
          AppUpdateHelper.showDialog({
            dialogStyleEnum: DialogStyleEnum.STYLE_CUSTOM_ALL,
            customView: () => {
              builderCustomDialogInputView();
            }
          })
        })
      }
      .justifyContent(FlexAlign.Center)
      .width('100%')
      .height('100%')
    }
    .height('100%')
  }
}
HarmonyOS
2025-01-09 15:59:43
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zxjiu

崩溃问题需要如下写法,弹窗未显示是封装的弹窗有问题,建议排查下封装库

AppUpdateHelper.showDialog({
  dialogStyleEnum: DialogStyleEnum.STYLE_CUSTOM_ALL,
  customView: () => {
    ()=>{
      builderCustomDialogInputView();
    }
  }
})
分享
微博
QQ
微信
回复
2025-01-09 17:25:11
相关问题
HarmonyOS 如何使用全局Builder
225浏览 • 1回复 待解决
HarmonyOS taskpool使用crash
1907浏览 • 2回复 待解决
HarmonyOS 支持获取应用crash日志吗
343浏览 • 1回复 待解决
@Builder使用引用时异常
1169浏览 • 1回复 待解决
HarmonyOS 应用全局弹框
751浏览 • 1回复 待解决
HarmonyOS 如何使用全局水印
253浏览 • 1回复 待解决
HarmonyOS 想在builder中插入builder
267浏览 • 1回复 待解决
HarmonyOS builder 作为 builder 的参数传递
335浏览 • 1回复 待解决
HarmonyOS 如何实现应用全局换肤功能
327浏览 • 1回复 待解决
如何实现crash堆栈抓取、crash回调
2252浏览 • 1回复 待解决
HarmonyOS 关于crash问题
891浏览 • 1回复 待解决