HarmonyOS 跳转隐私协议弹窗不盖住新的页面,回来的时候弹窗还在

HarmonyOS
1天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

参考示例如下:

interface RouterParams {
  name?: string,
  onPop?: (data: PopInfo) => void
}

// 封装路由工具类,并注册自定义弹窗组件
class AppRouter {
  private static instance = new AppRouter();
  private pathStack: NavPathStack = new NavPathStack();

  public static getInstance(): AppRouter {
    return AppRouter.instance;
  }

  public getPathStack(): NavPathStack {
    return this.pathStack;
  }

  private pushPath(name: string): void {
    this.pathStack.pushPath({ name: name })
  }

  public static push(name: string): void {
    AppRouter.instance.pushPath(name);
  }

  public static openDialog(name: string, params?: RouterParams): void {
    AppRouter.instance.pathStack.pushPath({
      name: name, param: params, onPop: (data: PopInfo) => {
        if (params?.onPop) {
          params.onPop!(data);
        }
      }
    });
  }

  public static pop(): void {
    AppRouter.instance.pathStack.pop();
  }
}

@Component
  // NavDestinationMode.DIALOG
struct DefaultDialog {
  build() {
    NavDestination() {
      Stack({ alignContent: Alignment.Center }) {
        Column() {
        }
        .width("100%")
        .height("100%")
        .backgroundColor('rgba(0,0,0,0.5)')
        .transition(
          TransitionEffect.OPACITY.animation({
            duration: 300,
            curve: Curve.Friction
          })
        )
        .onClick(() => {
          AppRouter.pop();
        })

        Column() {
          Text("dialogA")
            .fontColor(Color.White)
          Button("push pageC", { stateEffect: true, type: ButtonType.Capsule })
            .onClick(() => {
              AppRouter.push("pageC")
            })
        }
        .width("50%")
        .height("30%")
        .backgroundColor('#ffae2d2d')
        .transition(
          TransitionEffect.scale({ x: 0, y: 0 }).animation({
            duration: 300,
            curve: Curve.Friction
          })
        )
      }
      .width("100%")
      .height("100%")
    }
    .mode(NavDestinationMode.DIALOG)
    .hideTitleBar(true)
  }
}

@Component
struct PageA {
  @Consume('pageInfos') pageInfos: NavPathStack;

  build() {
    NavDestination() {
      Button('push dialogA', { stateEffect: true, type: ButtonType.Capsule })
        .onClick(() => {
          AppRouter.openDialog("DefaultDialog");
        }).margin(10)
    }.title('PageA')
  }
}

@Component
struct PageC {
  @Consume('pageInfos') pageInfos: NavPathStack;

  build() {
    NavDestination() {
      Column() {
        Text('pageC')
          .margin(10)
        Button('返回', { stateEffect: true, type: ButtonType.Capsule })
          .onClick(() => {
            AppRouter.pop();
          }).margin(10)
      }
    }.mode(NavDestinationMode.STANDARD)
  }
}

@Entry
@Component
struct pageRoot01 {
  @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack()
  // 显隐控制设置为不占用
  @State visible: Visibility = Visibility.None

  @Builder
  PagesMap(name: string) {
    if (name == 'pageA') {
      PageA()
    } else if (name == 'pageC') {
      PageC()
    } else if (name == 'DefaultDialog') {
      DefaultDialog()
    }
  }

  build() {
    // 在根页面中注册NavPathStack
    Navigation(AppRouter.getInstance().getPathStack()) {
      Stack({ alignContent: Alignment.Center }) {
        Column() {
          Button('push PageA', { stateEffect: true, type: ButtonType.Capsule })
            .onClick(() => {
              AppRouter.push('pageA')
            })
        }
      }
      .height("100%")
      .width("100%")
    }
    .hideTitleBar(true)
    .navDestination(this.PagesMap)
  }
}
分享
微博
QQ
微信
回复
1天前
相关问题
弹窗跳转页面后返回弹窗不消失
1734浏览 • 1回复 待解决
隐私安全页面跳转实践
2878浏览 • 1回复 待解决
HarmonyOS dialog弹窗跳转问题
11浏览 • 1回复 待解决
HarmonyOS 页面弹窗样式弹出
570浏览 • 1回复 待解决
HarmonyOS PageA跳转PageB,弹窗消失
252浏览 • 1回复 待解决
HarmonyOS 弹窗封装后open生效
365浏览 • 1回复 待解决
HarmonyOS 麦克风权限弹窗
46浏览 • 1回复 待解决
Text模拟隐私协议,有好方案吗?
779浏览 • 1回复 待解决