如何定义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%') 
  } 
}
  • 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.
分享
微博
QQ
微信
回复
2024-02-01 17:35:35
相关问题
如何实现振动,有人知道吗
1960浏览 • 2回复 待解决
如何获取windowStage,有人知道吗
1526浏览 • 1回复 待解决
如何保存faultLogger ,有人知道吗
1476浏览 • 1回复 待解决
如何发送短信,有人知道吗?
2840浏览 • 1回复 待解决
$$语法如何使用?有人知道吗
1500浏览 • 1回复 待解决
如何跳出ForEach,有人知道吗
2956浏览 • 1回复 待解决
ArkTS要如何使用this,有人知道吗
1359浏览 • 1回复 待解决
如何查询设备类型?有人知道吗
1100浏览 • 1回复 待解决
如何实现镂空效果,有人知道吗?
1034浏览 • 1回复 待解决
IP地址如何转化,有人知道吗
1273浏览 • 1回复 待解决
如何获取系统电量,有人知道吗
2858浏览 • 1回复 待解决
如何获取组件高度,有人知道吗
2986浏览 • 1回复 待解决
IDE如何开启ASAN,有人知道吗
967浏览 • 1回复 待解决
导航栏如何适配,有人知道吗?
2514浏览 • 0回复 待解决
如何引用HSP库,有人知道吗?
2425浏览 • 1回复 待解决
如何实现翻页功能,有人知道吗
2756浏览 • 1回复 待解决
如何使用快速修复,有人知道吗
1423浏览 • 1回复 待解决
深色模式如何屏蔽?有人知道吗
982浏览 • 0回复 待解决
如何实现图片预览,有人知道吗
1385浏览 • 1回复 待解决
如何获取wifi列表,有人知道吗
1623浏览 • 1回复 待解决
clientid相关问题,有人知道吗
2730浏览 • 1回复 待解决
webview组件demo ,有人知道吗
1632浏览 • 1回复 待解决
taskpool 使用问题,有人知道吗
1916浏览 • 1回复 待解决
有人知道吗
1129浏览 • 1回复 待解决
如何压缩字符串,有人知道吗
1434浏览 • 1回复 待解决