拉起双半模态,在实际开发中,我们在点击对应的选项时,需要通过半模态去进行进行着重显示

在实际开发中,我们在点击对应的选项时,需要通过半模态去进行进行着重显示,有时会出现二级标签,此时需要二次显示半模态并且在选中后同时消失的功能。

HarmonyOS
2024-05-26 14:20:16
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
rhyine

通过bindSheet功能给组件绑定半模态页面,点击后显示模态页面。

@Entry 
@Component 
struct SheetTransitionExample { 
  @State isShow: boolean = false 
  @State isShow2: boolean = false 
  @State sheetHeight: number = 400; 
  @State sheetHeight2: number = 200; 
  @State showDragBar: boolean = true; 
  @State showDragBar2: boolean = true; 
  
  @Builder 
  myBuilder() { 
    Column() { 
      Button("close modal 1") 
        .margin(10) 
        .fontSize(20) 
        .onClick(() => { 
          this.isShow = false; 
        }) 
      Button("open sheet2") 
        .margin(10) 
        .fontSize(20) 
        .onClick(() => { 
          // this.isShow = false; 
          this.isShow2 = true; 
        }) 
        .bindSheet( 
          $$this.isShow2, 
          this.myBuilder2(), 
          { 
            height: this.sheetHeight2, 
            dragBar: this.showDragBar2, 
            backgroundColor: Color.Blue, 
            maskColor:Color.Black, 
            onAppear: () => { 
              console.log("BindSheet onAppear.") 
            }, 
            onDisappear: () => { 
              console.log("BindSheet onDisappear.") 
            } 
          } 
        ) 
  
    } 
    .width('100%') 
    .height('100%') 
  } 
  
  @Builder 
  myBuilder2() { 
    Column() { 
      Button("close sheet2") 
        .margin(10) 
        .fontSize(20) 
        .onClick(() => { 
          this.isShow2 = false; 
          this.isShow = false; 
        }) 
    } 
    .width('100%') 
    .height('100%') 
  } 
  
  build() { 
    Column() { 
      Button("transition modal 1") 
        .onClick(() => { 
          this.isShow = true 
        }) 
        .fontSize(20) 
        .margin(10) 
        .bindSheet($$this.isShow, this.myBuilder(), { 
          height: this.sheetHeight, 
          dragBar: this.showDragBar, 
          backgroundColor: Color.Green, 
          maskColor:Color.Black, 
          onAppear: () => { 
            console.log("BindSheet onAppear.") 
          }, 
          onDisappear: () => { 
            console.log("BindSheet onDisappear.") 
          } 
        }) 
    } 
    .justifyContent(FlexAlign.Center) 
    .width('100%') 
    .height('100%') 
  } 
}
分享
微博
QQ
微信
回复
2024-05-27 18:09:56
相关问题
基于bindSheet模态弹窗
175浏览 • 1回复 待解决
应用怎么实现模态效果
676浏览 • 1回复 待解决
模态转场如何控制固定高度
500浏览 • 1回复 待解决
模态转场来实现弹框样式页面
366浏览 • 1回复 待解决
CustomDialog如何实现模态详情页效果
492浏览 • 1回复 待解决
如何使用命令行进行app打包
459浏览 • 1回复 待解决
Native侧进行跨模块加载
203浏览 • 1回复 待解决