HarmonyOS基本UI封装——顶部Toast、骨架屏(六)

1,000 阅读2分钟

前言

文章系列

简介

鸿蒙基本库封装,提升鸿蒙开发效率

安装

ohpm install @peakmain/library

一、NavBar扩展

背景
  • 因有大哥希望导航栏支持两个按钮,于是我这边对NavBar进行了扩展

image.png

导入依赖
import NavBar from "@peakmain/library/src/main/ets/components/title/NavBar"
参数
  • 新增leftClick和showLeftClose两个参数
参数名参数类型描述
titlestring设置导航栏标题
titleBoldboolean标题是否加粗,true表示加粗,false表示不加粗。默认是true
titleColorResourceColor设置标题字体颜色,默认字体颜色是 #272a2b
backgroundColorResourceResourceColor设置背景颜色,默认背景颜色是 Color.White
leftImagePixelMap | ResourceStr | DrawableDescriptor | null设置左边返回箭头资源,为空时不显示
rightstring右边文本内容
rightImagePixelMap | ResourceStr | DrawableDescriptor | null设置右边图片资源,为空时不显示
rightClick() => void设置右边图片或者文本的点击事件
leftClickvoid = ()左边返回点击事件,默认处理是返回上一个页面
showLeftCloseboolean是否显示关闭按钮,默认为false

二、顶部Toast

Toast提示工具.gif

导入依赖
import { ToastComponent } from "@peakmain/library"
参数
参数名参数类型名称
contentstringToast提示的文案
typeToastTypeToast提示的类型,不同类型提示的背景颜色不同
默认时间ToastType.Normal
durationnumber动画加载时长

ToastType枚举类型

枚举类型背景颜色说明
NORMAL#272a2b默认情况
SUCCESS#579572成功
ERROR#9F4B48错误
示例代码

CustomDialogController仅在作为@CustomDialog和@Component struct的成员变量,且在@Component struct内部定义时赋值才有效

  • 声明需要显示内容的CustomDialogController
  dialogController: CustomDialogController = new CustomDialogController({
  builder: ToastComponent({
    content: this.toastStatus == 0 ? "默认情况" : (this.toastStatus == 1 ? "正确情况" : "错误情况"),
    type: this.toastStatus == 0 ? ToastType.NORMAL : (this.toastStatus == 1 ? ToastType.SUCCESS : ToastType.ERROR),
  }),
  customStyle: true,
  alignment: DialogAlignment.Top,
  autoCancel: false
})

  • 需要显示的地方直接调用open即可
 this.dialogController.open()

三、Skeleton骨架屏

Skeleton骨架屏.gif

导入依赖
import {  PkSkeleton } from '@peakmain/library';
参数
参数名参数类型名称
showAvatarboolean是否显示头像,默认不显示
countnumber骨架屏显示数量,默认是3
示例代码
PkSkeleton({
  count: 3,
  showAvatar: this.showAvatar
})