iphonex.js 871 B

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