调用expandSafeArea将页面内容扩展至系统安全区域外部,同时,CustomDialogController会自动为弹窗添加半透明遮罩层,用于阻断用户与底层内容的交互,通过CustomDialogController弹出对话框,实现遮罩效果。
@CustomDialog
struct CustomDialogExample {
controller?: CustomDialogController;
build() {
Column() {
Text('遮罩层')
.fontColor(Color.White)
.fontSize(30);
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
.borderRadius(10)
.onClick(() => {
this.controller?.close();
});
}
}
@Entry
@Component
struct CustomDialogMask {
dialogController: CustomDialogController = new CustomDialogController({
builder: CustomDialogExample(),
customStyle: true
});
build() {
Column() {
Button('click me')
.onClick(() => {
this.dialogController.open();
});
}
.width('100%')
.height('100%')
.backgroundColor('#ffe2eeff')
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]);
}
}