CustomToast.ets 960 Bytes
@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)
  }
}