Stack Outlet
The router outlet that keeps a stack of screens and moves between them as native apps do, with a swipe back. import { LynxStackOutlet, type StackNavigationInfo, LynxStackPage, LynxStackChrome, LynxStackBottomBar } from '@blotch/angular-lynx';
Usage
See Slide screens in and out for what it does, and which way each navigation moves.
API
LynxStackOutlet
A RouterOutlet that keeps a stack of screens and moves between them as iOS and Android apps do. Use it in place of <router-outlet>: it has the same inputs, outputs and API, and the screens under the top one stay alive.
swipeBacktakes a drag from the left edge, or from anywhere that doesn't scroll sideways.pageClass: without it, a screen is drawn onvar(--background, #ffffff).hideBottomBar:'pushed'is every screen pushed over the first, and'never'is none.- It fills its parent (
flex: 1) and clips the screens in it. Each screen sits in a frame of its own, absolutely placed over the others. - While Reduce Motion is on, a push or a pop cross-fades.
- A swipe goes back through the history, to the entry before the top screen's, however many it added since. A guard that refuses brings the screen back.
- A screen pushed over the first takes the bottom bar away, and says so through
LynxStackChrome. A route'sdata: { bottomBar: 'visible' | 'hidden' }says otherwise for its screen. - With
withErrorBoundaries(), a screen that throws shows its route's error component in its frame, andisErrorComponentActiveistruewhile the top screen does, as on<router-outlet>. Going back to the screen builds it again. A covered screen that fails gets onlyerror:<router-outlet>binds the route's params and data to its one active screen, and the router is on the top one, so make the error component's route inputs optional. See When a screen fails.
StackNavigationInfo
What a navigation does to a LynxStackOutlet's stack, when the URL doesn't say it the way you want. Pass it as the navigation's info:
- On a
routerLink:[info]="{ stack: 'push' }" - From code:
router.navigate(commands, { info: { stack: 'root' } })
A LynxTabOutlet reads 'root' too. A navigation to a hidden tab's own URL with stack: 'root' goes to that URL, rather than to where the tab was left.
LynxStackPage
The screen of a LynxStackOutlet that a component is on. Any component on it can inject it: inject(LynxStackPage, { optional: true }), which is null off a stack. It also identifies the screen, for state kept per screen.
- A covered screen's components keep running, so use
active()to pause what only matters while it shows. bottomBarHidden()doesn't change while the screen is covered. So a screen can drop the room it keeps at its end for the bar without moving its content under a screen on top. SeeLynxStackChrome.
LynxStackChrome
What the stack that's showing does, for a bar outside it: a tab bar or a dock beside the <router-outlet> whose tabs hold <lynx-stack-outlet>s.
- The Tab Bar and the Dock follow it through
LynxStackBottomBar, which also has the screen underneath carry the bar on iOS. - A bar of your own can do the same, or read the chrome directly and slide away on its own, as below.
bottomBarHiddenchanges as a push or a pop starts, and when the router goes back after a swipe. It doesn't change while a finger drags. Hide the bar from screen readers and taps while it'strue.bottomBarProgressfollows a finger dragging a screen back, move by move. A push or a pop sets it to where the bar ends up as the screens start to move.bottomBarMotion.animationis the screens'animation, or'fade'while Reduce Motion cross-fades them.bottomBarMotion.duration(ms) andeasingare the push's or pop's.durationis0while a finger drags or nothing moves.bottomBarMotion.coveredXis how far the screen under a pushed one moves, as a share of the width (-0.3on iOS).
Which screens take the bar away
- Every screen pushed over a stack's first one, unless its outlet's
hideBottomBaris'never'. - A route says otherwise in its data.
{ path: 'results', component: Results, data: { bottomBar: 'visible' } }keeps it.bottomBar: 'hidden'takes it away, even from a stack's first screen. - Only a stack the app shows counts: one with a screen the router has active, on screens that are on top of their own stacks. A tab the router has left doesn't hide the bar on another tab, nor does a stack on a covered screen.
- Stacks inside stacks: the innermost decides. A screen that doesn't say (a stack's first, or a pushed one under
hideBottomBar="never") leaves the bar as the stacks around it have it. - On a stack's screen, it follows only the stacks on that screen. A bar inside a screen moves with the screen, so the stack that moves the screen doesn't move the bar too.
LynxStackBottomBar
Makes a bottom bar part of the screen that has it while a stack's screens move as iOS's do. UIKit does the same with its tab bar while a navigation controller moves. The Tab Bar and the Dock put it on their hosts.
- The pushed screen covers the bar as it covers the screen underneath, with its rounded corner and its shadow.
- The dark over the screen underneath dims the bar too.
- The bar moves with that screen under a finger.
- Why not a bar outside the stack: it would lie over both screens. The best it could do is cut itself off along the pushed screen's edge.
Put it on your bar's host, and move the bar with its signals rather than LynxStackChrome's:
While a screen carries the bar, the bar should look as it does at rest.
- Which screen carries it: the one that shows the bar, as another screen moves over it or off it. A push carries it in the screen underneath, and a pop or a swipe back carries it back in.
- How long: that screen keeps it while it's covered. The bar goes back to its own place once that screen is on top again, or the router leaves the stack (another tab).
- Where it doesn't carry it: a screen that's popped, or one a finger drags (which may go), doesn't carry a bar it shows. The bar slides away on its own.
- Android's motion and the Reduce Motion cross-fade don't carry it either.
progressandmotionare then the chrome's. - Where it sits: absolutely, along the bottom and across the width of the screen carrying it, which fills the stack.
- So the stack should run to the bottom of the screen, as it does beside a floating dock, or once a tab bar is out of the layout. (The Tab Bar lies over the stack while it's away or on its way.)
- Its place: a comment holds the bar's place in its parent meanwhile, as with CDK's
DomPortal.
Related
- Slide screens in and out: how the stack moves, and the tab bar on pushed screens.
- Routing:
provideRouter()and the rest of the router API. - Tab Outlet: keeps each tab alive, stacks and all.
- Location:
LynxLocationStrategy.historyIndex, which the stack's swipe goes back by. - Tab Bar and Dock
