Skip to content

Commit 2520880

Browse files
author
MritunjayTiwari14
committed
home: Add icons label on main navigation bar.
Labeled the Navigation Bar for each Icon by zulip_localizations, nav bar touch logic changed from IconButton to GestureDetector to improve performace. Fixes: #1857
1 parent 6adc9c3 commit 2520880

File tree

3 files changed

+64
-23
lines changed

3 files changed

+64
-23
lines changed

assets/l10n/app_en.arb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,18 @@
12311231
"@wildcardMentionTopicDescription": {
12321232
"description": "Description for \"@topic\" wildcard-mention autocomplete options when writing a channel message."
12331233
},
1234+
"navBarFeedLabel": "Combined feed",
1235+
"@navBarFeedLabel": {
1236+
"description": "Label for the Feed button on the bottom navigation bar."
1237+
},
1238+
"navBarDmLabel": "DMs",
1239+
"@navBarDmLabel": {
1240+
"description": "Label for the Direct Messages button on the bottom navigation bar."
1241+
},
1242+
"navBarMenuLabel": "Menu",
1243+
"@navBarMenuLabel": {
1244+
"description": "Label for the Menu button on the bottom navigation bar."
1245+
},
12341246
"messageIsEditedLabel": "EDITED",
12351247
"@messageIsEditedLabel": {
12361248
"description": "Label for an edited message. (Use ALL CAPS for cased alphabets: Latin, Greek, Cyrillic, etc.)"

lib/widgets/home.dart

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -86,35 +86,43 @@ class _HomePageState extends State<HomePage> {
8686

8787
@override
8888
Widget build(BuildContext context) {
89+
final zulipLocalizations = ZulipLocalizations.of(context);
90+
8991
const pageBodies = [
9092
(_HomePageTab.inbox, InboxPageBody()),
9193
(_HomePageTab.channels, SubscriptionListPageBody()),
9294
// TODO(#1094): Users
9395
(_HomePageTab.directMessages, RecentDmConversationsPageBody()),
9496
];
9597

96-
_NavigationBarButton button(_HomePageTab tab, IconData icon) {
98+
_NavigationBarButton button(_HomePageTab tab, IconData icon, String label) {
9799
return _NavigationBarButton(icon: icon,
98100
selected: _tab.value == tab,
99101
onPressed: () {
100102
_tab.value = tab;
101-
});
103+
},
104+
label: label);
102105
}
103106

104107
// TODO(a11y): add tooltips for these buttons
105108
final navigationBarButtons = [
106-
button(_HomePageTab.inbox, ZulipIcons.inbox),
109+
button(_HomePageTab.inbox, ZulipIcons.inbox,
110+
zulipLocalizations.inboxPageTitle),
107111
_NavigationBarButton( icon: ZulipIcons.message_feed,
108112
selected: false,
109113
onPressed: () => Navigator.push(context,
110114
MessageListPage.buildRoute(context: context,
111-
narrow: const CombinedFeedNarrow()))),
112-
button(_HomePageTab.channels, ZulipIcons.hash_italic),
115+
narrow: const CombinedFeedNarrow())),
116+
label: zulipLocalizations.navBarFeedLabel),
117+
button(_HomePageTab.channels, ZulipIcons.hash_italic,
118+
zulipLocalizations.channelsPageTitle),
113119
// TODO(#1094): Users
114-
button(_HomePageTab.directMessages, ZulipIcons.two_person),
120+
button(_HomePageTab.directMessages, ZulipIcons.two_person,
121+
zulipLocalizations.navBarDmLabel),
115122
_NavigationBarButton( icon: ZulipIcons.menu,
116123
selected: false,
117-
onPressed: () => _showMainMenu(context, tabNotifier: _tab)),
124+
onPressed: () => _showMainMenu(context, tabNotifier: _tab),
125+
label: zulipLocalizations.navBarMenuLabel),
118126
];
119127

