HarmonyOS ComponentContent封装的Dialog能设置点击Dialog区域外,不自动关闭吗?

HarmonyOS
2025-01-09 16:00:08
625浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit

ComponentContent的控制方式类似,openCustomDialog也支持传入options,可以用于控制相关能力,具体文档请参考:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-arkui-uicontext-V5#opencustomdialog12

示例代码如下:

import { ComponentContent } from "@kit.ArkUI";

class Params {
  text: string = ""

  constructor(text: string) {
    this.text = text;
  }
}

@Builder
function buildText(params: Params) {
  Column() {
    Text(params.text)
      .fontSize(50)
      .fontWeight(FontWeight.Bold)
      .margin({ bottom: 36 })
  }.backgroundColor('#FFF0F0F0')
}

@Entry
@Component
struct Index {
  @State message: string = "hello"

  build() {
    Row() {
      Column() {
        Button("click me")
          .onClick(() => {
            let uiContext = this.getUIContext();
            let promptAction = uiContext.getPromptAction();
            let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), new Params(this.message));
            promptAction.openCustomDialog(contentNode, {
              // autoCancel:false,
              onWillDismiss: (dismissDialogAction: DismissDialogAction) => {
                console.info("reason=" + JSON.stringify(dismissDialogAction.reason))
                console.log("dialog onWillDismiss")
                if (dismissDialogAction.reason == DismissReason.PRESS_BACK) {
                  // dismissDialogAction.dismiss()
                }
                if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) {
                  // dismissDialogAction.dismiss()
                }
              },
            })
          })
      }
      .width('100%')
      .height('100%')
    }
    .height('100%')
  }
}
  • 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.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
分享
微博
QQ
微信
回复
2025-01-09 17:16:29
相关问题
dialog跳转新页面返回后dialog关闭
1027浏览 • 1回复 待解决
HarmonyOS 如何封装自定义Dialog
833浏览 • 1回复 待解决
HarmonyOS Tabs如何设置不自动滚动
595浏览 • 1回复 待解决
HarmonyOS dialog如何禁止侧滑返回关闭
687浏览 • 1回复 待解决
HarmonyOS 自定义dialog封装后全局调用
795浏览 • 1回复 待解决