HarmonyOS CustomDialog是否支持自定义动画?

HarmonyOS CustomDialog是否支持自定义动画?

HarmonyOS
2024-09-03 11:54:03
631浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

请参考如下demo:

// 打开Dialog的autoCancel属性可以做到自定义出场动画,屏幕右滑现在不能实现(返回事件当前不能监听,有一个相关需求在做) 
let anmDuration: number = 800; 
 
// 弹窗交互 
@CustomDialog 
struct CustomDialogExample { 
  @State showFlag: Visibility = Visibility.Visible; 
  @State isAutoCancel: boolean = false; 
  controller: CustomDialogController = new CustomDialogController({ 
    builder: CustomDialogExample({}), 
    autoCancel: 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: anmDuration }) 
        .combine(TransitionEffect.translate({ x: 100, y: 0 }))) 
  } 
 
  // 延迟关闭弹窗,让自定义的出场动画显示 
  cancel() { 
    this.showFlag = Visibility.Hidden 
    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%’).margin({ top: 5 }) 
  } 
}
  • 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.
  • 70.
  • 71.
  • 72.
  • 73.

1.自定义设置弹窗弹出的动画效果相关参数AnimateParam

参考文档:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-methods-custom-dialog-box-V5#ZH-CN_TOPIC_0000001847211028__customdialogcontrolleroptions对象说明

2.参考文档

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-develop-apply-immersive-effects-V5#section15671730447

方案如下:

// 先获取到导航条区域的高度 
let bottomRectHeight = avoidArea.bottomRect.height; 
//再在每个界面做如下适配 
Row() { } 
.margin({ bottom: this.bottomRectHeight }) 
// 此处margin具体数值在实际中应与导航条区域高度保持一致
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
分享
微博
QQ
微信
回复
2024-09-03 17:43:03
相关问题
CustomDialog支持自定义动画
1183浏览 • 2回复 待解决
CustomDialog自定义动画
1307浏览 • 1回复 待解决
弹窗打开、关闭动画是否支持自定义
3316浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog
739浏览 • 1回复 待解决
HarmonyOS 自定义CustomDialog 跳转问题
743浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog问题
1341浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog 问题
765浏览 • 1回复 待解决
HarmonyOSCustomDialog自定义Dialog
1124浏览 • 1回复 待解决
自定义弹窗自定义转场动画
1919浏览 • 1回复 待解决
是否支持自定义装饰器
2846浏览 • 1回复 待解决
HarmonyOS ArkTS是否支持自定义注解
917浏览 • 1回复 待解决
HarmonyOS 自定义弹窗 (CustomDialog)问题
1260浏览 • 1回复 待解决
HarmonyOS 是否支持自定义升级弹窗
668浏览 • 1回复 待解决
HarmonyOS 是否支持自定义装饰器?
983浏览 • 1回复 待解决
HarmonyOS ArkWeb是否支持自定义UserAgent
1172浏览 • 1回复 待解决
HarmonyOS 组件是否支持自定义事件
798浏览 • 1回复 待解决