HarmonyOS @customDialog修饰的弹窗,在弹窗不关闭的情况下新开页面,新页面会在弹窗下层展示

@customDialog修饰的弹窗,在弹窗不关闭的情况下新开页面,弹窗会盖在新页面的上面

期望:新页面在弹窗上,弹窗不可见,关闭新页面后,显示弹窗

HarmonyOS
2024-12-26 13:32:35
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

如果想实现所说的应用场景,使用模态弹窗可能会更合适。可参考文档:

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-modal-transition-V5#使用if实现模态转场

以下是参考样例代码:

import { router } from '@kit.ArkUI';

@Entry
@Component
struct ModalTransitionTest {
  @State message: string = 'Hello World';
  @State showDialog: boolean = false

  onBackPress(): boolean | void {
    if (this.showDialog) {
      animateTo({duration: 300}, () => {
        this.showDialog = false
      })
      return true
    }
    return false
  }

  build() {
    Stack() {
      RelativeContainer() {
        Text(this.message)
          .id('ModalTransitionTestHelloWorld')
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .alignRules({
            center: { anchor: '__container__', align: VerticalAlign.Center },
            middle: { anchor: '__container__', align: HorizontalAlign.Center }
          })
          .onClick(() => {
            animateTo({duration: 300}, () => {
              this.showDialog = true
            })
          })
      }
      .height('100%')
      .width('100%')

      if (this.showDialog) {
        Column() {
          Column() {
            Text('跳转新页面')
              .fontSize(30)
              .onClick(() => {
                router.pushUrl({
                  url: 'pages/Index'
                })
              })
          }
          .backgroundColor(Color.White)
          .borderRadius(15)
          .width('80%')
          .height('40%')
          .transition(
            TransitionEffect.OPACITY.animation({ duration: 300, curve: Curve.FastOutLinearIn })
              .combine(TransitionEffect.scale({
                x: 0.3,
                y: 0.3
              }))
          )
        }
        .backgroundColor(0x44000000)
        .alignItems(HorizontalAlign.Center)
        .justifyContent(FlexAlign.Center)
        .width('100%')
        .height('100%')
        .onClick(() => {
          animateTo({duration: 300}, () => {
            this.showDialog = false
          })
        })
      }
    }
    .width('100%')
    .height('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
分享
微博
QQ
微信
回复
2024-12-26 16:23:35
相关问题
dialog跳转新页面返回后dialog关闭
1026浏览 • 1回复 待解决