HarmonyOS CustomDialogController一直是undefined

@Component
export struct DialogBug {
  dialogController: CustomDialogController = new CustomDialogController({
    builder: getPublishWidgetBuilder().builder,
    cornerRadius: 0,
    customStyle: true,
    alignment: DialogAlignment.Center,
    maskColor: 0x77000000
  })

  build() {
    Column() {
      Button(‘
      open’
      )
      .
      onClick(() => {
        this.dialogController.open()
      })
    }
    .margin({ top: 200 })
  }
}

function getPublishWidgetBuilder(): WrappedBuilder<[]> {
  return wrapBuilder(DialogBuilder)
}

@Builder
function DialogBuilder() {
  Mydialog()
}

@Component
@CustomDialog
struct Mydialog {
  dialogController?: CustomDialogController

  build() {
    Column() {
      Button(‘
      close’
      ).
      onClick(() => {
        this.dialogController?.close()
      })

    }
  }
}

补充说明:Mydialog中使用new CustomDialogController方式,dialog依然无法关闭

HarmonyOS
7h前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zbw_apple

请参考如下修改:

@Entry
@Component
struct Test5 {
  build() {
    Column() {
      DialogBug()
    }
  }
}

@Component
export struct DialogBug {
  dialogController: CustomDialogController = new CustomDialogController({
    //builder: getPublishWidgetBuilder().builder,
    builder: Mydialog(),
    cornerRadius: 0,
    customStyle: true,
    alignment: DialogAlignment.Center,
    maskColor: 0x77000000
  })

  build() {
    Column() {
      Button('open').onClick(() => {
        this.dialogController.open()
      })
    }
    .margin({ top: 200 })
  }
}

function getPublishWidgetBuilder(): WrappedBuilder<[]> {
  return wrapBuilder(DialogBuilder)
}

@Builder
function DialogBuilder() {
  Mydialog()
}

@Component
@CustomDialog
struct Mydialog {
  dialogController?: CustomDialogController

  build() {
    Column() {
      Button('close').onClick(() => {
        if (this.dialogController != undefined) {
          this.dialogController.close()
        }
        console.info('dialogController is undefined')
      })

    }
  }
}
分享
微博
QQ
微信
回复
5h前
相关问题
HarmonyOS Profiler TIme 一直initializing
311浏览 • 1回复 待解决
info 获取失败 一直为空
1866浏览 • 1回复 待解决
HarmonyOS IDE无法打开,一直崩溃
102浏览 • 1回复 待解决
HarmonyOS获取图片旋转值一直报错
447浏览 • 1回复 待解决
http 请求一直报 2300058
1653浏览 • 0回复 待解决
自动签名失败一直加载怎么回事?
6361浏览 • 2回复 待解决
DevEco Studio无法登陆 一直这个画面
10587浏览 • 2回复 已解决
用华为登录一直报6003错误
7925浏览 • 1回复 待解决
配置OHPM代理一直不成功
574浏览 • 1回复 待解决
自动签名一直失败怎么回事?
597浏览 • 1回复 待解决
previewer 一直loading failed怎么回事?
2746浏览 • 1回复 待解决