HarmonyOS 自定义弹窗怎么设置自定义动画?

HarmonyOS 自定义弹窗怎么设置自定义动画?


HarmonyOS
2024-10-15 12:05:24
985浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

使用组件内转场实现,参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-transition-animation-component-V5

如下demo:

let anmDuration: number = 1000; // 弹窗交互  
@CustomDialog  
struct CustomDialogExample1 {  
  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: 30 })  
      .width('80%')  
      .borderRadius(10)  
    }  
    .justifyContent(FlexAlign.End)  
    .width('100%')  
    .height("100%")  
    .onClick(() => {  
      console.log("dialogClick")  
      if (this.isAutoCancel) {  
        console.log("dialogClick2")  
        this.cancel();  
      }  
    })  
    .visibility(this.showFlag)  
    .transition(TransitionEffect.move(TransitionEdge.START).animation({ duration: anmDuration }))  
  }  
  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: CustomDialogExample1({ 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.
分享
微博
QQ
微信
回复
2024-10-15 16:45:36


相关问题
自定义弹窗自定义转场动画
1931浏览 • 1回复 待解决
如何设置自定义弹窗位置
2803浏览 • 1回复 待解决
弹窗打开、关闭动画是否支持自定义
3321浏览 • 1回复 待解决
HarmonyOS 如何设置自定义弹窗透明
888浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog
748浏览 • 1回复 待解决
CustomDialog自定义动画
1328浏览 • 1回复 待解决
HarmonyOS 自定义弹窗选择
1298浏览 • 1回复 待解决
HarmonyOS 自定义弹窗封装问题
873浏览 • 1回复 待解决
HarmonyOS 如何封装自定义弹窗
900浏览 • 1回复 待解决
HarmonyOS 唤起自定义弹窗crash
816浏览 • 1回复 待解决
HarmonyOS 自定义弹窗 (CustomDialog)问题
1276浏览 • 1回复 待解决
使用自定义弹窗实现分享弹窗
1343浏览 • 1回复 待解决
HarmonyOS 自定义弹窗的问题
1601浏览 • 1回复 待解决