CustomToast.ets
1.24 KB
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
@CustomDialog
export struct CustomToast {
public static LENGTH_LONG = 4000;
public static LENGTH_SHORT = 2000;
@State msg: ResourceStr = ""
@State duration: number = CustomToast.LENGTH_SHORT
@State bgBorderRadius: number = 10
opacityValue: number = 0.7
bgColor: ResourceColor = $r("app.color.black")
fontSizeValue :number | string | Resource = 16
lineHeightValue :number | string | Resource = 20
controller: CustomDialogController
marginTop :number | string | Resource = 0
dismiss: () => void = () => {
}
aboutToAppear(): void {
let intervalID = setInterval(() => {
if (this.controller != undefined) {
this.controller.close()
this.dismiss()
clearInterval(intervalID);
}
}, this.duration);
}
build() {
Row() {
Text(this.msg)
.fontWeight(FontWeight.Regular)
.fontColor($r('app.color.white'))
.fontSize(this.fontSizeValue)
.lineHeight(this.lineHeightValue)
.textAlign(TextAlign.Center)
}.borderRadius(`${this.bgBorderRadius}`)
.constraintSize({maxWidth:"86%"})
.padding({top:12,bottom:12,left:16,right:16})
.backgroundColor(this.bgColor)
.opacity(this.opacityValue)
.margin({top:this.marginTop})
}
}