From 941a41dff8812767ab3c3631571e90a4f68c790d Mon Sep 17 00:00:00 2001 From: chenwenchang Date: Fri, 27 Jun 2025 08:01:59 +0000 Subject: [PATCH] cherry pick 0512 19 Signed-off-by: chenwenchang --- zh-cn/application-dev/ui/arkts-sheet-page.md | 67 ++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/zh-cn/application-dev/ui/arkts-sheet-page.md b/zh-cn/application-dev/ui/arkts-sheet-page.md index 8bf772a0527..22c149a4efc 100644 --- a/zh-cn/application-dev/ui/arkts-sheet-page.md +++ b/zh-cn/application-dev/ui/arkts-sheet-page.md @@ -186,4 +186,71 @@ onWillSpringBackWhenDismiss: ((SpringBackAction: SpringBackAction) => { }), ``` +## 半模态支持避让中轴 +半模态从API version 14开始支持中轴避让,当前在2in1设备默认开启(仅窗口处于瀑布模式时产生避让)中轴避让能力,且在2in1设备默认避让区域为上半屏。开发者可以通过[SheetOptions](../reference/apis-arkui/arkui-ts/ts-universal-attributes-sheet-transition.md#sheetoptions)的enableHoverMode主动设置是否避让中轴,及[SheetOptions](../reference/apis-arkui/arkui-ts/ts-universal-attributes-sheet-transition.md#sheetoptions)的hoverModeArea设置避让中轴后显示区域。 + +- 半模态中轴避让不支持控件子窗能力,showInSubWindow=true场景。 +- 2in1设备上需同时满足窗口处于瀑布模式才会产生避让。 + +完整示例代码如下: + +```ts +@Entry +@Component +struct SheetTransitionExample { + @State isShow: boolean = false; + @State enableHoverMode: boolean = true; + @State hoverModeArea: HoverModeAreaType = HoverModeAreaType.TOP_SCREEN; + + @Builder + myBuilder() { + Column() { + Button("enableHoverMode切换") + .margin(10) + .fontSize(20) + .onClick(() => { + this.enableHoverMode = !this.enableHoverMode; + }) + + Button("hoverModeArea切换") + .margin(10) + .fontSize(20) + .onClick(() => { + this.hoverModeArea = this.hoverModeArea === HoverModeAreaType.TOP_SCREEN ? + HoverModeAreaType.BOTTOM_SCREEN : HoverModeAreaType.TOP_SCREEN; + }) + + Button("close modal") + .margin(10) + .fontSize(20) + .onClick(() => { + this.isShow = false; + }) + } + .width('100%') + .height('100%') + } + + build() { + Column() { + Button("拉起半模态") + .onClick(() => { + this.isShow = true; + }) + .fontSize(20) + .margin(10) + .bindSheet($$this.isShow, this.myBuilder(), { + height: 300, + backgroundColor: Color.Green, + preferType: SheetType.CENTER, + enableHoverMode: this.enableHoverMode, + hoverModeArea: this.hoverModeArea + }) + } + .justifyContent(FlexAlign.Center) + .width('100%') + .height('100%') + } +} +``` -- Gitee