iphonex.js 867 B

1234567891011121314151617181920212223242526272829303132
  1. let isIPhoneX = null;
  2. function getIsIPhoneX() {
  3. return new Promise((resolve, reject) => {
  4. if (isIPhoneX !== null) {
  5. resolve(isIPhoneX);
  6. }
  7. else {
  8. wx.getSystemInfo({
  9. success: ({ model, screenHeight }) => {
  10. const iphoneX = /iphone x/i.test(model);
  11. const iphoneNew = /iPhone11/i.test(model) && screenHeight === 812;
  12. isIPhoneX = iphoneX || iphoneNew;
  13. resolve(isIPhoneX);
  14. },
  15. fail: reject
  16. });
  17. }
  18. });
  19. }
  20. export const iphonex = Behavior({
  21. properties: {
  22. safeAreaInsetBottom: {
  23. type: Boolean,
  24. value: true
  25. }
  26. },
  27. created() {
  28. getIsIPhoneX().then(isIPhoneX => {
  29. this.set({ isIPhoneX });
  30. });
  31. }
  32. });