HarmonyOS dialog覆盖的问题?

当前页面A弹出dialog 点击dialog的条目跳转另一个页面B 如何保证B页面回退A页面dialog不消失,且不覆盖在B页面上

阅读 599
1 个回答

参考demo:

@Component
export struct PrivacyDialog {
  @Consume('pageInfo') pageStack : NavPathStack;
  @State isAgree: string = "Not Agree";

  build() {
    NavDestination(){
      Stack({ alignContent: Alignment.Center }){
        // 蒙层
        Column() {
        }
        .width("100%")
        .height("100%")
        .backgroundColor('rgba(0,0,0,0.5)')
        // 隐私弹窗
        Column() {
          Text("注册应用账号").fontSize(30).height('20%')
          Text("请您仔细阅读一下协议并同意,我们将全力保护您的个人信息安全,您可以使用账号登录APP。").height('40%')
          Divider()
          Row(){
            // 点击隐私条款,跳转到隐私条款页面,并接受隐私条款的返回值,用来刷新页面的同意状态。
            Text("《应用隐私政策》").onClick(ent => {
              let pathInfo : NavPathInfo = new NavPathInfo('PrivacyItem', null
                , (popInfo: PopInfo) => {
                  this.isAgree = popInfo.result.toString();
                })
              this.pageStack.pushDestination(pathInfo, true)
            })
            Text(this.isAgree)
          }.height('20%')
          Divider()
          // 点击同意\不同意按钮,将状态返回登录页
          Row(){
            Button("不同意").onClick(ent => {
              this.pageStack.pop("Not Agree", true)
            }).width('30%')
            Button("同意").onClick(ent => {
              this.pageStack.pop("Agree", true)
            }).width('30%')
          }.height('20%')
        }.backgroundColor(Color.White)
        .height('50%')
        .width('80%')
      }
    }.hideTitleBar(true)
    // 设置Dialog类型
    .mode(NavDestinationMode.DIALOG)
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进