Skip to content

Commit 7bad41b

Browse files
anlyyaotdesign-bot
andauthored
feat(Navbar): support isHiddenInSpecialScene props (#4509)
* feat(Navbar): support isHiddenInSpecialScene props * docs(Navbar): update api docs * docs(Navbar): update api docs again * chore: stash changelog [ci skip] --------- Co-authored-by: tdesign-bot <tdesign@tencent.com>
1 parent 084fa9c commit 7bad41b

11 files changed

Lines changed: 52 additions & 3 deletions

File tree

packages/components/navbar/README.en-US.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ background | String | - | `deprecated`。background | N
1313
delta | Number | 1 | \- | N
1414
fixed | Boolean | true | \- | N
1515
home-icon | String | - | `deprecated`。homeIcon | N
16+
is-hidden-in-special-scene | Boolean | false | `1.15.2` | N
1617
left-arrow | Boolean | false | `0.26.0` | N
1718
left-icon | String | - | `deprecated` | N
1819
placeholder | Boolean | false | `1.12.1` | N
1920
safe-area-inset-top | Boolean | true | \- | N
2021
title | String | - | page title | N
2122
title-max-length | Number | - | \- | N
2223
visible | Boolean | true | \- | N
23-
z-index | Number | 1 | \- | N
24+
z-index | Number | 1 | `1.12.1` | N
2425

2526
### Navbar Events
2627

packages/components/navbar/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@ background | String | - | 已废弃。背景 | N
6262
delta | Number | 1 | 后退按钮后退层数,含义参考 [wx.navigateBack](https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.navigateBack.html),特殊的,传入 0 不会发生执行 wx.navigateBack | N
6363
fixed | Boolean | true | 是否固定在顶部 | N
6464
home-icon | String | - | 已废弃。首页图标地址。值为 '' 或者 undefined 则表示不显示返回图标,值为 'circle' 表示显示默认图标,值为 'slot' 表示使用插槽渲染,值为其他则表示图标地址 | N
65+
is-hidden-in-special-scene | Boolean | false | `1.15.2`。【实验】是否销毁导航栏,仅场景值为 1433、1434、1177、1175 时有效 | N
6566
left-arrow | Boolean | false | `0.26.0`。是否展示左侧箭头 | N
6667
left-icon | String | - | 已废弃。左侧图标地址,值为 '' 或者 undefined 则表示不显示返回图标,值为 'arrow-left' 表示显示返回图标,值为 'slot' 表示使用插槽渲染,值为其他则表示图标地址 | N
6768
placeholder | Boolean | false | `1.12.1`。固定在顶部时是否开启占位 | N
6869
safe-area-inset-top | Boolean | true | 是否开启顶部安全区适配 | N
6970
title | String | - | 页面标题 | N
7071
title-max-length | Number | - | 标题文字最大长度,超出的范围使用 `...` 表示 | N
7172
visible | Boolean | true | 是否显示 | N
72-
z-index | Number | 1 | 导航条层级 | N
73+
z-index | Number | 1 | `1.12.1`导航条层级 | N
7374

7475
### Navbar Events
7576

packages/components/navbar/navbar.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ import props from './props';
66
const { prefix } = config;
77
const name = `${prefix}-navbar`;
88

9+
// 这些场景下 wx.getMenuButtonBoundingClientRect 不可用或取值不可靠,需跳过调用
10+
// 1433(半屏小程序)、1434(半屏小程序-从聊天素材打开)、1177(视频号直播间)、1175(视频号profile页)
11+
const SKIP_MENU_RECT_SCENES = [1433, 1434, 1177, 1175];
12+
13+
/** 判断当前是否处于特殊场景(半屏、视频号等) */
14+
const checkSpecialScene = (): boolean => {
15+
const { scene } = wx.getLaunchOptionsSync();
16+
return SKIP_MENU_RECT_SCENES.includes(scene);
17+
};
18+
919
@wxComponent()
1020
export default class Navbar extends SuperComponent {
1121
externalClasses = [
@@ -66,12 +76,19 @@ export default class Navbar extends SuperComponent {
6676
showTitle: '',
6777
hideLeft: false, // 隐藏左侧内容
6878
hideCenter: false, // 隐藏中部内容
79+
isSpecialScene: false, // 是否处于特殊场景
6980
_menuRect: null, // 胶囊按钮节点信息
7081
_leftRect: null, // 左侧节点信息
7182
_boxStyle: {}, // 记录样式
7283
};
7384

7485
attached() {
86+
const isSpecialScene = checkSpecialScene();
87+
88+
if (isSpecialScene) {
89+
this.setData({ isSpecialScene });
90+
}
91+
7592
this.initStyle();
7693
this.getLeftRect();
7794
this.onMenuButtonBoundingClientRectWeightChange();
@@ -133,7 +150,8 @@ export default class Navbar extends SuperComponent {
133150
},
134151

135152
getMenuRect() {
136-
// 场景值为1177(视频号直播间)和1175 (视频号profile页)时,小程序禁用了 wx.getMenuButtonBoundingClientRect
153+
if (this.data.isSpecialScene) return;
154+
137155
if (wx.getMenuButtonBoundingClientRect) {
138156
const rect = wx.getMenuButtonBoundingClientRect();
139157
this.setData({

packages/components/navbar/navbar.wxml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<wxs src="../common/utils.wxs" module="_" />
22
<view
3+
wx:if="{{!(isSpecialScene && isHiddenInSpecialScene)}}"
34
class="{{_.cls(classPrefix, [['fixed', fixed]])}} {{visibleClass}} class {{prefix}}-class"
45
style="{{_._style([boxStyle, style, customStyle])}}"
56
>

packages/components/navbar/props.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ const props: TdNavbarProps = {
2121
type: Boolean,
2222
value: true,
2323
},
24+
/** 【实验】是否销毁导航栏,仅场景值为 1433、1434、1177、1175 时有效 */
25+
isHiddenInSpecialScene: {
26+
type: Boolean,
27+
value: false,
28+
},
2429
/** 是否展示左侧箭头 */
2530
leftArrow: {
2631
type: Boolean,

packages/components/navbar/type.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ export interface TdNavbarProps {
2929
type: BooleanConstructor;
3030
value?: boolean;
3131
};
32+
/**
33+
* 【实验】是否销毁导航栏,仅场景值为 1433、1434、1177、1175 时有效
34+
* @default false
35+
*/
36+
isHiddenInSpecialScene?: {
37+
type: BooleanConstructor;
38+
value?: boolean;
39+
};
3240
/**
3341
* 是否展示左侧箭头
3442
* @default false
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
pr_number: 4509
3+
contributor: anlyyao
4+
---
5+
6+
- feat(Navbar): 新增 `isHiddenInSpecialScene` 属性,表示是否销毁导航栏,仅场景值为 1433、1434、1177、1175 时有效 @anlyyao ([#4509](https://github.com/Tencent/tdesign-miniprogram/pull/4509))

packages/uniapp-components/navbar/README.en-US.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ background | String | - | `deprecated`。background | N
1212
delta | Number | 1 | \- | N
1313
fixed | Boolean | true | \- | N
1414
home-icon | String | - | `deprecated`。homeIcon | N
15+
is-hidden-in-special-scene | Boolean | false | \- | N
1516
left-arrow | Boolean | false | \- | N
1617
left-icon | String | - | `deprecated` | N
1718
placeholder | Boolean | false | \- | N

packages/uniapp-components/navbar/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ background | String | - | 已废弃。背景 | N
5959
delta | Number | 1 | 后退按钮后退层数,含义参考 [wx.navigateBack](https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.navigateBack.html),特殊的,传入 0 不会发生执行 wx.navigateBack | N
6060
fixed | Boolean | true | 是否固定在顶部 | N
6161
home-icon | String | - | 已废弃。首页图标地址。值为 '' 或者 undefined 则表示不显示返回图标,值为 'circle' 表示显示默认图标,值为 'slot' 表示使用插槽渲染,值为其他则表示图标地址 | N
62+
is-hidden-in-special-scene | Boolean | false | 【实验】是否销毁导航栏,仅场景值为 1433、1434、1177、1175 时有效 | N
6263
left-arrow | Boolean | false | 是否展示左侧箭头 | N
6364
left-icon | String | - | 已废弃。左侧图标地址,值为 '' 或者 undefined 则表示不显示返回图标,值为 'arrow-left' 表示显示返回图标,值为 'slot' 表示使用插槽渲染,值为其他则表示图标地址 | N
6465
placeholder | Boolean | false | 固定在顶部时是否开启占位 | N

packages/uniapp-components/navbar/props.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export default {
2020
type: Boolean,
2121
default: true,
2222
},
23+
/** 【实验】是否销毁导航栏,仅场景值为 1433、1434、1177、1175 时有效 */
24+
isHiddenInSpecialScene: Boolean,
2325
/** 是否展示左侧箭头 */
2426
leftArrow: Boolean,
2527
/** 固定在顶部时是否开启占位 */

0 commit comments

Comments
 (0)