在CustomDialog中打开新的页面,CustomDialog会自动消失
在CustomDialog中打开新的页面,CustomDialog会自动消失,如何解决。
代码描述:
ActionSheetExample.ets:
import { CustomDialogExample } from'…/view/CustomDialogExample';
import { UIContext } from '@ohos.arkui.UIContext';
import common from '@ohos.app.ability.common';
import { DialogManager } from '…/view/DialogManager';
@Entry
@Component
struct ActionSheetExample {
@State textValue: string = ''
@State inputValue: string = 'click me'
@State angle: number = 0
dialogController: CustomDialogController | null = new CustomDialogController({
builder: CustomDialogExample(),
autoCancel: true,
alignment: DialogAlignment.Bottom,
openAnimation: { duration: 0 },
closeAnimation: { duration: 0 },
offset: { dx: 0, dy: 0 },
// maskColor: ‘rgba(0, 0, 0, 0)’,
customStyle: true
})
constructor() {
super()
}
build() {
Column() {
Text('rotate').width('90%').fontColor(0xCCCCCC).padding(15).fontSize(14)
Row()
.rotate({
x: 0,
y: 0,
z: 1,
angle: this.angle
})// 组件以矢量(0,0,1)为旋转轴,绕中心点顺时针旋转300度
.width(100)
.height(50)
.backgroundColor(0xAFEEEE)
.onClick(() => {
animateTo({ curve: Curve.Ease, onFinish: () => {
}, duration: 300 }, () => {
this.angle += 180
})
})
Button(this.inputValue)
.onClick(() => {
if (this.dialogController != null) {
this.dialogController.open()
}
}).backgroundColor(0x317aff)
.margin(20)
Button('打开CallerPage').onClick(() => {
let context = getContext(this) as common.UIAbilityContext
context.startAbility({
bundleName: "com.example.myapplication",
abilityName: "CallerAbility",
}).catch((err: Error) => {
console.log(err.message)
})
})
}.width('100%').margin({ top: 5 })
}
}
CustomDialogExample.ets
import common from '@ohos.app.ability.common';
import router from '@ohos.router';
@CustomDialog
@Preview
export struct CustomDialogExample {
@State dialogHeight: number = 0
controller?: CustomDialogController
initOffsetY: number = 0;
datas: Array<number> = [1, 2]
initHeight: number = 60 * this.datas.length + 90
topBorderRadius: number = 20;
closeFlag: boolean = false;
open = () => {
this.moveTo(this.initHeight)
}
close = () => {
this.moveTo(0).then(() => {
this.controller?.close()
})
}
moveTo = (height: number) => {
return new Promise<void>((res) => {
animateTo({ curve: Curve.Ease, onFinish: res, duration: 300 }, () => {
this.dialogHeight = height
})
})
}
// 阻尼函数
damping(x: number, max: number) {
let y = Math.abs(x);
y = 0.82231 * max / (1 + 4338.47 / Math.pow(y, 1.14791));
return Math.round(x < 0 ? -y : y);
}
build() {
Column() {
Column() {
Column() {
Row() {
Text('Title')
}
.width('100%')
.height(30)
.justifyContent(FlexAlign.Center)
Scroll() {
Column() {
ForEach(this.datas, () => {
Column() {
Image($r('app.media.startIcon'))
.width(50)
.height(50)
}
.onClick(()=>{
// let context = getContext(this) as common.UIAbilityContext
// context.startAbility({
// bundleName: "com.example.myapplication",
// abilityName: "CallerAbility",
// }).catch((err: Error) => {
// console.log(err.message)
// })
router.pushUrl({
url:'pages/Index'
})
})
.width('100%')
.margin({ top: 10 })
.justifyContent(FlexAlign.Center)
})
}
}
}
.layoutWeight(1)
Row() {
Button('取消')
.onClick(() => {
this.close()
}).width('100%').backgroundColor(0xffffff).fontColor(Color.Black)
}
.backgroundColor(Color.Red)
.width('100%')
.height(50)
}
.justifyContent(FlexAlign.SpaceBetween)
.height(this.dialogHeight)
.width('100%')
.backgroundColor(Color.White)
.onAppear(this.open)
.zIndex(2)
.borderRadius({ topLeft: this.topBorderRadius, topRight: this.topBorderRadius })
Column()
.width('100%')
.height('100%')
.backgroundColor(0x33000000)
.position({ x: 0, y: 0 })
.zIndex(1)
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.End)
// .borderRadius({ topLeft: 40, topRight: 40, bottomLeft: 0, bottomRight: 0 })
}
}
HarmonyOS
赞
收藏 0
回答 1
待解决
相关问题
customdialog在滑动后消失时,会出现一个向上的消失动效
397浏览 • 1回复 待解决
CustomDialog,Popup等弹窗如何与页面解耦
481浏览 • 1回复 待解决
customDialog焦点透传
327浏览 • 1回复 待解决
Web的桥方法的实现中,不能弹出CustomDialog
422浏览 • 1回复 待解决
CustomDialog如何实现半模态详情页效果
497浏览 • 1回复 待解决
router 传参,传递对象后,在新打开的页面中接收对象,对象的父类信息丢失,无法使用 instanceOf
571浏览 • 1回复 待解决
自定义弹窗CustomDialog的maskRect属性中x,y是否支持calc
738浏览 • 1回复 待解决
自定义弹窗CustomDialog的maskRect属性设置问题
268浏览 • 1回复 待解决
看文档有个AlertDialog,但如果想自定义是不是要使用CustomDialog,但customDialog不能单独存在
517浏览 • 1回复 待解决
点击弹出来的CustomDialog的Mask区域时,如何将焦点传递给Dialog下面的页面
688浏览 • 1回复 待解决
在Web组件的H5页面中,如何使用a标签实现打开各种页面
620浏览 • 1回复 待解决
自定义弹窗(CustomDialog)是否具备拦截用户返回操作的能力
443浏览 • 1回复 待解决
自定义弹窗(CustomDialog)能否全局拉起,像AlertDialog等,而不需要挂载在某个struct下面
523浏览 • 1回复 待解决
类似CallStateObserver中的回调,是在app主线程,还新的线程中?
4027浏览 • 1回复 待解决
在MongoDB中如何创建一个新的数据库?
2422浏览 • 1回复 待解决
LocalStorageLink修饰的变量会自动保存
524浏览 • 1回复 待解决
在什么情况下,PolarDB会自动启动并行查询框架?
1788浏览 • 1回复 待解决
在entry中打开feature中的一个ability,报错,页面展示出来了,但其并不是加载在feature的ability上
483浏览 • 1回复 待解决
CustomDialog上面有一个textInput,点击对话框被顶出屏幕
524浏览 • 1回复 待解决
自动播放通话录音,下拉通知栏即可关闭(消失)!
7537浏览 • 1回复 待解决
【ets】switch开关打开后会自动关闭
2152浏览 • 1回复 待解决
弹窗跳转到页面后返回弹窗不消失
433浏览 • 1回复 待解决
在元服务开发过程中,使用Web组件打开H5页面.打开后一直循环(begin&end)
547浏览 • 1回复 待解决
如何实现从页面弹窗跳转到其他页面后返回弹窗不消失
393浏览 • 1回复 待解决
通过使用Stack替代CustomDialog,再控制Stack的显隐即可达到效果。