HarmonyOS 自定义弹窗控制问题

@CustomDialog
export default struct CustomDialogWidget {
  controller: CustomDialogController

  // aboutToAppear() {}
  build() {
    Column() {
      
    }.width('100%').height('100%').backgroundColor($r('app.color.search_hint_color')).onClick(() => {
      if (this.controller) {
        this.controller.close()
      }
    })
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.

上面是自定义的一个弹窗,按照官方提供的方法在页面上面打开,现在没有办法关闭也就是代码里面的controller这个属性一直是空值,controller要在哪里进行赋值然后用来关闭弹窗。

HarmonyOS
2024-12-25 12:43:31
618浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

参考示例如下:

@Entry
@Component
struct Index60 {
  @State message: string = '请点击';
  citySelectorDialogController: CustomDialogController = new CustomDialogController({
    builder: CustomDialogWidget(),
    alignment: DialogAlignment.Center,
    customStyle: true
  })

  build() {
    Column() {
      Text(this.message)
        .fontSize(40)
    }
    .width('100%')
    .height('100%')
    .onClick(() => {
      this.citySelectorDialogController.open()
    })
  }
}

@CustomDialog
export default struct CustomDialogWidget {
  controller: CustomDialogController

  build() {
    Column() {
      Text('這個是弹窗')
        .fontSize(40)
    }.width(300)
    .height(300)
    .backgroundColor(Color.Red)
    .onClick(() => {
      if (this.controller) {
        this.controller.close()
      }
    })
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
分享
微博
QQ
微信
回复
2024-12-25 14:44:46
相关问题
HarmonyOS 自定义弹窗CustomDialog问题
1381浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog 问题
823浏览 • 1回复 待解决
HarmonyOS 自定义弹窗层级问题
1016浏览 • 1回复 待解决
HarmonyOS 自定义弹窗问题
1650浏览 • 1回复 待解决
HarmonyOS 自定义弹窗关闭问题
951浏览 • 1回复 待解决
HarmonyOS 自定义弹窗封装问题
905浏览 • 1回复 待解决
HarmonyOS 自定义弹窗 (CustomDialog)问题
1320浏览 • 1回复 待解决
自定义弹窗使用相关问题
1772浏览 • 1回复 待解决
HarmonyOS 自定义弹窗刷新问题
713浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog调用问题
1165浏览 • 1回复 待解决
HarmonyOS 自定义弹窗点击跳转问题
816浏览 • 1回复 待解决
HarmonyOS 自定义弹窗部分问题答疑
1261浏览 • 1回复 待解决
HarmonyOS 自定义弹窗不能显示问题
913浏览 • 1回复 待解决
自定义弹窗自定义转场动画
1991浏览 • 1回复 待解决
HarmonyOS 自定义弹窗初始化问题
778浏览 • 1回复 待解决
HarmonyOS 自定义弹窗选择
1343浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog
798浏览 • 1回复 待解决