using-custom-navbar.js 991 B

12345678910111213141516171819202122232425262728293031323334
  1. import { systemInfo } from '../common/utils';
  2. const useCustomNavbarBehavior = Behavior({
  3. properties: {
  4. usingCustomNavbar: {
  5. type: Boolean,
  6. value: false,
  7. },
  8. customNavbarHeight: {
  9. type: Number,
  10. value: 0,
  11. },
  12. },
  13. data: {
  14. distanceTop: 0,
  15. },
  16. lifetimes: {
  17. attached() {
  18. if (this.properties.usingCustomNavbar) {
  19. this.calculateCustomNavbarDistanceTop();
  20. }
  21. },
  22. },
  23. methods: {
  24. calculateCustomNavbarDistanceTop() {
  25. const { statusBarHeight } = systemInfo;
  26. const menuButton = wx.getMenuButtonBoundingClientRect();
  27. const distance = menuButton.top + menuButton.bottom - statusBarHeight;
  28. this.setData({
  29. distanceTop: Math.max(distance, this.properties.customNavbarHeight + statusBarHeight),
  30. });
  31. },
  32. },
  33. });
  34. export default useCustomNavbarBehavior;