Skip to content

TDButtonBottomTabBar: onTap 支持重复点击 #586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 11, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

Widget _allowMultipleTaps(BuildContext context) {
return TDBottomTabBar(TDBottomTabBarBasicType.text, useVerticalDivider: false, navigationTabs: [
TDBottomTabBarTabConfig(
allowMultipleTaps: true,
tabText: '支持重复点击',
onTap: () {
onTapTab(context, '标签1');
},
),
TDBottomTabBarTabConfig(
tabText: '不支持重复点击',
onTap: () {
onTapTab(context, '标签2');
},
),
]);
}
22 changes: 21 additions & 1 deletion tdesign-component/example/lib/page/td_bottom_tab_bar_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ class _TDBottomTabBarPageState extends State<TDBottomTabBarPage> {
desc: 'icon默认大小底部文字不溢出',
builder: (context) {
return CodeWrapper(builder: _iconTextTypeTabBarOverflow);
})
}),
ExampleItem(desc: 'onTap支持重复触发', builder: _allowMultipleTaps),
],
);
}
Expand Down Expand Up @@ -1061,4 +1062,23 @@ class _TDBottomTabBarPageState extends State<TDBottomTabBarPage> {
),
);
}

@Demo(group: 'bottomTabBar')
Widget _allowMultipleTaps(BuildContext context) {
return TDBottomTabBar(TDBottomTabBarBasicType.text, useVerticalDivider: false, navigationTabs: [
TDBottomTabBarTabConfig(
allowMultipleTaps: true,
tabText: '支持重复点击',
onTap: () {
onTapTab(context, '标签1');
},
),
TDBottomTabBarTabConfig(
tabText: '不支持重复点击',
onTap: () {
onTapTab(context, '标签2');
},
),
]);
}
}
29 changes: 17 additions & 12 deletions tdesign-component/lib/src/components/tabbar/td_bottom_tab_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ class BadgeConfig {

/// 单个tab配置
class TDBottomTabBarTabConfig {
TDBottomTabBarTabConfig(
{required this.onTap,
this.selectedIcon,
this.unselectedIcon,
this.tabText,
this.selectTabTextStyle,
this.unselectTabTextStyle,
this.badgeConfig,
this.popUpButtonConfig,
this.onLongPress})
: assert(() {
TDBottomTabBarTabConfig({
required this.onTap,
this.selectedIcon,
this.unselectedIcon,
this.tabText,
this.selectTabTextStyle,
this.unselectTabTextStyle,
this.badgeConfig,
this.popUpButtonConfig,
this.allowMultipleTaps = false
}) : assert(() {
if (badgeConfig?.showBadge ?? false) {
if (badgeConfig?.tdBadge == null) {
throw FlutterError('[NavigationTab] if set showBadge = true, '
Expand Down Expand Up @@ -121,6 +121,9 @@ class TDBottomTabBarTabConfig {
/// 弹窗配置
final TDBottomTabBarPopUpBtnConfig? popUpButtonConfig;

/// onTap方法允许点击多次
final bool allowMultipleTaps;

/// 长按事件
final GestureLongPressCallback? onLongPress;
}
Expand Down Expand Up @@ -311,7 +314,9 @@ class _TDBottomTabBarState extends State<TDBottomTabBar> {

void _onTap(int index) {
setState(() {
widget.navigationTabs[index].onTap?.call();
if (_selectedIndex != index || widget.navigationTabs[index].allowMultipleTaps) {
widget.navigationTabs[index].onTap?.call();
}
if (_selectedIndex != index) {
_selectedIndex = index;
}
Expand Down