Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/components/tab-bar/tab-bar.less
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

&--normal&--safe {
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
padding-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom));
}

&--round {
Expand All @@ -41,6 +41,6 @@

&--fixed&--round&--safe {
bottom: constant(safe-area-inset-bottom);
bottom: env(safe-area-inset-bottom);
bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom));
}
}
24 changes: 24 additions & 0 deletions packages/components/tab-bar/tab-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export default class Tabbar extends SuperComponent {
prefix,
classPrefix,
placeholderHeight: 56,
safeAreaBottomHeight: 0,
safeAreaBottomReady: false,
};

properties = props;
Expand All @@ -54,15 +56,37 @@ export default class Tabbar extends SuperComponent {
'fixed, placeholder, shape, safeAreaInsetBottom'() {
this.setPlaceholderHeight();
},
safeAreaInsetBottom() {
this.setSafeAreaBottomHeight();
},
};

lifetimes = {
ready() {
this.showChildren();
this.setSafeAreaBottomHeight();
},
};

methods = {
setSafeAreaBottomHeight() {
if (!this.properties.safeAreaInsetBottom) {
// 关闭时清空,避免残留值影响样式
if (this.data.safeAreaBottomReady || this.data.safeAreaBottomHeight !== 0) {
this.setData({ safeAreaBottomHeight: 0, safeAreaBottomReady: false });
}
return;
}

wx.nextTick(() => {
const safeAreaBottomHeight = getSafeAreaBottom();
this.setData({ safeAreaBottomHeight, safeAreaBottomReady: true }, () => {
// safeArea 注入后,placeholder 占位高度可能依赖它,再触发一次重算
this.setPlaceholderHeight();
});
});
Comment thread
anlyyao marked this conversation as resolved.
},

setPlaceholderHeight() {
if (!this.properties.fixed || !this.properties.placeholder) return;

Expand Down
2 changes: 1 addition & 1 deletion packages/components/tab-bar/tab-bar.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
style="height: {{ placeholderHeight }}px;"
/>
<view
style="{{_._style(['z-index: ' + zIndex, style, customStyle])}}"
style="{{_._style(['z-index: ' + zIndex, safeAreaBottomReady ? '--safe-area-inset-bottom: ' + safeAreaBottomHeight + 'px' : '', style, customStyle])}}"
class="{{_.cls(classPrefix, [['border', bordered], ['fixed', fixed], ['safe', safeAreaInsetBottom], shape])}} class {{prefix}}-class"
aria-role="tablist"
>
Expand Down
6 changes: 6 additions & 0 deletions packages/tdesign-miniprogram/.changelog/pr-4304.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
pr_number: 4304
contributor: Darley-Wey
---

- fix(tab-bar): HarmonyOS 的安全区域内边距 @Darley-Wey ([#4304](https://github.com/Tencent/tdesign-miniprogram/pull/4304))
4 changes: 2 additions & 2 deletions packages/uniapp-components/tab-bar/tab-bar.less
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

&--normal&--safe {
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
padding-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom));
}

&--round {
Expand All @@ -41,6 +41,6 @@

&--fixed&--round&--safe {
bottom: constant(safe-area-inset-bottom);
bottom: env(safe-area-inset-bottom);
bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom));
}
}
28 changes: 27 additions & 1 deletion packages/uniapp-components/tab-bar/tab-bar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
:style="'height: ' + placeholderHeight + 'px;'"
/>
<view
:style="'' + tools._style(['z-index: ' + zIndex, customStyle])"
:style="
'' +
tools._style([
'z-index: ' + zIndex,
safeAreaBottomReady ? '--safe-area-inset-bottom: ' + safeAreaBottomHeight + 'px' : '',
customStyle,
])
"
:class="
'' +
tools.cls(classPrefix, [['border', bordered], ['fixed', fixed], ['safe', safeAreaInsetBottom], shape]) +
Expand Down Expand Up @@ -74,6 +81,8 @@ export default {

dataValue: coalesce(this.value, this.defaultValue),
placeholderHeight: 56,
safeAreaBottomHeight: 0,
safeAreaBottomReady: false,
};
},
watch: {
Expand All @@ -99,14 +108,31 @@ export default {
this.setPlaceholderHeight();
},
safeAreaInsetBottom() {
this.setSafeAreaBottomHeight();
this.setPlaceholderHeight();
},
},
mounted() {
this.setSafeAreaBottomHeight();
this.setPlaceholderHeight();
this.showChildren();
},
methods: {
setSafeAreaBottomHeight() {
if (!this.safeAreaInsetBottom) {
if (this.safeAreaBottomReady || this.safeAreaBottomHeight !== 0) {
this.safeAreaBottomHeight = 0;
this.safeAreaBottomReady = false;
}
return;
}
nextTick().then(() => {
this.safeAreaBottomHeight = getSafeAreaBottom();
this.safeAreaBottomReady = true;
// safeArea 注入后 placeholder 高度可能需要重算
this.setPlaceholderHeight();
});
},
setPlaceholderHeight() {
if (!this.fixed || !this.placeholder) {
return;
Expand Down