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
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.
The index of the selected tab in ShellGraph.tabs.
The stack of the selected tab, its root first.
Whether the top of the shell, pages excluded, is a child rather than a tab root.
The outer stack: ShellHomeRoute, or a start page, followed by every open page.
Functions
Closes every page, showing the shell.
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.
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.