checkIPhoneX.js 638 B

123456789101112131415161718192021222324252627282930
  1. /**
  2. * 获取系统信息
  3. */
  4. let systemInfo = null
  5. const getSystemInfo = (isForce) => {
  6. if (!systemInfo || isForce) {
  7. try {
  8. systemInfo = wx.getSystemInfoSync()
  9. } catch(e) { /* Ignore */ }
  10. }
  11. return systemInfo
  12. }
  13. // iPhoneX 竖屏安全区域
  14. export const safeAreaInset = {
  15. top: 88, // StatusBar & NavBar
  16. left: 0,
  17. right: 0,
  18. bottom: 34, // Home Indicator
  19. }
  20. const IPHONEX_DEVICE_HEIGHT = 812
  21. const isIPhoneX = ({ model, platform, screenHeight }) => {
  22. return /iPhone X/.test(model) && platform === 'ios' && screenHeight === IPHONEX_DEVICE_HEIGHT
  23. }
  24. export const checkIPhoneX = (isForce) => isIPhoneX(getSystemInfo(isForce))