CustomToast.ets
960 Bytes
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
@CustomDialog
export struct CustomToast {
public static LENGTH_LONG = 5000;
public static LENGTH_SHORT = 3000;
@State msg: string = ""
@State duration: number = CustomToast.LENGTH_SHORT
@State bgBorderRadius: number = 10
controller: CustomDialogController
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("27lpx")
.lineHeight("38lpx")
}.borderRadius(`${this.bgBorderRadius}lpx`)
.constraintSize({maxWidth:"86%"})
.padding({top:"23lpx",bottom:'23lpx',left:"35lpx",right:"35lpx"})
.backgroundColor($r("app.color.black"))
.opacity(0.7)
}
}