LynxBackButton
Hears Android's back button (and the back gesture), so that back closes what's open on top, and otherwise goes back a screen. import { LynxBackButton, type LynxBackHandler } from '@blotch/angular-lynx';
Usage
Register a handler while something that back should close is open, and remove it as that closes:
@blotch/ui's popovers and anchored action sheets register one while they're open. Its sheets, dialogs and drawers draw in an <overlay>, which Android gives back to first, as requestclose.
API
LynxBackButton
A press goes to the handler registered last with on(). With none, the router goes back a screen, with Location.back(), so guards and resolvers run. On the router's first screen, or without provideRouter() from @blotch/angular-lynx, back is Android's: it leaves the app.
- While an
<overlay>shows, Android gives back to it, as itsrequestcloseevent, and not to these handlers. - Android decides whether the app takes back when the gesture starts, before JavaScript could answer. So the app tells the shell beforehand: it takes back while a handler is registered or the router has a screen to go back to, and Android has it the rest of the time.
- Android's back gesture follows the finger in a
<lynx-stack-outlet>: while no handler takes back, the stack back goes back in moves its top screen with the gesture, and finishes going back as the finger lets go, or brings the screen back if the gesture is canceled. A handler hears back only once the gesture is done, as a press. - With a
LocationStrategyof your own, only the handlers take back: the router's history doesn't.
LynxBackButton.on()
Gives the back button's presses to handler until it's removed. While it's registered, back doesn't go back a screen or leave the app.
- The handler registered last gets each press, so what opened last closes first. The others wait their turn.
- A handler that throws is reported to Angular's
ErrorHandler. - The handler goes with its injection context. Called from one, such as a constructor, the handler is removed when the component or service is destroyed. Pass
injectorto tie it to another. Outside one, it stays until it's removed. - Returns a function that removes the handler.
