HarmonyOS 使用半模态转场指定SheetMode为EMBEDDED时如何使用

使用半模态转场bindSheet,指定SheetMode为EMBEDDED时,弹层无法弹出,想请教具体用法,下方是相关代码,如果将SheetMode改为OVERLAY就可以弹出

build() {
  RelativeContainer() {
    Column() {}
    .width('100%')
    .height('100%')
    .alignRules({
      top: { anchor: '__container__', align: VerticalAlign.Top },
      bottom: { anchor: '__container__', align: VerticalAlign.Bottom },
      left: { anchor: '__container__', align: HorizontalAlign.Start },
      right: { anchor: '__container__', align: HorizontalAlign.End }
    });
  }
  .bindSheet(true, this.buildBottomSheet(), {
    showClose: false,
    dragBar: false,
    preferType: SheetType.BOTTOM,
    // enableOutsideInteractive:true,
    mode:SheetMode.EMBEDDED,
    detents: [122, 32, 32],
  })
  .padding({ bottom: this.bottomRectHeight })
  .width('100%')
  .height('100%')
}

@Builder
buildBottomSheet() {
  Column()
    .width('100%')
    .height('100%')
    .backgroundColor(Color.Green)
}
  • 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.
HarmonyOS
2024-12-24 16:42:47
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

可以参考这个demo:

@Entry
@Component
struct SheetModeDemo {
  @State message: string = 'Hello World';
  @State sheetMode: boolean = false
  @Builder
  buildBottomSheet() {
    Column()
      .width('100%')
      .height('100%')
      .backgroundColor(Color.Green)
  }

  build() {
    RelativeContainer() {
      Column() {
        Button('修改模态框的值')
          .onClick(() => {
            console.log('模态框的属性值修改了')
            this.sheetMode = true
          })
      }
      .width('100%')
      .height('100%')
      .alignRules({
        top: { anchor: '__container__', align: VerticalAlign.Top },
        bottom: { anchor: '__container__', align: VerticalAlign.Bottom },
        left: { anchor: '__container__', align: HorizontalAlign.Start },
        right: { anchor: '__container__', align: HorizontalAlign.End }
      });
    }
    .bindSheet(this.sheetMode, this.buildBottomSheet(), {
      showClose: false,
      dragBar: false,
      preferType: SheetType.BOTTOM,
      // enableOutsideInteractive:true,
      mode:SheetMode.EMBEDDED,
      // mode:SheetMode.OVERLAY,
      detents: [122, 32, 32],
      onDisappear: () => {
        this.sheetMode = false
      }
    })
    //.padding({ bottom: this.bottomRectHeight })
    .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.
分享
微博
QQ
微信
回复
2024-12-24 20:05:51
相关问题
HarmonyOS 模态转场
936浏览 • 1回复 待解决
模态转场如何控制固定高度
2728浏览 • 1回复 待解决
HarmonyOS 模态转场如何透传手势?
1206浏览 • 1回复 待解决
如何固定模态转场的高度
1416浏览 • 1回复 待解决
HarmonyOS 模态相关使用
916浏览 • 1回复 待解决
HarmonyOS 关于模态转场的疑问
870浏览 • 1回复 待解决
模态转场来实现弹框样式的页面
1696浏览 • 1回复 待解决
HarmonyOS 如何转换模态
892浏览 • 1回复 待解决