当前位置:   article > 正文

【HarmonyOS NEXT】自定义弹窗动画使用疑惑_鸿蒙customdialogcontroller 底部弹出弹框动画

鸿蒙customdialogcontroller 底部弹出弹框动画

 【关键字】

自定义弹窗 / openAnimation / 显式动画 / 属性动画 / AnimateParam

【问题描述】

自定义弹窗的openAnimation和closeAnimation该如何使用, AnimateParam文档中描述需要配合animationto使用,customercontroller只定义openAnimation能有什么效果?

【解决方案】

AnimateParam并非必须配合animationto使用。AnimateParam是一个对象类型,只是openAnimation,closeAnimation,animationto在传参时都会用到这个对象类型;CustomDialogController只定义 openAnimation的demo可以参考如下demo,可以控制弹窗出现动画的持续时间,速度等参数。

  1. @CustomDialog
  2. struct CustomDialogExample {
  3. controller?: CustomDialogController
  4. build() {
  5. Column() {
  6. Text('Whether to change a text?').fontSize(16).margin({ bottom: 10 })
  7. }
  8. }
  9. }
  10. @Entry
  11. @Component
  12. struct CustomDialogUser {
  13. @State textValue: string = ''
  14. @State inputValue: string = 'click me'
  15. dialogController: CustomDialogController | null = new CustomDialogController({
  16. builder: CustomDialogExample(),
  17. openAnimation: {
  18. duration: 1200,
  19. curve: Curve.Friction,
  20. delay: 500,
  21. playMode: PlayMode.Alternate,
  22. onFinish: () => {
  23. console.info('play end')
  24. }
  25. },
  26. autoCancel: true,
  27. alignment: DialogAlignment.Bottom,
  28. offset: { dx: 0, dy: -20 },
  29. gridCount: 4,
  30. customStyle: false,
  31. backgroundColor: 0xd9ffffff,
  32. cornerRadius: 10,
  33. })
  34. // 在自定义组件即将析构销毁时将dialogControlle置空
  35. aboutToDisappear() {
  36. this.dialogController = null // 将dialogController置空
  37. }
  38. build() {
  39. Column() {
  40. Button(this.inputValue)
  41. .onClick(() => {
  42. if (this.dialogController != null) {
  43. this.dialogController.open()
  44. }
  45. }).backgroundColor(0x317aff)
  46. }.width('100%').margin({ top: 5 })
  47. }
  48. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/339934
推荐阅读
相关标签
  

闽ICP备14008679号