• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 半模态转场
2
3通过bindSheet属性为组件绑定半模态页面,在组件插入时可通过设置自定义或默认的内置高度确定半模态大小。
4
5>  **说明:**
6>
7>  从API Version 10开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
8>
9>  不支持横竖屏切换。
10>
11>  不支持路由跳转。
12
13## 属性
14
15| 名称        | 参数                                       | 参数描述                                     |
16| --------- | ---------------------------------------- | ---------------------------------------- |
17| bindSheet | isShow: boolean,<br>builder: [CustomBuilder](ts-types.md#custombuilder8),<br>options?: [SheetOptions](#sheetoptions) | 给组件绑定半模态页面,点击后显示模态页面。<br>isShow: 是否显示半模态页面。<br>从API version 10开始,该参数支持[$$](../../quick-start/arkts-two-way-sync.md)双向绑定变量<br>builder: 配置半模态页面内容。<br> options: 配置半模态页面的可选属性。 |
18> **说明:**
19>
20> 在非双向绑定情况下,以拖拽方式关闭半模态页面不会改变isShow参数的值。
21>
22> 为了使isShow参数值与半模态界面的状态同步,建议使用[$$](../../quick-start/arkts-two-way-sync.md)双向绑定isShow参数。
23## SheetOptions
24
25继承自[BindOptions](#bindoptions)。
26
27| 名称              | 类型                                       | 必填   | 描述              |
28| --------------- | ---------------------------------------- | ---- | --------------- |
29| height          | [SheetSize](#sheetsize)&nbsp;\|&nbsp;[Length](ts-types.md#length) | 否    | 半模态高度,默认是LARGE。 |
30| dragBar         | boolean                                  | 否    | 是否显示控制条,默认显示。   |
31| maskColor | [ResourceColor](ts-types.md#resourcecolor) | 否 | 半模态页面的背景蒙层颜色。 |
32
33## BindOptions
34
35| 名称            | 类型                                       | 必填 | 说明                     |
36| --------------- | ------------------------------------------ | ---- | ------------------------ |
37| backgroundColor | [ResourceColor](ts-types.md#resourcecolor) | 否   | 半模态页面的背板颜色。   |
38| onAppear        | () => void                                 | 否   | 半模态页面显示回调函数。 |
39| onDisappear     | () => void                                 | 否   | 半模态页面回退回调函数。 |
40
41## SheetSize枚举说明
42
43| 名称     | 参数描述            |
44| ------ | --------------- |
45| MEDIUM | 指定半模态高度为屏幕高度一半。 |
46| LARGE  | 指定半模态高度几乎为屏幕高度。 |
47
48## 示例
49
50```ts
51// xxx.ets
52@Entry
53@Component
54struct SheetTransitionExample {
55  @State isShow:boolean = false
56  @State isShow2:boolean = false
57  @State sheetHeight:number = 300;
58  @State showDragBar:boolean = true;
59
60  @Builder myBuilder() {
61    Column() {
62      Button("change height")
63        .margin(10)
64        .fontSize(20)
65        .onClick(()=>{
66          this.sheetHeight = 500;
67        })
68
69      Button("Set Illegal height")
70        .margin(10)
71        .fontSize(20)
72        .onClick(()=>{
73          this.sheetHeight = -1;
74        })
75
76      Button("close dragBar")
77        .margin(10)
78        .fontSize(20)
79        .onClick(()=>{
80          this.showDragBar = false;
81        })
82
83      Button("close modal 1")
84        .margin(10)
85        .fontSize(20)
86        .onClick(()=>{
87          this.isShow = false;
88        })
89    }
90    .width('100%')
91    .height('100%')
92  }
93
94  build() {
95    Column() {
96      Button("transition modal 1")
97        .onClick(() => {
98          this.isShow = true
99        })
100        .fontSize(20)
101        .margin(10)
102        .bindSheet($$this.isShow, this.myBuilder(), {height: this.sheetHeight, dragBar: this.showDragBar, backgroundColor: Color.Green, onAppear: () => {console.log("BindSheet onAppear.")}, onDisappear: () => {console.log("BindSheet onDisappear.")}})
103    }
104    .justifyContent(FlexAlign.Center)
105    .width('100%')
106    .height('100%')
107  }
108}
109```
110
111![zh-cn_sheet](figures/zh-cn_sheet.gif)
112