HarmonyOS new CustomDialogController初始化后,再修改属性应该怎么实现

创建CustomDialogController对象并初始化属性后,想再改变属性的值。select选择蒙层颜色后,maskColorIndex改变了,但是CustomDialogController对象的mask颜色没变化。

代码如下:

@Entry
@Component
struct Index {
  @State textValue: string = ''
  @State inputValue: string = 'click me'
  @State autoCancel: boolean = true
  private alignArr: DialogAlignment[] = [DialogAlignment.Top, DialogAlignment.TopStart, DialogAlignment.TopEnd, DialogAlignment.Bottom, DialogAlignment.BottomStart, DialogAlignment.BottomEnd]
  @State alignIndex: number = 3
  private maskColor: ResourceColor[] = ['#0000ff', 0x33000000, Color.Gray,Color.Transparent]
  @State maskColorIndex: number = 0
  private curveArr: Curve[] = [Curve.Linear, Curve.Ease]
  @State curveIndex: number = 0
  @State closeDuration: number = 0
  @State closeTempo: number = 0
  @State closeDelay: number = 0
  @State closeIterations: number = 0
  dialogController: CustomDialogController = new CustomDialogController({
    builder: CustDialog({
      textValue: $textValue,
      inputValue: $inputValue
    }),
    cancel: () => {
      console.info('Click the callback in the blank area')
    },
    autoCancel: this.autoCancel,
    alignment: this.alignArr[this.alignIndex],
    gridCount: 4,
    customStyle: false,
    maskColor:this.maskColor[this.maskColorIndex],
    openAnimation: ({}),
    closeAnimation: ({
      curve: this.curveArr[this.curveIndex],
      duration: this.closeDuration,
      tempo: this.closeTempo,
      delay: this.closeDelay,
      iterations: this.closeIterations,
    })
  })
  build() {
    Column() {
      Button('默认属性').onClick((event: ClickEvent) => {
        if (this.dialogDefaultAttr != undefined) {
          this.dialogDefaultAttr.open()
        }
      })
        .margin(5)
      Button(this.inputValue)
        .focusable(true)
        .onClick(() => {
          if (this.dialogController != undefined) {
            this.dialogController.open()
          }
        })
        .margin({ bottom: 10 })
      Row() {
        Row() {
          Text('弹窗位置')
          Select([
            { value: '顶部' },
            { value: '左上' },
            { value: '右上' },
            { value: '底部' },
            { value: '左下' },
            { value: '右下' }
          ])
            .value('底部')
            .onSelect((index: number) => {
              this.alignIndex = index
            })
        }.width('40%').justifyContent(FlexAlign.Center)
        Row() {
          Text('蒙层颜色')
          Select([
            { value: '#0000ff' },
            { value: '0x33000000' },
            { value: 'Color.Gray' },
            {value:'透明'}
          ])
            .value('#0000ff')
            .onSelect((index: number) => {
              this.maskColorIndex = index
            })
        }.width('60%').justifyContent(FlexAlign.Center)
      }.width('100%').justifyContent(FlexAlign.SpaceAround)
      Toggle({type:ToggleType.Switch,isOn:true})
        .onChange((isOn:boolean)=>{
          this.autoCancel=isOn
        })
    }
    .width('100%')
    .height('100%')
  }
}
HarmonyOS
2024-12-26 14:16:09
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
aquaa

修改属性后在重新new CustomDialogController初始化就可以了。

分享
微博
QQ
微信
回复
2024-12-26 17:31:24
相关问题
HarmonyOS 怎么监听Web初始化完成?
348浏览 • 1回复 待解决
HarmonyOS泛型类的属性如何初始化
691浏览 • 1回复 待解决
HarmonyOS XComponent初始化
396浏览 • 1回复 待解决
HarmonyOS 组件初始化参数
90浏览 • 1回复 待解决
HarmonyOS struct初始化方法
341浏览 • 1回复 待解决
HarmonyOS Component初始化问题
714浏览 • 1回复 待解决
HarmonyOS 初始化EGL环境失败
281浏览 • 1回复 待解决
HarmonyOS 推送服务初始化失败
56浏览 • 1回复 待解决
HarmonyOS 应用RDB初始化示例
663浏览 • 1回复 待解决
没法调试“已初始化”分支
471浏览 • 1回复 待解决