YTAvoid.ets 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { window } from "@kit.ArkUI"
  2. export interface AvoidType {
  3. top?: number,
  4. bottom?: number
  5. }
  6. export class YTAvoid {
  7. /**
  8. * @type number
  9. * @description 顶部安全区高度
  10. */
  11. static readonly SAFE_TOP_KEY: string = 'safeTop'
  12. /**
  13. * @type number
  14. * @description 底部安全区高度
  15. */
  16. static readonly SAFE_BOTTOM_KEY: string = 'bottomTop'
  17. static setAvoid(avoid: AvoidType) {
  18. if (typeof avoid.top != 'undefined') {
  19. AppStorage.setOrCreate<number>(YTAvoid.SAFE_TOP_KEY, px2vp(avoid.top))
  20. }
  21. if (typeof avoid.bottom != 'undefined') {
  22. AppStorage.setOrCreate<number>(YTAvoid.SAFE_BOTTOM_KEY, px2vp(avoid.bottom))
  23. }
  24. }
  25. static getTop() {
  26. return AppStorage.get<number>(YTAvoid.SAFE_TOP_KEY)
  27. }
  28. static getBottom() {
  29. return AppStorage.get<number>(YTAvoid.SAFE_BOTTOM_KEY)
  30. }
  31. static setTop(safeTop: number) {
  32. AppStorage.setOrCreate<number>(YTAvoid.SAFE_TOP_KEY, safeTop)
  33. }
  34. static setBottom(safeBottom: number) {
  35. AppStorage.setOrCreate<number>(YTAvoid.SAFE_BOTTOM_KEY, safeBottom)
  36. }
  37. static setStatusBarContentColor(color: string, context: Context) {
  38. window.getLastWindow(context, (err, windowClass) => {
  39. if (!err) {
  40. windowClass.setWindowSystemBarProperties({ statusBarContentColor: color })
  41. } else {
  42. // YTLog.error(err)
  43. }
  44. })
  45. }
  46. }