ShellNavigator

The shell's navigation state and the only way screens move through it.

There is one outer stack, pages, whose bottom is ShellHomeRoute, the shell, and one inner stack per tab. Every tab keeps its own stack while another is selected, so returning to a tab finds it where it was left.

An app can instead start on a screen of its own, a start page such as a welcome or sign-in screen: the outer stack then begins with that page and no shell under it, so back from it leaves the app. Navigating to a tab or a child, or enterShell, replaces it with the shell.

Screens call navigate with any registered key and the navigator decides where it goes from the key's DestinationKind: tabs are selected, children are pushed on the current tab, pages are pushed on the outer stack. Back follows one order everywhere, gesture or button: close the top page, then the top child of the current tab, then return to the tab visited before, then leave the app from the first tab.

Tabs are remembered in the order they were visited, each once, like a back stack of tabs: Apps, Games, Search, Apps goes back to Search, then Games, then Apps. Revisiting a tab moves it to the top, the first tab included. The app is always left from the first tab: when the history runs out on another tab, back returns to the first before it leaves.

The per-tab stacks and the "exit through the first tab" rule are adapted from the multiple back stacks recipe in android/nav3-recipes, Apache License 2.0. The tab history, outer page stack, destination kinds and single-detail rule are the shell's.

Properties

Link copied to clipboard

The destination on top: the top page, or, with the shell on top, the current tab's top screen. What a person is looking at, for analytics and the like.

Link copied to clipboard
Link copied to clipboard

The index of the selected tab in ShellGraph.tabs.

Link copied to clipboard

The stack of the selected tab, its root first.

Link copied to clipboard

Whether the shell is on the outer stack, rather than a start page in its place.

Link copied to clipboard

Whether the top of the shell, pages excluded, is a child rather than a tab root.

Link copied to clipboard

The outer stack: ShellHomeRoute, or a start page, followed by every open page.

Link copied to clipboard

The tabs whose stacks the inner display holds, in the order back will return through them, the selected one last: the history, with the first tab under it when it is not in it, since back ends there.

Functions

Link copied to clipboard
fun close(key: NavKey)

Closes the page key and every page opened above it. A list page uses this for its back button, so the detail open beside it closes with it. Closing the start page, the bottom of the stack when no shell is under it, leaves the app, as back does.

Link copied to clipboard

Closes every page, showing the shell.

Link copied to clipboard

Replaces the start screen, and any page open over it, with next, another start screen: a welcome that hands over to a permission request, then to onboarding. Back from next leaves the app, as from the first. Once the shell is showing, it opens next as a page.

Link copied to clipboard

Shows the shell, closing every page, and replacing a start page with the shell for good: a start screen calls this, or navigates to a tab, when it is done.

Link copied to clipboard
fun goBack()

Back, from an app bar or any button. Leaves the app once there is nothing left to close.

Link copied to clipboard
fun navigate(key: NavKey)

Opens a registered destination according to its kind. Navigating to another detail replaces the current detail so one Back returns to the list.

Link copied to clipboard

Closes the top page. False when only the shell is left. The outer display calls it on back.

Link copied to clipboard

Pops the current tab's top child, or returns from a tab's root to the tab visited before it. False when the first tab's root is showing. The inner display calls it on back.

Link copied to clipboard
fun selectTab(index: Int)

Selects index, moving it to the top of the tab history, or returns an already selected tab to its root.

Link copied to clipboard
fun tabStack(index: Int): List<NavKey>
Link copied to clipboard
fun timesOpened(index: Int): Int

How many times tab index has been picked from another tab. Back to a tab does not count, so a screen can tell being opened again from being returned to.