120128
final designVariables = DesignVariables.of(context);
@@ -134,7 +142,8 @@ class _HomePageState extends State<HomePage> {
134142
border: Border(top: BorderSide(color: designVariables.borderBar)),
135143
color: designVariables.bgBotBar),
136144
child: SafeArea(
137-
child: SizedBox(height: 48,
145+
child: SizedBox(
146+
height: 62,
138147
child: Center(
139148
child: ConstrainedBox(
140149
// TODO(design): determine a suitable max width for bottom nav bar
@@ -231,35 +240,46 @@ class _NavigationBarButton extends StatelessWidget {
231240
required this.icon,
232241
required this.selected,
233242
required this.onPressed,
243+
required this.label,
234244
});
235245

236246
final IconData icon;
237247
final bool selected;
238248
final void Function() onPressed;
249+
final String label;
239250

240251
@override
241252
Widget build(BuildContext context) {
242253
final designVariables = DesignVariables.of(context);
243254

244-
final iconColor = WidgetStateColor.fromMap({
245-
WidgetState.pressed: designVariables.iconSelected,
246-
~WidgetState.pressed: selected ? designVariables.iconSelected
247-
: designVariables.icon,
248-
});
255+
final color = selected ? designVariables.iconSelected : designVariables.icon;
249256

250257
return AnimatedScaleOnTap(
251258
scaleEnd: 0.875,
252259
duration: const Duration(milliseconds: 100),
253-
child: IconButton(
254-
icon: Icon(icon, size: 24),
255-
onPressed: onPressed,
256-
style: IconButton.styleFrom(
257-
// TODO(#417): Disable splash effects for all buttons globally.
258-
splashFactory: NoSplash.splashFactory,
259-
highlightColor: designVariables.navigationButtonBg,
260-
shape: const RoundedRectangleBorder(
261-
borderRadius: BorderRadius.all(Radius.circular(4))),
262-
).copyWith(foregroundColor: iconColor)));
260+
child: GestureDetector(
261+
behavior: HitTestBehavior.opaque,
262+
onTap: onPressed,
263+
child: Column(
264+
children: [
265+
SizedBox(
266+
height: 34,
267+
child: Center(
268+
child: Icon(icon, size: 24, color: color,)),
269+
),
270+
Expanded(
271+
child: Text(
272+
label,
273+
style: TextStyle(
274+
fontSize: 12,
275+
color: color,
276+
height: 1.0,),
277+
textAlign: TextAlign.center,
278+
maxLines: 2,
279+
overflow: TextOverflow.ellipsis),
280+
)
281+
]),
282+
));
263283
}
264284
}
265285

test/widgets/home_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,27 @@ void main () {
117117
check(find.descendant(
118118
of: find.byType(ZulipAppBar),
119119
matching: find.text('Inbox'))).findsOne();
120+
check(find.descendant(
121+
of: find.byType(ZulipAppBar),
122+
matching: find.bySemanticsLabel(RegExp("Inbox")))).findsOne();
120123

121124
await tester.tap(find.byIcon(ZulipIcons.hash_italic));
122125
await tester.pump();
123126
check(find.descendant(
124127
of: find.byType(ZulipAppBar),
125128
matching: find.text('Channels'))).findsOne();
129+
check(find.descendant(
130+
of: find.byType(ZulipAppBar),
131+
matching: find.bySemanticsLabel(RegExp("Channels")))).findsOne();
126132

127133
await tester.tap(find.byIcon(ZulipIcons.two_person));
128134
await tester.pump();
129135
check(find.descendant(
130136
of: find.byType(ZulipAppBar),
131137
matching: find.text('Direct messages'))).findsOne();
138+
check(find.descendant(
139+
of: find.byType(ZulipAppBar),
140+
matching: find.bySemanticsLabel(RegExp("Direct messages")))).findsOne();
132141
});
133142

134143
testWidgets('combined feed', (tester) async {

0 commit comments

Comments
 (0)