HarmonyOS 弹窗A内点击关闭A打开弹窗B后无法绘制新组件
页面打开弹窗A,点击弹窗A里按钮,关闭弹窗A后打开弹窗B,弹窗B里if判断组件的image不会在条件为true时展示
// xxx.ets
@CustomDialog
struct CustomDialogExampleTwo {
controllerTwo?: CustomDialogController
@State form_img_idx: number = 0
@State flag: boolean = false
@State arr: Array<Resource> =
[$r('app.media.startIcon'), $r('app.media.startIcon'), $r('app.media.startIcon'), $r('app.media.startIcon'),
$r('app.media.startIcon'), $r('app.media.startIcon')]
@Builder
buildCover() {
ForEach(this.arr, (item: Resource, idx) => {
Stack() {
Image(item).width(100).onClick((e) => {
this.form_img_idx = idx;
this.flag = true;
console.log("this.form_img_idx", this.form_img_idx)
})
// Image($r(`app.media.icon`)).width(20).visibility(this.form_img_idx == idx?Visibility.Visible:Visibility.Hidden)
if (this.form_img_idx == idx) {
Image($r(`app.media.startIcon`)).width(20)
} else {
Image($r(`app.media.startIcon`)).width(30)
}
if (this.flag) {
Text(`${this.form_img_idx == idx}`)
}
}.margin({
bottom: "10lpx"
})
})
}
build() {
Column() {
Flex({
justifyContent: FlexAlign.SpaceBetween,
wrap: FlexWrap.Wrap
}) {
this.buildCover();
}
}.height(500).justifyContent(FlexAlign.Center)
}
}
@CustomDialog
@Component
struct CustomDialogExample {
@Link textValue: string
@Link inputValue: string
dialogControllerTwo: CustomDialogController | null = null;
initMenuAct() {
this.dialogControllerTwo = new CustomDialogController({
builder: CustomDialogExampleTwo({
}),
autoCancel: false,
isModal: true,
onWillDismiss: (dismissDialogAction: DismissDialogAction) => {
return false
},
alignment: DialogAlignment.Bottom
})
}
controller?: CustomDialogController
// 若尝试在CustomDialog中传入多个其他的Controller,以实现在CustomDialog中打开另一个或另一些CustomDialog,那么此处需要将指向自己的controller放在所有controller的后面
cancel: () => void = () => {
}
confirm: () => void = () => {
}
build() {
Column() {
Text('Change text').fontSize(20).margin({ top: 10, bottom: 10 })
TextInput({ placeholder: '', text: this.textValue }).height(60).width('90%')
.onChange((value: string) => {
this.textValue = value
})
Text('Whether to change a text?').fontSize(16).margin({ bottom: 10 })
Flex({ justifyContent: FlexAlign.SpaceAround }) {
Button('cancel')
.onClick(() => {
if (this.controller != undefined) {
this.controller.close()
this.cancel()
}
}).backgroundColor(0xffffff).fontColor(Color.Black)
Button('confirm')
.onClick(() => {
if (this.controller != undefined) {
this.inputValue = this.textValue
this.controller.close()
this.confirm()
}
}).backgroundColor(0xffffff).fontColor(Color.Red)
}.margin({ bottom: 10 })
Button('点我打开第二个弹窗')
.onClick(() => {
this.initMenuAct()
if (this.dialogControllerTwo != null) {
this.controller?.close()
this.dialogControllerTwo.open()
}
})
.margin(20)
}.borderRadius(10)
// 如果需要使用border属性或cornerRadius属性,请和borderRadius属性一起使用。
}
}
@Entry
@Component
struct CustomDialogUser {
@State textValue: string = ''
@State inputValue: string = 'click me'
dialogController: CustomDialogController | null = new CustomDialogController({
builder: CustomDialogExample({
cancel: () => {
this.onCancel()
},
confirm: () => {
this.onAccept()
},
textValue: $textValue,
inputValue: $inputValue
}),
cancel: this.exitApp,
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.Bottom,
offset: { dx: 0, dy: -20 },
gridCount: 4,
customStyle: false,
cornerRadius: 10,
})
// 在自定义组件即将析构销毁时将dialogController置空
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')
}
exitApp() {
console.info('Click the callback in the blank area')
}
build() {
Column() {
Button(this.inputValue)
.onClick(() => {
if (this.dialogController != null) {
this.dialogController.open()
}
}).backgroundColor(0x317aff)
}.width('100%').margin({ top: 5 })
}
}
- 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.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
- 166.
- 167.
- 168.
- 169.
- 170.
- 171.
- 172.
- 173.
- 174.
- 175.
- 176.
- 177.
- 178.
- 179.
HarmonyOS
赞
收藏 0
回答 1
相关问题
webview选择本地文件关闭文件打开方式弹窗后无法获取弹窗关闭事件
8913浏览 • 4回复 待解决
HarmonyOS 协议弹窗,在点击弹窗内的跳转链接后弹窗还在
447浏览 • 1回复 待解决
HarmonyOS 如何实现自定义弹窗内点击元素跳转时不关闭弹窗
1076浏览 • 1回复 待解决
HarmonyOS 怎么在页面退出时关闭所有页面内打开的弹窗
871浏览 • 1回复 待解决
HarmonyOS 自定义弹窗如何设置点击遮罩层关闭弹窗无效
697浏览 • 1回复 待解决
如何点击弹窗外部区域,可以是弹窗不会自动关闭?
793浏览 • 1回复 待解决
HarmonyOS CustomDialog内跳转其他页面弹窗不关闭
696浏览 • 1回复 待解决
自定义弹窗如何设置点击遮盖层不关闭弹窗
2750浏览 • 1回复 待解决
HarmonyOS 自定义弹窗(CustomDialog)无法关闭
1278浏览 • 1回复 待解决
弹窗打开、关闭动画是否支持自定义
3076浏览 • 1回复 待解决
CustomDialogController.open打开的弹窗被异常关闭
1037浏览 • 2回复 待解决
HarmonyOS promptAction.openCustomDialog如何实现点击弹窗阴影区域时弹窗不关闭
620浏览 • 1回复 待解决
HarmonyOS promptAction.showDialog点击区域外不关闭弹窗
543浏览 • 1回复 待解决
系统提供的popup弹窗是否点击了弹窗内容后弹窗一定会消失?
901浏览 • 1回复 待解决
HarmonyOS 自定义CustomDialogController弹窗不能关闭弹窗
1432浏览 • 0回复 待解决
HarmonyOS 自定义弹窗组件,点击空白处弹窗消失
475浏览 • 1回复 待解决
半模态转场关闭弹窗重新打开时无需重新加载
1651浏览 • 1回复 待解决
HarmonyOS 如何禁止弹窗关闭
1024浏览 • 1回复 待解决
HarmonyOS 如何实现打开弹窗后自动播放动画
879浏览 • 1回复 待解决
HarmonyOS 应用内弹窗实现
849浏览 • 1回复 待解决
HarmonyOS 如何先关闭键盘 再关闭弹窗
1067浏览 • 1回复 待解决
HarmonyOS 从弹窗里点击按钮打开的页面,弹窗会盖在新页面上面
1127浏览 • 1回复 待解决
HarmonyOS 页面返回会把上个页面已经打开的弹窗关闭掉
1785浏览 • 2回复 待解决
弹窗组件无法进入onPageShow方法
2478浏览 • 1回复 待解决
现在第二个dialog在前端的父节点是第一个dialog,第一个dialog下树之后,第二个dialog就无法响应状态变量了。这个是符合状态管理当前规格的(父节点销毁之后子节点不再刷新),当前可以通过改变第二个dialog弹出的位置(不让它在第一个弹窗里面执行open方法)去规避这一行为