system.js 3.0 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1
import {
fxy060608's avatar
fxy060608 已提交
2
  callApiSync,
fxy060608's avatar
fxy060608 已提交
3
  isTabBarPage,
Q
qiang 已提交
4 5 6
  getLastWebview,
  getStatusbarHeight,
  getScreenInfo
fxy060608's avatar
fxy060608 已提交
7 8 9 10 11 12
} from '../util'

import {
  TITLEBAR_HEIGHT
} from '../../constants'

fxy060608's avatar
fxy060608 已提交
13
import tabBar from '../../framework/tab-bar'
fxy060608's avatar
fxy060608 已提交
14

fxy060608's avatar
fxy060608 已提交
15
export function getSystemInfoSync () {
fxy060608's avatar
fxy060608 已提交
16 17
  return callApiSync(getSystemInfo, Object.create(null), 'getSystemInfo', 'getSystemInfoSync')
}
fxy060608's avatar
fxy060608 已提交
18 19

export function getSystemInfo () {
fxy060608's avatar
fxy060608 已提交
20 21
  const platform = plus.os.name.toLowerCase()
  const ios = platform === 'ios'
Q
qiang 已提交
22 23 24 25 26 27 28 29 30 31
  const {
    screenWidth,
    screenHeight
  } = getScreenInfo()
  const statusBarHeight = getStatusbarHeight()

  let safeAreaInsets
  const titleNView = {
    height: 0,
    cover: false
32
  }
Q
qiang 已提交
33
  const webview = getLastWebview()
fxy060608's avatar
fxy060608 已提交
34 35
  if (webview) {
    let style = webview.getStyle()
Q
qiang 已提交
36 37 38 39
    style = style && style.titleNView
    if (style && style.type && style.type !== 'none') {
      titleNView.height = style.type === 'transparent' ? 0 : (statusBarHeight + TITLEBAR_HEIGHT)
      titleNView.cover = style.type === 'transparent' || style.type === 'float'
fxy060608's avatar
fxy060608 已提交
40
    }
Q
qiang 已提交
41
    safeAreaInsets = webview.getSafeAreaInsets()
42
  } else {
Q
qiang 已提交
43
    safeAreaInsets = plus.navigator.getSafeAreaInsets()
44
  }
Q
qiang 已提交
45 46 47 48 49 50 51 52 53 54
  const tabBarView = {
    height: 0,
    cover: false
  }
  if (isTabBarPage()) {
    tabBarView.height = tabBar.visible ? tabBar.height : 0
    tabBarView.cover = tabBar.cover
  }
  const windowTop = titleNView.cover ? titleNView.height : 0
  const windowBottom = tabBarView.cover ? tabBarView.height : 0
55 56
  let windowHeight = screenHeight - titleNView.height - tabBarView.height
  let windowHeightReal = screenHeight - (titleNView.cover ? 0 : titleNView.height) - (tabBarView.cover ? 0 : tabBarView.height)
Q
qiang 已提交
57
  const windowWidth = screenWidth
58 59 60 61
  if ((!tabBarView.height || tabBarView.cover) && !safeAreaInsets.bottom && safeAreaInsets.deviceBottom) {
    windowHeight -= safeAreaInsets.deviceBottom
    windowHeightReal -= safeAreaInsets.deviceBottom
  }
Q
qiang 已提交
62 63 64 65 66 67 68
  safeAreaInsets = ios ? safeAreaInsets : {
    left: 0,
    right: 0,
    top: titleNView.height && !titleNView.cover ? 0 : statusBarHeight,
    bottom: 0
  }
  const safeArea = {
69 70 71
    left: safeAreaInsets.left,
    right: windowWidth - safeAreaInsets.right,
    top: safeAreaInsets.top,
Q
qiang 已提交
72
    bottom: windowHeightReal - safeAreaInsets.bottom,
73
    width: windowWidth - safeAreaInsets.left - safeAreaInsets.right,
Q
qiang 已提交
74
    height: windowHeightReal - safeAreaInsets.top - safeAreaInsets.bottom
fxy060608's avatar
fxy060608 已提交
75
  }
76

fxy060608's avatar
fxy060608 已提交
77 78
  return {
    errMsg: 'getSystemInfo:ok',
79
    brand: plus.device.vendor,
fxy060608's avatar
fxy060608 已提交
80 81 82 83
    model: plus.device.model,
    pixelRatio: plus.screen.scale,
    screenWidth,
    screenHeight,
84 85
    windowWidth,
    windowHeight,
fxy060608's avatar
fxy060608 已提交
86 87 88 89 90 91 92
    statusBarHeight,
    language: plus.os.language,
    system: plus.os.version,
    version: plus.runtime.innerVersion,
    fontSizeSetting: '',
    platform,
    SDKVersion: '',
Q
qiang 已提交
93
    windowTop,
Q
qiang 已提交
94
    windowBottom,
Q
qiang 已提交
95 96 97 98 99 100 101
    safeArea,
    safeAreaInsets: {
      top: safeAreaInsets.top,
      right: safeAreaInsets.right,
      bottom: safeAreaInsets.bottom,
      left: safeAreaInsets.left
    }
fxy060608's avatar
fxy060608 已提交
102
  }
103
}