Skip to content

Commit a465684

Browse files
committed
fix(ohos): 悬浮底栏被拉满整屏宽
1 parent 9d87b97 commit a465684

1 file changed

Lines changed: 29 additions & 13 deletions

File tree

‎lib/pages/main/view.dart‎

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -360,19 +360,35 @@ class _MainAppState extends PopScopeState<MainApp>
360360
return null;
361361
}
362362
if (_mainController.floatingNavBar) {
363-
bottomNav = Obx(
364-
() => FloatingNavigationBar(
365-
onDestinationSelected: _mainController.setIndex,
366-
selectedIndex: _mainController.selectedIndex.value,
367-
destinations: _mainController.navigationBars
368-
.map(
369-
(e) => FloatingNavigationDestination(
370-
label: e.label,
371-
icon: _buildIcon(type: e),
372-
selectedIcon: _buildIcon(type: e, selected: true),
373-
),
374-
)
375-
.toList(),
363+
// 悬浮底栏必须拿到「松」的宽度约束才能保持自身 destinations.length * 86 的
364+
// 宽度。上游从 `e89241109 opt ui` 起把主页换成了自绘的 MainLayout,那里给
365+
// bottomNav 的是 constraints.loosen() 再手动水平居中;鸿蒙没跟进这个骨架
366+
// 重构(状态栏取色依赖 Scaffold 里那个零高 AppBar,换掉代价太大),而
367+
// Scaffold.bottomNavigationBar 下发的是 fullWidthConstraints —— 宽度是紧
368+
// 约束(material/scaffold.dart:1035 `looseConstraints.tighten(width:)`),
369+
// FloatingNavigationBar 内部的 SizedBox 会被 enforce 成整屏宽。
370+
//
371+
// 这里用 Align 吃掉紧宽度:Align 自己撑满宽度,子节点拿到松约束、按自身
372+
// 宽度水平居中;heightFactor: 1 让高度仍按子节点算,Scaffold 据此计算的
373+
// body 内边距与改动前一致。两侧空白区域 Align 不参与命中测试,点击会穿透
374+
// 到下面的内容,与上游 MainLayout 的表现一致。
375+
bottomNav = Align(
376+
alignment: Alignment.bottomCenter,
377+
heightFactor: 1,
378+
child: Obx(
379+
() => FloatingNavigationBar(
380+
onDestinationSelected: _mainController.setIndex,
381+
selectedIndex: _mainController.selectedIndex.value,
382+
destinations: _mainController.navigationBars
383+
.map(
384+
(e) => FloatingNavigationDestination(
385+
label: e.label,
386+
icon: _buildIcon(type: e),
387+
selectedIcon: _buildIcon(type: e, selected: true),
388+
),
389+
)
390+
.toList(),
391+
),
376392
),
377393
);
378394
} else if (_mainController.enableMYBar) {

0 commit comments

Comments
 (0)