HarmonyOS Next中如何实现切换页面弹窗不消失?

如何实现用户首次进入应用需要进行权限配置,弹出弹窗后,点击跳转到隐私详情页面,返回后弹窗还在显示?

本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。

阅读 644
1 个回答

NavDestinationMode.DIALOG弹窗存在于路由栈中,可以实现切换页面弹窗不消失。

@Component
export struct CustomDialogNotDisappear {
  @Consume('NavPathStack') pageStack: NavPathStack;

  build() {
    NavDestination() {
      Column() {
        Row() {
          Button('OPEN')
            .fontSize(16)
            .width('100%')
            .borderRadius(20)
            .margin({ bottom: 16 })
            .backgroundColor('#0A59F7')
            .onClick(() => {
              this.pageStack.pushPathByName('DialogPage', '');
            })
        }
        .width('100%')
        .alignItems(VerticalAlign.Center)
      }
      .width('100%')
      .height('100%')
      .padding({
        left: 16,
        right: 16
      })
      .justifyContent(FlexAlign.End)
    }
  }
}

@Component
export struct DialogPage {
  @Consume('NavPathStack') pageStack: NavPathStack;

  build() {
    NavDestination() {
      Stack({ alignContent: Alignment.Center }) {
        Column() {
          Row() {
            Text('Title')
              .fontSize(20)
              .fontWeight(FontWeight.Bold)
          }
          .width('100%')
          .height(56)
          .justifyContent(FlexAlign.Center)

          Text('This is a dialog content.')
            .fontSize(14)

          Button('CONFIRM')
            .fontSize(16)
            .fontColor('#0A59F7')
            .backgroundColor(Color.White)
            .onClick(() => {
              this.pageStack.pushPathByName('PageOne', 'PageOne Param');
            })
            .width('100%')
            .margin({
              top: 8,
              bottom: 16
            })
        }
        .padding({
          left: 24,
          right: 24
        })
        .justifyContent(FlexAlign.Center)
        .alignItems(HorizontalAlign.Center)
        .backgroundColor(Color.White)
        .borderRadius(32)
        .margin({
          left: 16,
          right: 16
        })
      }
      .height('100%')
      .width('100%')
    }
    .backgroundColor('rgba(0,0,0,0.2)')
    .hideTitleBar(true)
    .mode(NavDestinationMode.DIALOG)
  }
}

@Component
export struct PageOne {
  @Consume('NavPathStack') pageStack: NavPathStack;

  build() {
    NavDestination() {
      Stack({ alignContent: Alignment.Center }) {
        Column() {
          Row() {
            Image($r('app.media.Back'))
              .width(40)
              .height(40)
              .margin({ right: 8 })
              .onClick(() => {
                this.pageStack.pop();
              })

            Text('Back')
              .fontSize(20)
              .fontWeight(FontWeight.Bold)
          }
          .width('100%')
          .height(56)
          .justifyContent(FlexAlign.Start)
        }
        .backgroundColor('#F1F3F5')
        .padding({
            left: 16,
            right: 16
        })
        .height('100%')
        .width('100%')
      }
      .height('100%')
      .width('100%')
    }
    .backgroundColor('#F1F3F5')
    .hideTitleBar(true)
    .mode(NavDestinationMode.DIALOG)
  }
}

本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题