HarmonyOS CustomDialogController 弹出多次如何修改每次的offset

尝试下面的代码,无法生效。

@State
dialogOffset?:Offset = undefined
controller: CustomDialogController = new CustomDialogController({
  builder: MyDialog(),
  alignment: DialogAlignment.CenterStart,
  offset:this.dialogOffset
})

// 这个方面会多次调用
openDialog() {

  this.dialogOffset = xxx // <==== 这里每次都会更新值不一样

  this.controller.open()
}
}

//尝试每次都new CustomDialogController 会提示
Error message:is not callable
Stacktrace:
  at SynchedPropertyTwoWayPU 
HarmonyOS
2024-12-20 15:14:56
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
fox280

目前自定义弹窗的所有参数,暂不支持动态刷新。具体可参考链接如下: https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/js-apis-arkui-UIContext.md#updatecustomdialog12

参考以下demo:

import { BusinessError } from '@ohos.base';
import { ComponentContent } from "@ohos.ArkUI.node";

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));
            try {
              promptAction.openCustomDialog(contentNode);
            } catch (error) {
              let message = (error as BusinessError).message;
              let code = (error as BusinessError).code;
              console.error(OpenCustomDialog args error code is ${code}, message is ${message});
            };
            setTimeout(() =&gt; {
              try {
                promptAction.updateCustomDialog(contentNode, { alignment: DialogAlignment.CenterEnd });
              } catch (error) {
                let message = (error as BusinessError).message;
                let code = (error as BusinessError).code;
                console.error(updateCustomDialog args error code is ${code}, message is ${message});
              };
            }, 2000);   //2&#31186;&#21518;&#33258;&#21160;&#26356;&#26032;&#24377;&#31383;&#20301;&#32622;
          })
      }
      .width('100%')
      .height('100%')
    }
    .height('100%')
  }
}
分享
微博
QQ
微信
回复
2024-12-20 17:59:39
相关问题
HarmonyOS 修改气泡弹出位置
235浏览 • 1回复 待解决
HarmonyOS CustomDialogController如何封装
727浏览 • 1回复 待解决
HarmonyOS 嵌套滑动NestedScroll 指定offset
640浏览 • 1回复 待解决
HarmonyOS web控件执行多次问题
931浏览 • 1回复 待解决
分页使用pageNum还是offset优缺点
3461浏览 • 1回复 待解决
HarmonyOS CustomDialogController问题
927浏览 • 1回复 待解决
HarmonyOS CustomDialogController封装
366浏览 • 1回复 待解决