You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

checkIPhoneX.js 951B

1 年之前
12345678910111213141516171819202122232425262728293031323334353637
  1. // 获取系统信息
  2. let systemInfo = null
  3. // iPhoneX 竖屏安全区域
  4. let safeAreaInset = {
  5. top: 88, // StatusBar & NavBar
  6. left: 0,
  7. right: 0,
  8. bottom: 34, // Home Indicator
  9. }
  10. const getSystemInfo = (isForce) => {
  11. if (!systemInfo || isForce) {
  12. try {
  13. systemInfo = wx.getSystemInfoSync()
  14. } catch(e) { /* Ignore */ }
  15. try {
  16. safeAreaInset.top = systemInfo.statusBarHeight + systemInfo.safeArea.top
  17. safeAreaInset.bottom = systemInfo.screenHeight - systemInfo.safeArea.bottom
  18. } catch(e) { /* Ignore */ }
  19. }
  20. return systemInfo
  21. }
  22. const isIPhoneX = ({ model, windowHeight, windowWidth }) => {
  23. return /iphone (x|12|13)/.test(model.toLowerCase()) || (windowHeight >= 812 && windowHeight / windowWidth > 2)
  24. }
  25. const checkIPhoneX = (isForce) => isIPhoneX(getSystemInfo(isForce))
  26. checkIPhoneX()
  27. export {
  28. safeAreaInset,
  29. getSystemInfo,
  30. checkIPhoneX,
  31. }