HarmonyOS 自定义Dialog如何修改弹出动画?

HarmonyOS
2024-12-20 16:43:35
1.2w浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280
let anmDuration: number = 300;

// 弹窗交互
@CustomDialog
struct CustomDialogExample {
  controller: CustomDialogController = new CustomDialogController({
    builder: CustomDialogExample({}),
    autoCancel: false
  })
  @State showFlag: Visibility = Visibility.Visible;
  @State isAutoCancel: boolean = false;
  textController: TextAreaController = new TextAreaController()

  build() {
    Column() {
      Row() {
        Text("自定义动画的弹窗")
      }
      .borderRadius(20)
      .backgroundColor('#ff6288cb')
      .height(200)
      .width('100%')
    }
    .margin({top:10})
    .justifyContent(FlexAlign.Center)
    .width('100%')
    .height("100%")
    .onClick(() => {
      console.log("dialogClick")
      if (this.isAutoCancel) {
        console.log("dialogClick2")
        this.cancel();
      }
    })
    .visibility(this.showFlag)
    // 定义进场出场转场动画效果
    .transition(TransitionEffect.OPACITY.animation({ duration: anmDuration })
      .combine(TransitionEffect.translate({ y: 500 })))
  }
  // 延迟关闭弹窗,让自定义的出场动画显示
  cancel() {
    this.showFlag = Visibility.Hidden
    console.log("closeDialog")
    setTimeout(() => {
      this.controller.close()
    }, anmDuration)
  }
}

@Entry
@Component
struct CustomDialogUser {
  @State isAutoCancel: boolean = true;
  dialogController: CustomDialogController = new CustomDialogController({
    builder: CustomDialogExample({ isAutoCancel: this.isAutoCancel }),
    autoCancel: this.isAutoCancel,
    customStyle: true,
  })

  build() {
    Column() {
      Button('click me')
        .onClick(() => {
          this.dialogController.open()
        })
    }.width('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.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
分享
微博
QQ
微信
回复
2024-12-20 20:24:53


相关问题
HarmonyOS 如何封装自定义Dialog
497浏览 • 1回复 待解决
HarmonyOS 自定义Dialog宽度
573浏览 • 1回复 待解决
HarmonyOS 自定义全局dialog
390浏览 • 1回复 待解决
HarmonyOS 自定义全屏dialog
571浏览 • 1回复 待解决
自定义弹窗自定义转场动画
1633浏览 • 1回复 待解决
HarmonyOS 自定义dialog open无效
683浏览 • 1回复 待解决
HarmonyOS 自定义Dialog显示问题
956浏览 • 1回复 待解决
HarmonyOS 自定义dialog相关问题
481浏览 • 1回复 待解决
HarmonyOS 用CustomDialog自定义Dialog
811浏览 • 1回复 待解决
HarmonyOS 自定义Dialog高度问题
477浏览 • 1回复 待解决