在HarmonyOS NEXT开发中如何在List或者Grid中使用半模态 bindSheet?

在HarmonyOS NEXT开发中如何在List或者Grid中使用半模态 bindSheet?现在有一个类似于分享弹窗的页面,需要点击每一个item都会弹出一个半模态的页面?

阅读 505
1 个回答

请参考如下代码:

@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) 
  } 
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进