封装windowManger

58 阅读1分钟
import { window } from '@kit.ArkUI'

export class windowManger {

  static async enableFullScreen() {
    const win = await window.getLastWindow(getContext())
    win.setWindowLayoutFullScreen(true)
  }

  static async disableFullScreen() {
    const win = await window.getLastWindow(getContext())
    win.setWindowLayoutFullScreen(false)
  }

  static async getAvoidAreaTop() {
    const win = await window.getLastWindow(getContext())
    const area = win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM)
    const topHeight = px2vp(area.topRect.height)
    AppStorage.setOrCreate('topHeight', topHeight)
    return topHeight
  }

  static async getAvoidAreaBottom() {
    const win = await window.getLastWindow(getContext())
    const area = win.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR)
    const bottomHeight = px2vp(area.bottomRect.height)
    AppStorage.setOrCreate('bottomHeight', bottomHeight)
    return bottomHeight
  }
  
  static async settingStatusBarContentColor(color:'#FFFFFF') {
    const win = await window.getLastWindow(getContext())
    win.setWindowSystemBarProperties({ statusBarContentColor: color })
  }
}