HarmonyOS打开对话框时如何实现从下到上出现的动画?

builder: AccountSelectDialog(),  
   autoCancel: true,  
   alignment: DialogAlignment.Bottom,  
   offset: { dx: 0, dy: 0, },  
   customStyle: true,  
   cornerRadius: 0,  
   openAnimation: {  
     curve: Curve.EaseIn,  
     playMode: PlayMode.Alternate,  
     onFinish: () => {  
       console.info('play end')  
     }  
   },

openAnimation如何做才能实现像页面这种从下至上显示的动画。像页面这种API的这种效果。

pageTransition() {  
   PageTransitionEnter({ duration: 500, curve: Curve.Linear }).slide(SlideEffect.Bottom)  
   PageTransitionExit({ duration: 500, curve: Curve.Linear }).slide(SlideEffect.Bottom)  
 }
HarmonyOS
2024-09-29 10:39:23
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

参考demo:

let anmDuration: number = 300;  
// 弹窗交互  
@CustomDialog  
struct AccountSelectDialog {  
  controller: CustomDialogController = new CustomDialogController({  
    builder: AccountSelectDialog({}),  
    autoCancel: false  
  })  
  @State showFlag: Visibility = Visibility.Visible;  
  @State isAutoCancel: boolean = false;  
  textController: TextAreaController = new TextAreaController()  
  @State eventType: string = ''  
  @State touchDown:number = 0  
  @State touchUp:number = 0  
  build() {  
    Column() {  
      Row() {  
        Text("自定义动画的弹窗")  
      }  
      .borderRadius(20)  
      .backgroundColor('#ff6288cb')  
      .height(200)  
      .width('100%')  
    }  
    .margin({top:10})  
    .justifyContent(FlexAlign.Center)  
    .width('100%')  
    .height("100%")  
    // .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM])  
    .onTouch((event?: TouchEvent) => {  
      if(event){  
        if (event.type === TouchType.Down) {  
          this.eventType = 'Down'  
          this.touchDown = event.touches[0].y  
        }  
        if (event.type === TouchType.Up) {  
          this.eventType = 'Up'  
          this.touchUp = event.touches[0].y  
        }  
        if (event.type === TouchType.Move) {  
          this.eventType = 'Move'  
        }  
        if (this.touchUp - this.touchDown > 0) {  
          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: AccountSelectDialog(),  
    autoCancel: true,  
    alignment: DialogAlignment.Bottom,  
    offset: { dx: 0, dy: 0, },  
    customStyle: true,  
    cornerRadius: 0,  
    openAnimation: {  
      curve: Curve.EaseIn,  
      playMode: PlayMode.Alternate,  
      onFinish: () => {  
        console.info('play end')  
      }  
    }  
  })  
  build() {  
    Column() {  
      Button('click me')  
        .onClick(() => {  
          this.dialogController.open()  
        })  
    }.width('100%')  
    .height('100%')  
  }  
}
分享
微博
QQ
微信
回复
2024-09-29 16:10:11
相关问题
HarmonyOS 对话框弹出页面被遮挡
28浏览 • 1回复 待解决
HarmonyOS class中创建对话框不能显示
40浏览 • 1回复 待解决
如何封装一个自定义Dialog对话框
2234浏览 • 1回复 待解决
如何实现从底部缓慢上升弹窗动画
1927浏览 • 1回复 待解决