为app提供侧边栏,显示文本或者组件的容器
1.用法
- 子组件类型:系统组件和自定义组件
- 子组件个数:必须且仅包含2个子组件,第一个位置的组件作为侧边栏的内容,第二个位置的组件是内容
- 子组件个数异常时:3个或以上子组件,显示第一个和第二个。1个子组件显示侧边栏,内容区为空白。
SideBarContainer(SideBarContainerType.Overlay) {
Column() {
// 子组件 1:侧边栏
}
Column() {
// 子组件 2:内容区域
}
}
.showSideBar(false) // 默认隐藏
| showSideBar | boolean | 设置是否显示侧边栏。true:显示侧边栏false:不显示侧边栏默认值:true。 | |
|---|---|---|---|
| 参数名 | 参数类型 | 必填 | 参数描述 |
| ------- | -------------------- | ------ | ----------------------------------------- |
| type | SideBarContainerType | 否 | 设置侧边栏的显示类型。默认值:SideBarContainerType.Embed |
@Entry
@Component
struct SideBarContainer01 {
build() {
SideBarContainer(SideBarContainerType.Overlay) {
Column() {
// 子组件 1:侧边容器
}
.backgroundColor(Color.Orange)
Column() {
// 子组件 2:内容区域
}
.backgroundColor(Color.Pink)
}
.showSideBar(false) // 默认隐藏
}
}
2.属性
.showSideBar($$this.status) // true,false 默认隐藏
.showControlButton(true) // true:显示控制按钮(默认) false:不显示控制按钮
.sideBarWidth(350) // 设置侧边栏的宽度,默认值:240vp,超出minSideBarWidth和maxSideBarWidth设定的范围后该值无效
.sideBarPosition(SideBarPosition.End) //设置侧边栏显示位置。 默认值:SideBarPosition.Start
.minSideBarWidth(100) // 设置侧边栏最小宽度 默认值:240vp
.maxSideBarWidth(300) // 设置侧边栏最大宽度 默认值:280vp
| 名称 | 参数类型 | 描述 | |
|---|---|---|---|
| showSideBar | boolean | 设置是否显示侧边栏。true:显示侧边栏false:不显示侧边栏默认值:true从API version 10开始,该属性支持$$双向绑定变量。 | |
| showControlButton | boolean | 设置是否显示控制按钮。true:显示控制按钮false:不显示控制按钮默认值:true | |
| sideBarWidth | number | Length | 设置侧边栏的宽度。默认值:240vp单位:vp |
| sideBarPosition | SideBarPosition | 设置侧边栏显示位置。默认值:SideBarPosition.Start | |
| minSideBarWidth | number | Length9+ | 设置侧边栏最小宽度。默认值:240vp单位:vp |
| maxSideBarWidth | number | Length9+ | 设置侧边栏最大宽度。默认值:280vp单位:vp |
| 事件 | |||
| onChange(callback: (value: boolean) => void) | 当侧边栏的状态在显示和隐藏之间切换时触发回调。true表示显示,false表示隐藏。触发该事件的条件:1、showSideBar属性值变换时;2、showSideBar属性自适应行为变化时;3、分割线拖拽触发autoHide时。 | ||
| -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |