HarmonyOS 半模态弹框(bindSheet)在折叠屏展开状态和平板上没有了半模态的效果?

半模态弹框(bindSheet)在折叠屏展开状态和平板上没有了半模态的效果,不知道正常不?如果是正常的,我们需要修改一个我们的设计,或者在折叠屏展开状态和平板上不展示。

阅读 595
1 个回答

想让半模态在折叠屏和平板上正常展开,应将半模态类型设置为底部弹窗( preferType : SheetType.BOTTOM )。

参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-sheet-transition-V5\#sheettype11枚举说明

测试demo如下:

// xxx.ets
@Entry
@Component
struct SheetTransitionExample {
  @State isShow:boolean = false
  @Builder myBuilder() {
    Column() {
      Button("content1")
        .margin(10)
        .fontSize(20)

      Button("content2")
        .margin(10)
        .fontSize(20)
    }
    .width('100%')
  }

  build() {
    Column() {
      Button("transition modal 1")
        .onClick(() => {
          this.isShow = true
        })
        .fontSize(20)
        .margin(10)
        .bindSheet($$this.isShow, this.myBuilder(),{
          detents:[SheetSize.MEDIUM,SheetSize.LARGE,200],
          backgroundColor:Color.Gray,
          blurStyle:BlurStyle.Thick,
          showClose:true,
          title:{title:"title", subtitle:"subtitle"},
          // 将弹窗类型设置为底部弹窗
          preferType: SheetType.BOTTOM,
          shouldDismiss:((sheetDismiss: SheetDismiss)=> {
            console.log("bind sheet shouldDismiss")
            sheetDismiss.dismiss()
          })
        })
    }
    .backgroundColor(Color.Green)
    .justifyContent(FlexAlign.Start)
    .width('100%')
    .height('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进