首页 > 数据库 > 数据库开发技术 > HarmonyOS NEXT实战:弹出底部菜单
##HarmonyOS Next实战##HarmonyOS SDK应用服务##教育##
目标:拉起底部菜单,实现底部菜单的弹起和关闭。
知识点:
使用约束
生命周期 半模态页面提供了生命周期函数,用于通知用户该弹窗的生命周期状态。生命周期的触发顺序依次为:onWillAppear -> onAppear -> onWillDisappear -> onDisappear。
使用嵌套滚动交互:半模态上述交互默认的嵌套模式为:{Forward:PARENT_FIRST,Backward:SELF_FIRST}
在半模态面板内容区域滑动时的操作优先级:
实战:BottomPopUpDemoPage
@Entry
@Component
struct BottomPopUpDemoPage {
@State isShow: boolean = false
@State sheetHeight: number = 300;
build() {
Column({ space: 20 }) {
Text('底部菜单Demo')
Button("拉起底部菜单")
.onClick(() => {
this.isShow = true
})
.fontSize(20)
.margin(10)
.bindSheet($$this.isShow, this.buildSheet(), {
height: this.sheetHeight,
backgroundColor: '#EEEEEE',
onWillAppear: () => {
console.log("BindSheet onWillAppear.")
},
onAppear: () => {
console.log("BindSheet onAppear.")
},
onWillDisappear: () => {
console.log("BindSheet onWillDisappear.")
},
onDisappear: () => {
console.log("BindSheet onDisappear.")
}
})
}
.width('100%')
.height('100%')
}
@Builder
buildSheet() {
Column({ space: 10 }) {
Text('底部菜单栏')
Button('菜单 1')
Button('菜单 2')
Button('菜单 3')
Button("收起菜单")
.fontSize(20)
.backgroundColor(Color.Gray)
.onClick(() => {
this.isShow = false;
})
}
.width('100%')
.height('100%')
.padding({ top: 10 })
}
}
原文作者:;如有侵权,请联系管理员删除。