Skip to content

Commit c444e34

Browse files
klopez4212wesbillmanPinkyBrain
authored
Mobile tab bar polish (#1368)
Signed-off-by: Wes <[email protected]> Signed-off-by: Wes <[email protected]> Co-authored-by: Wes <[email protected]> Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Wes <[email protected]> Co-authored-by: Brain <21994759fc7a6fa6b965551d35cfd7897d262f2495467f2d78694ddcfa6a5c7e@sprout-oss.stage.blox.sqprod.co>
1 parent f86f97b commit c444e34

1 file changed

Lines changed: 81 additions & 29 deletions

File tree

‎mobile/lib/features/home/home_page.dart‎

Lines changed: 81 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,24 @@ class HomePage extends HookConsumerWidget {
1919
static const double _selectedTabRadius =
2020
(_tabBarHeight - (_tabBarInnerInset * 2)) / 2;
2121
static const double _tabBarBottomGap = Grid.twelve;
22-
static const double _tabBarHorizontalMargin = Grid.sm;
22+
static const double _tabBarHorizontalMargin = Grid.gutter;
2323
static const double _fabClearance = _tabBarHeight + _tabBarBottomGap;
24+
static const Duration _tabIconWeightDuration = Duration(milliseconds: 120);
2425

2526
static const _destinations = [
2627
_HomeDestination(
27-
icon: LucideIcons.house,
28-
selectedIcon: LucideIcons.house,
28+
icon: LucideIcons.house300,
29+
selectedIcon: LucideIcons.house500,
2930
label: 'Home',
3031
),
3132
_HomeDestination(
32-
icon: LucideIcons.bell,
33-
selectedIcon: LucideIcons.bell,
33+
icon: LucideIcons.bell300,
34+
selectedIcon: LucideIcons.bell400,
3435
label: 'Activity',
3536
),
3637
_HomeDestination(
37-
icon: LucideIcons.search,
38-
selectedIcon: LucideIcons.search,
38+
icon: LucideIcons.search300,
39+
selectedIcon: LucideIcons.search500,
3940
label: 'Search',
4041
),
4142
];
@@ -106,6 +107,18 @@ class _FloatingTabBar extends StatelessWidget {
106107
Widget build(BuildContext context) {
107108
final colorScheme = context.colors;
108109
final isDark = context.theme.brightness == Brightness.dark;
110+
final reducedMotion = MediaQuery.of(context).disableAnimations;
111+
if (destinations.isEmpty) {
112+
return const SizedBox.shrink();
113+
}
114+
final destinationCount = destinations.length;
115+
final safeSelectedIndex = selectedIndex
116+
.clamp(0, destinationCount - 1)
117+
.toInt();
118+
final selectedAlignment = destinationCount <= 1
119+
? Alignment.center
120+
: Alignment(-1 + (2 * safeSelectedIndex / (destinationCount - 1)), 0);
121+
109122
return SafeArea(
110123
minimum: const EdgeInsets.fromLTRB(
111124
HomePage._tabBarHorizontalMargin,
@@ -115,8 +128,8 @@ class _FloatingTabBar extends StatelessWidget {
115128
),
116129
child: Align(
117130
alignment: Alignment.bottomCenter,
118-
child: ConstrainedBox(
119-
constraints: const BoxConstraints(maxWidth: 336),
131+
child: SizedBox(
132+
width: double.infinity,
120133
child: DecoratedBox(
121134
decoration: BoxDecoration(
122135
borderRadius: BorderRadius.circular(HomePage._tabBarRadius),
@@ -183,16 +196,44 @@ class _FloatingTabBar extends StatelessWidget {
183196
height:
184197
HomePage._tabBarHeight -
185198
(HomePage._tabBarInnerInset * 2),
186-
child: Row(
199+
child: Stack(
187200
children: [
188-
for (var i = 0; i < destinations.length; i++)
189-
Expanded(
190-
child: _FloatingTabDestination(
191-
destination: destinations[i],
192-
selected: i == selectedIndex,
193-
onTap: () => onDestinationSelected(i),
201+
AnimatedAlign(
202+
alignment: selectedAlignment,
203+
duration: reducedMotion
204+
? Duration.zero
205+
: const Duration(milliseconds: 180),
206+
curve: Curves.easeOutCubic,
207+
child: FractionallySizedBox(
208+
widthFactor: 1 / destinationCount,
209+
heightFactor: 1,
210+
child: Padding(
211+
padding: const EdgeInsets.symmetric(
212+
horizontal: Grid.quarter,
213+
),
214+
child: DecoratedBox(
215+
decoration: BoxDecoration(
216+
color: colorScheme.secondaryContainer,
217+
borderRadius: BorderRadius.circular(
218+
HomePage._selectedTabRadius,
219+
),
220+
),
221+
),
194222
),
195223
),
224+
),
225+
Row(
226+
children: [
227+
for (var i = 0; i < destinations.length; i++)
228+
Expanded(
229+
child: _FloatingTabDestination(
230+
destination: destinations[i],
231+
selected: i == selectedIndex,
232+
onTap: () => onDestinationSelected(i),
233+
),
234+
),
235+
],
236+
),
196237
],
197238
),
198239
),
@@ -224,24 +265,24 @@ class _FloatingTabDestination extends StatelessWidget {
224265
Widget build(BuildContext context) {
225266
final colorScheme = context.colors;
226267
final textStyle = context.textTheme.labelSmall;
268+
final reducedMotion = MediaQuery.of(context).disableAnimations;
227269
final foregroundColor = selected
228-
? colorScheme.onPrimary
270+
? colorScheme.onSecondaryContainer
229271
: colorScheme.onSurfaceVariant;
272+
final icon = selected ? destination.selectedIcon : destination.icon;
230273

231274
return Padding(
232275
padding: const EdgeInsets.symmetric(horizontal: Grid.quarter),
233276
child: Material(
234-
color: selected
235-
? colorScheme.primary.withValues(alpha: 0.94)
236-
: Colors.transparent,
277+
color: Colors.transparent,
237278
borderRadius: BorderRadius.circular(HomePage._selectedTabRadius),
238279
clipBehavior: Clip.antiAlias,
239280
child: InkWell(
240281
onTap: onTap,
282+
splashFactory: NoSplash.splashFactory,
283+
overlayColor: const WidgetStatePropertyAll<Color>(Colors.transparent),
241284
borderRadius: BorderRadius.circular(HomePage._selectedTabRadius),
242-
child: AnimatedContainer(
243-
duration: const Duration(milliseconds: 180),
244-
curve: Curves.easeOutCubic,
285+
child: Padding(
245286
padding: const EdgeInsets.symmetric(
246287
horizontal: Grid.xxs,
247288
vertical: Grid.xxs,
@@ -250,10 +291,20 @@ class _FloatingTabDestination extends StatelessWidget {
250291
mainAxisAlignment: MainAxisAlignment.center,
251292
mainAxisSize: MainAxisSize.min,
252293
children: [
253-
Icon(
254-
selected ? destination.selectedIcon : destination.icon,
255-
color: foregroundColor,
256-
size: 20,
294+
AnimatedSwitcher(
295+
duration: reducedMotion
296+
? Duration.zero
297+
: HomePage._tabIconWeightDuration,
298+
switchInCurve: Curves.easeOutCubic,
299+
switchOutCurve: Curves.easeOutCubic,
300+
transitionBuilder: (child, animation) =>
301+
FadeTransition(opacity: animation, child: child),
302+
child: Icon(
303+
icon,
304+
key: ValueKey('${destination.label}-$icon'),
305+
color: foregroundColor,
306+
size: 20,
307+
),
257308
),
258309
const SizedBox(height: 1),
259310
Text(
@@ -263,8 +314,9 @@ class _FloatingTabDestination extends StatelessWidget {
263314
style: textStyle?.copyWith(
264315
color: foregroundColor,
265316
fontSize: 10.5,
266-
fontWeight: selected ? FontWeight.w700 : FontWeight.w600,
267-
letterSpacing: 0.05,
317+
fontWeight: selected ? FontWeight.w700 : FontWeight.w400,
318+
height: 1.15,
319+
letterSpacing: 0,
268320
),
269321
),
270322
],

0 commit comments

Comments
 (0)