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%')
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-25 16:31:36
相关问题
如何固定模态转场的高度
1416浏览 • 1回复 待解决
模态转场如何控制固定高度
2728浏览 • 1回复 待解决
HarmonyOS Grid和模态问题
901浏览 • 1回复 待解决
HarmonyOS 模态转场
936浏览 • 1回复 待解决
HarmonyOS 如何转换模态
892浏览 • 1回复 待解决
HarmonyOS 模态相关使用
916浏览 • 1回复 待解决
HarmonyOS bindSheet模态弹窗
1491浏览 • 1回复 待解决
模态转场来实现弹框样式的页面
1696浏览 • 1回复 待解决
HarmonyOS 关于模态转场的疑问
870浏览 • 1回复 待解决
应用怎么实现模态效果
3006浏览 • 1回复 待解决
基于bindSheet的模态弹窗
2029浏览 • 1回复 待解决