HarmonyOS鸿蒙Next中底部弹出的弹窗用哪个组件好
HarmonyOS鸿蒙Next中底部弹出的弹窗用哪个组件好 底部弹出的弹窗用哪个组件好,最好有demo
4 回复
推荐使用半模态转场,参考文档,文档里有示例
或者可以通过自定义弹框实现:
let anmDuration: number = 300;
// 弹窗交互
@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("自定义动画的弹窗")
}
.borderRadius(20)
.backgroundColor('#ff6288cb')
.height(200)
.width('100%')
}
.margin({ top: 10 })
.justifyContent(FlexAlign.Center)
.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: 500 })))
}
// 延迟关闭弹窗,让自定义的出场动画显示
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%')
}
}
更多关于HarmonyOS鸿蒙Next中底部弹出的弹窗用哪个组件好的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
[https://ohpm.openharmony.cn/#/cn/detail/@abner%2Fdialog](https://ohpm.openharmony.cn/#/cn/detail/@abner%2Fdialog)
参考下这个
在HarmonyOS鸿蒙Next中,底部弹出的弹窗通常使用BottomSheet
组件。BottomSheet
是一个从屏幕底部滑出的面板,可以展示更多内容或操作选项。它适用于需要用户进行选择或执行操作的场景,具有良好的用户体验和交互效果。可以通过showBottomSheet
方法来显示,并通过hideBottomSheet
方法来隐藏。