HarmonyOS如何实现跳转页面弹窗不关闭?

HarmonyOS如何实现跳转页面弹窗不关闭?

HarmonyOS
2024-09-29 11:11:29
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

参考demo:

import router from '@ohos.router';  
@CustomDialog  
struct CustomDialog_Out_example {  
  controller?: CustomDialogController  
  cancel: () => void = () => {  
  }  
  confirm: () => void = () => {  
  }  
  build() {  
    Column() {  
      Text('可展示在主窗口外的弹窗')  
        .fontSize(30)  
        .height(100)  
      Button('点我跳转页面')  
        .onClick(() => {  
          if (this.controller != undefined) {  
            router.pushUrl({  
              url: 'pages/UI/Focus_Controller'  
            })  
          }  
        })  
        .margin(20)  
    }  
  }  
}  
@Entry  
@Component  
struct CustomDialog_Out {  
  dialogController: CustomDialogController | null = new CustomDialogController({  
    builder: CustomDialog_Out_example({  
      cancel: ()=> { this.onCancel() },  
      confirm: ()=> { this.onAccept() }  
    }),  
    cancel: this.existApp,  
    autoCancel: true,  
    onWillDismiss:(dismissDialogAction: DismissDialogAction)=> {  
      console.info("reason=" + JSON.stringify(dismissDialogAction.reason))  
      console.log("dialog onWillDismiss")  
      if (dismissDialogAction.reason == DismissReason.PRESS_BACK) {  
        dismissDialogAction.dismiss()  
      }  
      if (dismissDialogAction.reason == DismissReason.TOUCH_OUTSIDE) {  
        dismissDialogAction.dismiss()  
      }  
    },  
    alignment: DialogAlignment.Center,  
    offset: { dx: 0, dy: -20 },  
    gridCount: 4,  
    showInSubWindow: true,  
    isModal: true,  
    customStyle: false,  
    cornerRadius: 10,  
  })  
  // 在自定义组件即将析构销毁时将dialogControlle置空  
  aboutToDisappear() {  
    this.dialogController = null // 将dialogController置空  
  }  
  onCancel() {  
    console.info('Callback when the first button is clicked')  
  }  
  onAccept() {  
    console.info('Callback when the second button is clicked')  
  }  
  existApp() {  
    console.info('Click the callback in the blank area')  
  }  
  build() {  
    Column() {  
      Button('click me')  
        .onClick(() => {  
          if (this.dialogController != null) {  
            this.dialogController.open()  
          }  
        }).backgroundColor(0x317aff)  
    }.width('100%').margin({ top: 5 })  
  }  
}
分享
微博
QQ
微信
回复
2024-09-29 16:09:17
相关问题
全局关闭弹窗如何实现
223浏览 • 2回复 待解决
HarmonyOS 如何关闭键盘 再关闭弹窗
404浏览 • 1回复 待解决
弹窗跳转页面后返回弹窗不消失
1597浏览 • 1回复 待解决
HarmonyOS如何实现hap包页面跳转
604浏览 • 1回复 待解决
dialog跳转页面返回后dialog关闭
258浏览 • 1回复 待解决
page页面关闭关闭指定页面么?
486浏览 • 1回复 待解决