HarmonyOS基本UI封裝——頂部Toast、骨架屏(六)

前言

文章系列

簡介

鴻蒙基本庫封裝,提升鴻蒙開發(fā)效率

安裝

ohpm install @peakmain/library

一、NavBar擴展

背景
  • 因有大哥希望導(dǎo)航欄支持兩個按鈕,于是我這邊對NavBar進行了擴展

[圖片上傳失敗...(image-50f619-1729820549472)]

導(dǎo)入依賴
import NavBar from "@peakmain/library/src/main/ets/components/title/NavBar"
參數(shù)
  • 新增leftClick和showLeftClose兩個參數(shù)
參數(shù)名 參數(shù)類型 描述
title string 設(shè)置導(dǎo)航欄標題
titleBold boolean 標題是否加粗,true表示加粗,false表示不加粗。默認是true
titleColor ResourceColor 設(shè)置標題字體顏色,默認字體顏色是 #272a2b
backgroundColorResource ResourceColor 設(shè)置背景顏色,默認背景顏色是 Color.White
leftImage PixelMap | ResourceStr | DrawableDescriptor | null 設(shè)置左邊返回箭頭資源,為空時不顯示
right string 右邊文本內(nèi)容
rightImage PixelMap | ResourceStr | DrawableDescriptor | null 設(shè)置右邊圖片資源,為空時不顯示
rightClick () => void 設(shè)置右邊圖片或者文本的點擊事件
leftClick void = () 左邊返回點擊事件,默認處理是返回上一個頁面
showLeftClose boolean 是否顯示關(guān)閉按鈕,默認為false

二、頂部Toast

[圖片上傳失敗...(image-8cac9-1729820549473)]

導(dǎo)入依賴
import { ToastComponent } from "@peakmain/library"
參數(shù)
參數(shù)名 參數(shù)類型 名稱
content string Toast提示的文案
type ToastType Toast提示的類型,不同類型提示的背景顏色不同
默認時間ToastType.Normal
duration number 動畫加載時長

ToastType枚舉類型

枚舉類型 背景顏色 說明
NORMAL #272a2b 默認情況
SUCCESS #579572 成功
ERROR #9F4B48 錯誤
示例代碼

CustomDialogController僅在作為@CustomDialog和@Component struct的成員變量,且在@Component struct內(nèi)部定義時賦值才有效

  • 聲明需要顯示內(nèi)容的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
})

  • 需要顯示的地方直接調(diào)用open即可
 this.dialogController.open()

三、Skeleton骨架屏

Skeleton骨架屏.gif
導(dǎo)入依賴
import {  PkSkeleton } from '@peakmain/library';
參數(shù)
參數(shù)名 參數(shù)類型 名稱
showAvatar boolean 是否顯示頭像,默認不顯示
count number 骨架屏顯示數(shù)量,默認是3
示例代碼
PkSkeleton({
  count: 3,
  showAvatar: this.showAvatar
})
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容