Use openCustomDialog to open dialog box A and click the button in dialog box A to open dialog box B. Use getDialogController to obtain the PromptActionDialogController instance object and call the close() method to close the current dialog box. The code snippet is as follows:
import { ComponentContent } from '@kit.ArkUI';
@Component
struct DialogAComponent {
build() {
Column() {
Column() {
Text('dialog A')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}
.justifyContent(FlexAlign.Center)
.height(120)
Row() {
Text('close')
.fontColor('#0A59F7')
.onClick(() => {
// close self.
this.getDialogController()?.close();
})
.width('50%')
.height('100%')
.textAlign(TextAlign.Center)
Text('open dialog B')
.fontColor('#0A59F7')
.onClick(() => {
// Open dialog B.
let uiContext = this.getUIContext();
let promptAction = uiContext.getPromptAction();
promptAction.openCustomDialog(new ComponentContent(uiContext, wrapBuilder(dialogBBuilder)));
})
.width('50%')
.height('100%')
.textAlign(TextAlign.Center)
}
.height(50)
}
.width(360)
.borderRadius(32)
.backgroundColor(Color.White)
}
}
@Builder
function dialogABuilder() {
DialogAComponent()
}
@Component
struct DialogBComponent {
build() {
Column() {
Column() {
Text('dialog B')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}
.justifyContent(FlexAlign.Center)
.height(120)
Row() {
Text('close')
.fontColor('#0A59F7')
.onClick(() => {
// close self.
this.getDialogController()?.close();
})
.width('50%')
.height('100%')
.textAlign(TextAlign.Center)
}
.height(50)
}
.width(320)
.borderRadius(32)
.backgroundColor(Color.White)
}
}
@Builder
function dialogBBuilder() {
DialogBComponent()
}
@Entry
@Component
struct PopUpDialogAgainInCustomDialog {
build() {
Column() {
Button('open Dialog A')
.onClick(() => {
// Open dialog A.
let uiContext = this.getUIContext();
let promptAction = uiContext.getPromptAction();
promptAction.openCustomDialog(new ComponentContent(uiContext, wrapBuilder(dialogABuilder)));
})
}
.width('100%')
.height('100%')
.alignItems(HorizontalAlign.Center)
.justifyContent(FlexAlign.Center)
}
} 