Popup弹出后,没办法在指定时机消失。
bindPopup的第二个参数是PopupOptions对象,其默认autoCancel的值是true,mask值也是true,会展示遮罩,点击遮罩会默认关闭Popup弹窗,而遮罩会遮挡住下面内容区域,导致点击事件无法透传到下面内容区域,而直接关闭弹窗。
如下示例代码中,第一个Button没有设置autoCancel和mask,点击页面其他位置会关闭Popup。而第二个Button设置了autoCancel为false,mask为false之后,点击页面其他位置Popup不会消失。
@Entry
@Component
struct PopupControlMiss {
@State customPopup: boolean = false;
@State handlePopup: boolean = false;
build() {
Column({ space: 100 }) {
Button('popup')
.margin({ top: 50 })
.onClick(() => {
this.customPopup = !this.customPopup;
})
.bindPopup(this.customPopup, {
message: 'this is a popup',
arrowHeight: 20, // 设置气泡箭头高度
arrowWidth: 20, // 设置气泡箭头宽度
radius: 20, // 设置气泡的圆角
shadow: ShadowStyle.OUTER_DEFAULT_XS, // 设置气泡的阴影
});
Button('PopupOptions')
.onClick(() => {
this.handlePopup = !this.handlePopup;
})
.bindPopup(this.handlePopup, {
width: 300,
message: 'This is a popup with PopupOptions',
mask: false,
arrowPointPosition: ArrowPointPosition.START, // 设置箭头的位置
backgroundBlurStyle: BlurStyle.NONE, // 关闭气泡的模糊背景
popupColor: Color.Red, // 设置气泡的背景色
autoCancel: false,
});
}
.width('100%');
}
}