Tab Bar
Switch between your app's top-level screens from a row of icon-and-label tabs along the bottom of the screen, as most mobile apps do.
Installation
This also adds Icon, whose icons and theme colors the tabs draw with.
Usage
Give each tab a route, an icon and a label, and put the bar under a <lynx-tab-outlet>, which keeps each tab as a native tab bar does:
- A tap navigates to the tab's
route, with Angular's ownRouterLink. Set up the router withprovideRouter()from@blotch/angular-lynx. - The tab of the current route is selected: its icon and label take the theme's
primarycolor, and the others itsmuted-foreground. - A tab stays selected on the routes under it. The Inbox tab at
/inboxis still selected at/inbox/42. - A tab shows selected as soon as it's tapped, before the screen it shows has been built, so a tab that takes a moment to build doesn't look like a missed tap. If the navigation ends somewhere else (a guard says no or redirects, or it fails), the tab of the route the app is on is selected again.
- Going back to a tab finds it as you left it, with
<lynx-tab-outlet>: its scroll positions, the screens pushed in it, and its native views. A tap on the selected tab pops its stack to its first screen. With<router-outlet>, each tab is built again every time. - The tabs share the bar's width equally, and the bar pads itself by the bottom safe area, so the tabs sit above the iPhone's home indicator.
- The icon is any Icon name, or your own mark.
Give each routed screen's host flex-1 so it fills the space above the bar, or its <scroll-view> grows to fit its content instead of scrolling:
Away on a pushed screen
Give a tab a <lynx-stack-outlet>, and a screen it pushes over the tab's first screen takes the bar away, as iOS's hidesBottomBarWhenPushed and Material's navigation bar do. The example's Inbox is one: open a message.
- While it's away, the bar lies over the bottom of the screen rather than under the outlet, so the pushed screen runs to the bottom edge.
- Where screens move as iOS's do, the screen underneath carries the bar: it moves a little left with that screen, and the pushed screen slides over it, rounded corner and shadow and all.
- Where they move as Android's do, it slides down off the screen.
- Back, Android's back button or a swipe brings it back, following the finger while it drags. While it's away, screen readers skip it and it takes no taps.
A route keeps the bar with data: { bottomBar: 'visible' }. See LynxStackChrome for what the stack says, and LynxStackBottomBar for how a screen carries the bar.
Badges
[badge] shows a count or a short text over the tab's icon, such as unread messages:
A count of 0, an empty string, null or undefined shows no badge, so bind the count as it is.
Your own mark
For a mark the icon set doesn't have, such as your app's logo on the Home tab, pass its markup to svg instead of icon:
currentColortakes the tab's color, as the set's icons do:primarywhile it's selected andmuted-foregroundotherwise. A one-color mark written incurrentColorfollows the selection and your theme.- Colors written out stay, so a multi-color mark keeps them.
xmlnsis optional, and lines must be<path>s, as for an icon's own SVG.
A tab for the root route
Every route starts with /, so a tab for / would stay selected everywhere. Match it exactly:
Router options
The item takes RouterLink's inputs, which work as on the web: queryParams, queryParamsHandling, fragment, preserveFragment, state, info, relativeTo, replaceUrl and skipLocationChange.
- Each tap adds a history entry, as any
RouterLinkdoes, so Android's back button walks back through the tabs. SetreplaceUrlto replace the entry instead. - A relative
routeresolves from the component the bar is in. A bar inside a routed screen can switch its child routes withroute="feed".
React to a tap
(pressed) emits on every tap, including one on the tab that's already selected, where the route doesn't change. Native apps scroll the screen back to the top then:
Dark mode
The icons draw with the light theme's colors until you say otherwise, as every icon does. If your app switches to dark mode, set the icons' color scheme with provideIconTheme().
API
UiTabBar
UiTabBarItem
Accessibility
- Each tab is one button, named by its
labeland then its badge: "Inbox, 3". - The selected tab has the
selectedtrait, from the tap, as it shows, so iOS VoiceOver announces it as selected. Android has no selected trait, so TalkBack doesn't say which tab is selected. - On iOS, the bar has the
tabbartrait, as a native tab bar does, which tells VoiceOver that its buttons are tabs. - Away on a pushed screen, the bar is hidden from screen readers and takes no taps.
Related
- Routing and navigation: set up the router and its routes
- Safe area: the inset the bar pads for
- Dock: the same navigation as a floating Liquid Glass bar
- Tabs: switch panels within one screen instead of routed screens
- Nav Drawer: a side menu, for more destinations than a tab bar fits
- Icon: the icons a tab can show, and how to write your own mark
