| 123456789101112131415161718192021222324252627282930313233 |
- const useCustomNavbarBehavior = Behavior({
- properties: {
- usingCustomNavbar: {
- type: Boolean,
- value: false,
- },
- customNavbarHeight: {
- type: Number,
- value: 0,
- },
- },
- data: {
- distanceTop: 0,
- },
- lifetimes: {
- attached() {
- if (this.properties.usingCustomNavbar) {
- this.calculateCustomNavbarDistanceTop();
- }
- },
- },
- methods: {
- calculateCustomNavbarDistanceTop() {
- const { statusBarHeight } = wx.getSystemInfoSync();
- const menuButton = wx.getMenuButtonBoundingClientRect();
- const distance = menuButton.top + menuButton.bottom - statusBarHeight;
- this.setData({
- distanceTop: Math.max(distance, this.properties.customNavbarHeight + statusBarHeight),
- });
- },
- },
- });
- export default useCustomNavbarBehavior;
|