Skip to content

feat(tab-bar): add liquid glass effect - #2276

Open
ChenXiaoming233 wants to merge 2 commits into
Tencent:developfrom
ChenXiaoming233:feat/tab-bar-liquid-glass
Open

feat(tab-bar): add liquid glass effect#2276
ChenXiaoming233 wants to merge 2 commits into
Tencent:developfrom
ChenXiaoming233:feat/tab-bar-liquid-glass

Conversation

@ChenXiaoming233

@ChenXiaoming233 ChenXiaoming233 commented Jul 28, 2026

Copy link
Copy Markdown

TabBar 的主题 Token、组件样式及相关设计文档统一维护在 tdesign-common 中,tdesign-mobile-vue 通过 src/_common 子模块复用这些共享资源,以保持样式来源唯一、避免重复维护。

本 PR 依赖的 Liquid Glass 与 Capsule 样式由 Tencent/tdesign-common#2650 提供。此前 src/_common 指向仅存在于本地对象库的 ecff38ac,导致 CI 无法递归检出子模块。现将 src/_common 更新至 Tencent/tdesign-common#2650 的 head commit 26fb5344,令子模块可访问;待 #2650 合并后, _common 再更新至最终进入 tdesign-common/develop 的正式提交。

🤔 这个 PR 的性质是?

  • 日常 bug 修复
  • 新特性提交
  • 文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • CI/CD 改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他

🔗 相关 Issue

关联 PR

💡 需求背景和解决方案

为 TabBar 接入渐进增强的 Liquid Glass 材质,并提供独立的共享胶囊选中主题。

公开 API

<t-tab-bar effect="glass" shape="round" theme="capsule">
  ...
</t-tab-bar>

最终 API 实现与用法

interface TdTabBarProps {
  bordered?: boolean; // default: true
  effect?: 'normal' | 'glass'; // default: normal
  fixed?: boolean; // default: true
  placeholder?: boolean; // default: false
  safeAreaInsetBottom?: boolean; // default: true
  shape?: 'normal' | 'round'; // default: normal
  split?: boolean; // default: true
  theme?: 'normal' | 'tag' | 'capsule'; // default: normal
  value?: string | number | Array<string | number>;
  defaultValue?: string | number | Array<string | number>;
  modelValue?: string | number | Array<string | number>;
  zIndex?: number; // default: 1
  onChange?: (value: string | number) => void;
}

主要改动

  • 新增 Liquid Glass API

    • src/tab-bar/type.ts:新增 effect?: 'normal' | 'glass',并为 theme 增加 capsule
    • src/tab-bar/props.ts:补充默认值和枚举校验;默认 effect="normal",保持兼容。
  • TabBar 渲染玻璃材质与共享胶囊

    • src/tab-bar/tab-bar.tsx
      • Glass 模式增加 Material Base、Refraction、Surface Sheen 和实例级 SVG Filter。
      • shape="round" + theme="capsule" 时渲染共享移动选中胶囊。
      • 普通模式不生成 Glass DOM,避免额外运行时开销。
  • TabBarItem 交互适配

    • src/tab-bar/tab-bar-item.tsx
      • Capsule 模式增加 pointer 按压、长按、释放和取消反馈。
      • prefers-reduced-motion 下取消缩放和移动动画。
  • 实现折射纹理生成

    • src/tab-bar/liquid-glass-map.ts
      • 根据组件尺寸、圆角和 DPR 生成超椭圆位移图与高光图。
      • DPR 上限为 2,单张纹理上限为 524,288 像素。
      • 输出确定、无持续动画或后台计算。
  • 管理滤镜生命周期

    • src/tab-bar/useTabBarGlassFilter.ts
      • 管理 Canvas 编码、SVG Filter ID、ResizeObserver 和 DPR 变化。
      • 支持多实例、运行时 effect/shape 切换和卸载清理。
      • SSR 或浏览器能力不足时自动使用 CSS fallback。
  • 新增公开 Demo 与文档

    • src/tab-bar/demos/glass.vue:展示 Classic tag 和 Shared capsule 两种 Glass 组合。
    • src/tab-bar/demos/mobile.vue:将 Glass 示例接入组件 Demo。
    • src/tab-bar/tab-bar.mdtab-bar.en-US.md:补充 API 和降级说明。

液态玻璃 CSS 变量

style/mobile/components/tab-bar/_var.less

@tab-bar-glass-bg-color:玻璃基础背景色,支持明暗主题动态覆盖
@tab-bar-glass-shadow:玻璃外部阴影,用于表现悬浮高度
@tab-bar-glass-fallback-blur:CSS 降级模糊基准值,默认 8px
@tab-bar-glass-sheen-opacity:玻璃表面高光透明度
@tab-bar-selected-bg-color:选中胶囊的背景颜色
@tab-bar-selected-bg-opacity:选中背景透明度,默认 16%
@tab-bar-selected-sheen-opacity:选中胶囊表面高光透明度
@tab-bar-selected-border-color:普通胶囊选中态的边框颜色

效果图 与 Playground:

在此提供了 Classic 与 Capsule 两种主题分别处于 Normal / CSS Fallback / LiquidGlass 在深浅模式下的效果图;

同时,为能更直观地观察参数调整对 Glass 材质视觉效果带来的影响,此处提供两个 Playground 用于实践:

效果图:

IMG_20260729_005432 IMG_20260729_005455

Playground:

1Capture_2026-07-29_00 51 17@2x 1Capture_2026-07-29_00 51 56@2x

📝 更新日志

  • feat(TabBar): 新增 Liquid Glass 材质和共享胶囊选中主题
  • 本条 PR 不需要纳入 Changelog

☑️ 本地验证

  • TabBar 目标测试 50/50
  • 全量单元测试 786/786
  • Demo 快照 408/408
  • Lint 和 TypeScript 检查
  • 生产构建
  • 子模块完整性检查
  • git diff --check
  • 远程 CI,等待 PR 创建后执行

☑️ 请求合并前的自查清单

  • 文档已补充
  • 代码演示已提供
  • TypeScript 定义已补充
  • Changelog 已提供

- add the public effect="glass" API and the capsule theme
- render layered glass materials and a shared selection indicator while preserving existing TabBar behavior
- generate superellipse displacement and specular textures for lifecycle-managed SVG filters
- provide a readable CSS fallback for unsupported browsers, SSR, Canvas failures, and runtime capability changes
- synchronize pointer press feedback across the capsule, icons, and labels
- support multiple instances, runtime effect switching, resource cleanup, and reduced-motion preferences
- add the Liquid Glass demo, documentation, runtime tests, interaction tests, and displacement coverage
- exclude demos and tests from production builds and verify the shared common submodule integrity

feat(tab-bar): 实现液态玻璃效果与胶囊主题

- 新增公开的 effect="glass" API 和 capsule 主题
- 渲染分层玻璃材质与共享选中指示器,同时保持现有 TabBar 行为不变
- 生成超椭圆位移与高光纹理,并管理 SVG Filter 的完整生命周期
- 为不支持的浏览器、SSR、Canvas 失败和运行时能力变化提供可读的 CSS 降级效果
- 为胶囊、图标和文字提供同步的指针按压反馈
- 支持多实例、运行时效果切换、资源清理和 reduced-motion 偏好
- 补充 Liquid Glass 示例、组件文档、运行时测试、交互测试和位移效果测试
- 从生产构建中排除 Demo 与测试文件,并校验 common 子模块完整性
@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

完成

@pkg-pr-new

pkg-pr-new Bot commented Jul 29, 2026

Copy link
Copy Markdown

commit: 1e6b51d

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants