| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import { window } from "@kit.ArkUI"
- export interface AvoidType {
- top?: number,
- bottom?: number
- }
- export class YTAvoid {
- /**
- * @type number
- * @description 顶部安全区高度
- */
- static readonly SAFE_TOP_KEY: string = 'safeTop'
- /**
- * @type number
- * @description 底部安全区高度
- */
- static readonly SAFE_BOTTOM_KEY: string = 'bottomTop'
- static setAvoid(avoid: AvoidType) {
- if (typeof avoid.top != 'undefined') {
- AppStorage.setOrCreate<number>(YTAvoid.SAFE_TOP_KEY, px2vp(avoid.top))
- }
- if (typeof avoid.bottom != 'undefined') {
- AppStorage.setOrCreate<number>(YTAvoid.SAFE_BOTTOM_KEY, px2vp(avoid.bottom))
- }
- }
- static getTop() {
- return AppStorage.get<number>(YTAvoid.SAFE_TOP_KEY)
- }
- static getBottom() {
- return AppStorage.get<number>(YTAvoid.SAFE_BOTTOM_KEY)
- }
- static setTop(safeTop: number) {
- AppStorage.setOrCreate<number>(YTAvoid.SAFE_TOP_KEY, safeTop)
- }
- static setBottom(safeBottom: number) {
- AppStorage.setOrCreate<number>(YTAvoid.SAFE_BOTTOM_KEY, safeBottom)
- }
- static setStatusBarContentColor(color: string, context: Context) {
- window.getLastWindow(context, (err, windowClass) => {
- if (!err) {
- windowClass.setWindowSystemBarProperties({ statusBarContentColor: color })
- } else {
- // YTLog.error(err)
- }
- })
- }
- }
|