HarmonyOS 半模态页面切换高度档位问题

根据文档半模态页面实现切换高度调整需要绑定height,但height在设置detents时无效。现有一半模态页面需要有两个高度档位,且在跟手滑动时及点击页面中的按钮时,都可以切换该半模态页面高度档位,该如何实现?

HarmonyOS
2024-12-25 13:58:22
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
FengTianYa

参考示例如下:

@Entry
@Component
struct SheetTransitionExample {
  @State isShow: boolean = false
  @State isDetents: boolean = true
  @State bindSheetHeight: number = 300

  @Builder
  myBuilder() {
    Column() {
      Button("跳到二档高度")
        .margin(10)
        .fontSize(20).onClick(() => {
        this.isDetents = false
      })

      Button("跳到一档高度")
        .margin(10)
        .fontSize(20).onClick(() => {
        this.isDetents = true
      })
    }
    .width('100%')
  }

  build() {
    Column() {
      Button("显示")
        .onClick(() => {
          this.isShow = true
        })
        .fontSize(20)
        .margin(10)
        .bindSheet($$this.isShow, this.myBuilder(), {
          // height: this.bindSheetHeight,
          detents: this.isDetents ? [300, 500] : [500, 700],
          backgroundColor: Color.Gray,
          blurStyle: BlurStyle.Thick,
          showClose: true,
          title: { title: "title", subtitle: "subtitle" },
          preferType: SheetType.CENTER,
          shouldDismiss: ((sheetDismiss: SheetDismiss) => {
            console.log("bind sheet shouldDismiss")
            sheetDismiss.dismiss()
          })
        })
    }
    .justifyContent(FlexAlign.Start)
    .width('100%')
    .height('100%')
  }
}
分享
微博
QQ
微信
回复
2024-12-25 16:31:36
相关问题
模态转场如何控制固定高度
2183浏览 • 1回复 待解决
如何固定模态转场的高度
883浏览 • 1回复 待解决
HarmonyOS Grid和模态问题
377浏览 • 1回复 待解决
HarmonyOS 模态转场
405浏览 • 1回复 待解决
HarmonyOS bindSheet模态弹窗
700浏览 • 1回复 待解决
HarmonyOS 模态相关使用
454浏览 • 1回复 待解决
HarmonyOS 如何转换模态
412浏览 • 1回复 待解决
模态转场来实现弹框样式的页面
1165浏览 • 1回复 待解决
基于bindSheet的模态弹窗
1399浏览 • 1回复 待解决
应用怎么实现模态效果
2596浏览 • 1回复 待解决
HarmonyOS 关于模态转场的疑问
331浏览 • 1回复 待解决
HarmonyOS 模态会被软键盘顶起
307浏览 • 1回复 待解决