如何定义dialog动画?

CustomDialogController的 openAnimation closeAnimation 如何定义转场效果。想把dialog动画改成底部弹出,向底部收起。

阅读 317
1 个回答

参考如下demo设置自定义弹窗的自定义动画,思路就是让自定义弹窗占满整个页面然后让里面的内容来添加转场动画,然后这个demo就是底部弹出底部收起的。

let anmDuration: number = 200; 
 
// 弹窗交互 
@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("自定义动画的弹窗") 
      } 
      .padding(8) 
      .backgroundColor('#FFFFFF') 
      .height(200) 
      .margin({ bottom: -5 }) 
      .width('100%') 
    } 
    .justifyContent(FlexAlign.End) 
    .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: 100 }))) 
  } 
 
  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%') 
  } 
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进