HarmonyOS CustomDialogController自定义弹窗,如何实现从下往上弹出动画

HarmonyOS
2024-12-25 08:04:35
1.2w浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

打开Dialog的autoCancel属性可以做到自定义出场动画,demo如下:

// 弹窗交互
@CustomDialog
@Component
struct CustomDialogExample {

  controller: CustomDialogController = new CustomDialogController({
    builder: CustomDialogExample({}),
    autoCancel:false
  })

  @State showFlag: Visibility = Visibility.Visible;
  @State isAutoCancel: boolean = false;

  build() {
    Column() {
      Text('我是内容').fontSize(20).margin({ top: 10, bottom: 10 })
        .backgroundColor('#FFFFFF')
        .textAlign(TextAlign.Center)
        .height(200)
        .width('100%')
        .margin({top:600})
        .onClick(()=>{
          this.cancel();
        })
    }
    .width('100%')
    .height('100%')
    .margin({
      bottom: -15
    })
    .onClick(()=>{
      if(this.isAutoCancel){
        this.cancel();
      }
    })
    .visibility(this.showFlag)
    .transition(TransitionEffect.OPACITY.animation({duration: 1000}).combine(TransitionEffect.translate({y: 100})))
  }

  cancel(){
    this.showFlag=Visibility.Hidden
    setTimeout(()=>{
      this.controller.close()
    }, 1000)
  }
}

@Entry
@Component
struct CustomDialogUser {
  @State isAutoCancel: boolean = false;

  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%').margin({ top: 5 })
    .onClick(()=>{
    })
  }
}
  • 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-25 10:58:35


相关问题
自定义弹窗自定义转场动画
1633浏览 • 1回复 待解决
HarmonyOS 全局自定义弹窗无法弹出
569浏览 • 1回复 待解决
如何实现从底部缓慢上升的弹窗动画
2161浏览 • 1回复 待解决