safe-area.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var cache = null;
  4. function getSafeArea() {
  5. return new Promise(function (resolve, reject) {
  6. if (cache != null) {
  7. resolve(cache);
  8. }
  9. else {
  10. wx.getSystemInfo({
  11. success: function (_a) {
  12. var model = _a.model, screenHeight = _a.screenHeight, statusBarHeight = _a.statusBarHeight;
  13. var iphoneX = /iphone x/i.test(model);
  14. var iphoneNew = /iPhone11/i.test(model) && screenHeight === 812;
  15. cache = {
  16. isIPhoneX: iphoneX || iphoneNew,
  17. statusBarHeight: statusBarHeight
  18. };
  19. resolve(cache);
  20. },
  21. fail: reject
  22. });
  23. }
  24. });
  25. }
  26. exports.safeArea = function (_a) {
  27. var _b = _a === void 0 ? {} : _a, _c = _b.safeAreaInsetBottom, safeAreaInsetBottom = _c === void 0 ? true : _c, _d = _b.safeAreaInsetTop, safeAreaInsetTop = _d === void 0 ? false : _d;
  28. return Behavior({
  29. properties: {
  30. safeAreaInsetTop: {
  31. type: Boolean,
  32. value: safeAreaInsetTop
  33. },
  34. safeAreaInsetBottom: {
  35. type: Boolean,
  36. value: safeAreaInsetBottom
  37. }
  38. },
  39. created: function () {
  40. var _this = this;
  41. getSafeArea().then(function (_a) {
  42. var isIPhoneX = _a.isIPhoneX, statusBarHeight = _a.statusBarHeight;
  43. _this.set({ isIPhoneX: isIPhoneX, statusBarHeight: statusBarHeight });
  44. });
  45. }
  46. });
  47. };