Skip to content

fix(tab-bar): fallback safe-area inset for HarmonyOS#4304

Open
Darley-Wey wants to merge 3 commits intoTencent:developfrom
Darley-Wey:fix/tabbar-safe-area-fallback-4299
Open

fix(tab-bar): fallback safe-area inset for HarmonyOS#4304
Darley-Wey wants to merge 3 commits intoTencent:developfrom
Darley-Wey:fix/tabbar-safe-area-fallback-4299

Conversation

@Darley-Wey
Copy link

Summary

  • Read bottom safe area from systemInfo and cache it as safeAreaBottomHeight in TabBar.
  • Inject --safe-area-inset-bottom in tab-bar.wxml, falling back to env(safe-area-inset-bottom) when value is 0.
  • Replace env(safe-area-inset-bottom) usage in tab-bar.less with var(--safe-area-inset-bottom).
  • Closes [TabBar] safe-area-inset-bottom在鸿蒙系统skyline环境无效 #4299.

Test plan

  • Build component dist and verify no compile errors.
  • Open TabBar examples in _example and verify layout on normal devices.
  • Verify HarmonyOS Skyline device/emulator applies bottom safe-area spacing correctly.

🤖 Generated with Claude Code

Read window safe area and expose a css var fallback for env in TabBar.
This keeps bottom inset working on HarmonyOS Skyline devices. Closes Tencent#4299.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 3, 2026 16:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves TabBar safe-area handling on HarmonyOS (Skyline) by computing a bottom inset from runtime system info, exposing it to styles via a CSS custom property, and routing existing safe-area CSS to use that custom property.

Changes:

  • Compute and cache safeAreaBottomHeight in TabBar using systemInfo.safeArea.
  • Inject --safe-area-inset-bottom into the TabBar root inline style, with a fallback to env(safe-area-inset-bottom).
  • Update TabBar LESS to use var(--safe-area-inset-bottom) instead of env(safe-area-inset-bottom).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/components/tab-bar/tab-bar.wxml Injects a CSS custom property for bottom safe-area inset with an env() fallback.
packages/components/tab-bar/tab-bar.ts Adds safe-area bottom inset calculation and stores it in component data.
packages/components/tab-bar/tab-bar.less Switches safe-area spacing usage to var(--safe-area-inset-bottom).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +57 to +64
setSafeAreaBottomHeight() {
if (!this.properties.safeAreaInsetBottom) return;

wx.nextTick(() => {
const { screenHeight, safeArea } = systemInfo;
const safeAreaBottomHeight = screenHeight - (safeArea?.bottom ?? screenHeight);
this.setData({ safeAreaBottomHeight: Math.max(0, safeAreaBottomHeight) });
});
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new safe-area fallback logic (setSafeAreaBottomHeight + CSS variable injection) isn't covered by existing TabBar tests. Since this affects layout across platforms (including the HarmonyOS regression), please add a unit/snapshot test that verifies the rendered style includes --safe-area-inset-bottom and that it uses the pixel value when systemInfo.safeArea.bottom implies a non-zero inset (and falls back to env(safe-area-inset-bottom) when the computed value is 0).

Copilot uses AI. Check for mistakes.
/>
<view
style="{{_._style(['z-index: ' + zIndex, style, customStyle])}}"
style="{{_._style(['z-index: ' + zIndex, style, customStyle, '--safe-area-inset-bottom: ' + (safeAreaBottomHeight ? safeAreaBottomHeight + 'px' : 'env(safe-area-inset-bottom)')])}}"
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

customStyle is no longer the last entry in the _._style([...]) list, so any user-provided customStyle can no longer reliably override the injected --safe-area-inset-bottom value. Most components keep customStyle last to preserve override precedence (e.g. packages/components/sticky/sticky.wxml:5, packages/components/overlay/overlay.wxml:6). Consider moving the injected CSS variable earlier in the array (e.g. after z-index and before style/customStyle) so customStyle remains last.

Suggested change
style="{{_._style(['z-index: ' + zIndex, style, customStyle, '--safe-area-inset-bottom: ' + (safeAreaBottomHeight ? safeAreaBottomHeight + 'px' : 'env(safe-area-inset-bottom)')])}}"
style="{{_._style(['z-index: ' + zIndex, style, '--safe-area-inset-bottom: ' + (safeAreaBottomHeight ? safeAreaBottomHeight + 'px' : 'env(safe-area-inset-bottom)'), customStyle])}}"

Copilot uses AI. Check for mistakes.
Move the injected --safe-area-inset-bottom style before style/customStyle
so customStyle remains last in _._style and can still override values.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 4, 2026

Open in StackBlitz

npm i https://pkg.pr.new/tdesign-miniprogram@4304
npm i https://pkg.pr.new/@tdesign/uniapp@4304
npm i https://pkg.pr.new/@tdesign/uniapp-chat@4304

commit: 5ffbd41

@tdesign-bot
Copy link
Collaborator

tdesign-bot commented Mar 4, 2026

TDesign Component Site Preview Open

Component Preview
tdesign-miniprogram 完成
@tdesign-miniprogram/chat 完成
tdesign-uniapp 完成
tdesign-uniapp-chat 完成

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TabBar] safe-area-inset-bottom在鸿蒙系统skyline环境无效

3 participants