问题场景宽度占据屏幕宽度(自定义弹窗方式 @CustomDialog 默认并没有占据百分百宽度 有间隙)底部对齐屏幕底部(自定义弹窗的定义 也没有到底 距离底部有间隙)目前CustomDialog不支持修改左右和下方边距,可通过半模态转场来实现,请参考取下代码:@Entry @Component struct BindSheetDemo { // 半模态转场显示隐藏控制 @State isShowSheet: boolean = false; private menuList: string[] = ['不要辣', '少放辣', '多放辣', '不要香菜', '不要香葱', '不要一次性餐具', '需要一次性餐具']; // 通过@Builder构建半模态展示界面 @Builder mySheet() { Column() { Flex({ direction: FlexDirection.Row, wrap: FlexWrap.Wrap }) { ForEach(this.menuList, (item: string) => { Text(item) .fontSize(16) .fontColor(0x333333) .backgroundColor(0xf1f1f1) .borderRadius(8) .margin(10) .padding(10) }) } .padding({ top: 18 }) } .width('100%') .height('100%') .backgroundColor(Color.White) } build() { Column() { Text('口味与餐具') .fontSize(28) .padding({ top: 30, bottom: 30 }) Column() { Row() { Row() .width(10) .height(10) .backgroundColor('#a8a8a8') .margin({ right: 12 }) .borderRadius(20) Column() { Text('选择点餐口味和餐具') .fontSize(16) .fontWeight(FontWeight.Medium) } .alignItems(HorizontalAlign.Start) Blank() Row() .width(12) .height(12) .margin({ right: 15 }) .border({ width: { top: 2, right: 2 }, color: 0xcccccc }) .rotate({ angle: 45 }) } .borderRadius(15) .shadow({ radius: 100, color: '#ededed' }) .width('90%') .alignItems(VerticalAlign.Center) .padding({ left: 15, top: 15, bottom: 15 }) .backgroundColor(Color.White) .bindSheet(this.isShowSheet, this.mySheet(), { height: 300, dragBar: false, onDisappear: () => { this.isShowSheet = !this.isShowSheet; } }) .onClick(() => { this.isShowSheet = !this.isShowSheet; }) } .width('100%') } .width('100%') .height('100%') .backgroundColor(0xf1f1f1) } }bindSheet可以有多个,同时bindSheet目前没有提供修改圆角的属性多个bindSheet,请参考以下代码:@Entry @Component struct BindSheetDemo { // 半模态转场显示隐藏控制 @State isShowSheet: boolean = false; @State isShowDetailSheet: boolean = false; private menuList: string[] = ['不要辣', '少放辣', '多放辣', '不要香菜', '不要香葱', '不要一次性餐具', '需要一次性餐具']; private detailList: string[] = ['直播间111111', '相关内容22222222', '更多334455665']; // 通过@Builder构建半模态展示界面 @Builder mySheet() { Column() { Flex({ direction: FlexDirection.Row, wrap: FlexWrap.Wrap }) { ForEach(this.menuList, (item: string) => { Text(item) .fontSize(16) .fontColor(0x333333) .backgroundColor(0xf1f1f1) .borderRadius(8) .margin(10) .padding(10) .onClick(() => { this.isShowDetailSheet = !this.isShowDetailSheet; }) }) } .bindSheet(this.isShowDetailSheet, this.myDetailSheet(), { // height: 550, dragBar: true, onDisappear: () => { this.isShowDetailSheet = !this.isShowDetailSheet; } }) .padding({ top: 18 }) } .width('100%') .height('100%') .backgroundColor(Color.White) } @Builder myDetailSheet() { Column() { Flex({ direction: FlexDirection.Row, wrap: FlexWrap.Wrap }) { ForEach(this.detailList, (item: string) => { Text(item) .fontSize(16) .fontColor(0x333333) .backgroundColor(0xf1f1f1) .borderRadius(8) .margin(10) .padding(10) }) } .padding({ top: 18 }) } .width('100%') .height('100%') .backgroundColor(Color.White) } build() { Column() { Text('直播间') .fontSize(28) .padding({ top: 30, bottom: 30 }) Column() { Row() { Row() .width(10) .height(10) .backgroundColor('#a8a8a8') .margin({ right: 12 }) .borderRadius(20) Column() { Text('点击查看') .fontSize(16) .fontWeight(FontWeight.Medium) } .alignItems(HorizontalAlign.Start) Blank() Row() .width(12) .height(12) .margin({ right: 15 }) .border({ width: { top: 2, right: 2 }, color: 0xcccccc }) .rotate({ angle: 45 }) } .borderRadius(15) .shadow({ radius: 100, color: '#ededed' }) .width('90%') .alignItems(VerticalAlign.Center) .padding({ left: 15, top: 15, bottom: 15 }) .backgroundColor(Color.White) .bindSheet(this.isShowSheet, this.mySheet(), { height: 150, dragBar: false, onDisappear: () => { this.isShowSheet = !this.isShowSheet; } }) .onClick(() => { this.isShowSheet = !this.isShowSheet; }) } .width('100%') } .width('100%') .height('100%') .backgroundColor(0xf1f1f1) } }同一个组件只能绑定一个bindsheet同一个页面下多个弹窗,可以把bindsheet绑定在触发bindsheet显隐的组件上,参考代码如下:@Entry @Component struct TEST { @State isShowSheet1 :boolean =false @State isShowSheet2 :boolean =false build() { Column(){ Text('按钮1 ') .bindSheet(this.isShowSheet1,this.Sheet1()) .onClick(()=>{ this.isShowSheet1 = true }) Text('按钮2 ') .onClick(()=>{ this.isShowSheet2 = true }) .bindSheet(this.isShowSheet2,this.Sheet2()) .margin({top:40}) } } @Builder Sheet1(){ Column(){ Text('1') } } @Builder Sheet2(){ Column(){ Text('2') } } }
问题场景
宽度占据屏幕宽度(自定义弹窗方式 @CustomDialog 默认并没有占据百分百宽度 有间隙)
底部对齐屏幕底部(自定义弹窗的定义 也没有到底 距离底部有间隙)
目前CustomDialog不支持修改左右和下方边距,可通过半模态转场来实现,请参考取下代码:
bindSheet可以有多个,同时bindSheet目前没有提供修改圆角的属性
多个bindSheet,请参考以下代码:
同一个组件只能绑定一个bindsheet
同一个页面下多个弹窗,可以把bindsheet绑定在触发bindsheet显隐的组件上,参考代码如下: