如何定义dialog动画,有人知道吗?

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

HarmonyOS
2024-01-31 10:48:02
浏览
已于2024-2-1 17:41:45修改
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Bald_eagle

示例代码

参考如下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%') 
  } 
}
分享
微博
QQ
微信
回复
2024-02-01 17:35:35
相关问题
如何保存faultLogger ,有人知道吗
197浏览 • 1回复 待解决
如何跳出ForEach,有人知道吗
808浏览 • 1回复 待解决
如何发送短信,有人知道吗?
792浏览 • 1回复 待解决
$$语法如何使用?有人知道吗
96浏览 • 1回复 待解决
如何实现振动,有人知道吗
774浏览 • 2回复 待解决
如何实现图片预览,有人知道吗
20浏览 • 1回复 待解决
如何使用快速修复,有人知道吗
270浏览 • 1回复 待解决
如何引用HSP库,有人知道吗?
776浏览 • 1回复 待解决
导航栏如何适配,有人知道吗?
773浏览 • 0回复 待解决
如何实现翻页功能,有人知道吗
743浏览 • 1回复 待解决
如何实现镂空效果,有人知道吗?
24浏览 • 1回复 待解决
如何获取组件高度,有人知道吗
752浏览 • 1回复 待解决
IP地址如何转化,有人知道吗
260浏览 • 1回复 待解决
ArkTS要如何使用this,有人知道吗
57浏览 • 1回复 待解决
如何获取系统电量,有人知道吗
831浏览 • 1回复 待解决
taskpool 使用问题,有人知道吗
457浏览 • 1回复 待解决
webview组件demo ,有人知道吗
464浏览 • 1回复 待解决
如何实现http长连接,有人知道吗
746浏览 • 1回复 待解决
如何开启AOT编译模式,有人知道吗
900浏览 • 1回复 待解决
如何压缩字符串,有人知道吗
476浏览 • 1回复 待解决
热重载该如何实现?有人知道吗
391浏览 • 1回复 待解决
如何拉起相机界面,有人知道吗
758浏览 • 1回复 待解决
如何调整内存大小,有人知道吗
27浏览 • 1回复 待解决
clientid相关问题,有人知道吗
698浏览 • 1回复 待解决
List组件性能问题,有人知道吗
815浏览 • 1回复 待解决