pub fn attach_back_handler<State: 'static>(
controller: NavigatorController<State>,
) -> BackHandler<State>Expand description
Android back-press ⇄ navigator auto-wiring:
attach_back_handler/BackHandler pop a NavigatorController on a
platform back press and keep frust-reactive‘s handles_back flag in
sync with the stack depth, so a shell knows whether a root-level back should
fall through to the platform (activity finish). Mirrors
RouterDeepLinks’s shape and, like it, is the ONLY place in the facade
that sees both frust-widgets’ NavigatorController and
frust-reactive’s back-press source together — see BackHandler’s doc
for the consume/dedupe and timing contracts. Call BackHandler::track
from every Component::build.
Android back-press ⇄ navigator auto-wiring:
attach_back_handler/BackHandler pop a NavigatorController on a
platform back press and keep frust-reactive‘s handles_back flag in
sync with the stack depth, so a shell knows whether a root-level back should
fall through to the platform (activity finish). Mirrors
RouterDeepLinks’s shape and, like it, is the ONLY place in the facade
that sees both frust-widgets’ NavigatorController and
frust-reactive’s back-press source together — see BackHandler’s doc
for the consume/dedupe and timing contracts. Call BackHandler::track
from every Component::build.
Android back-press ⇄ navigator auto-wiring:
attach_back_handler/BackHandler pop a NavigatorController on a
platform back press and keep frust-reactive‘s handles_back flag in
sync with the stack depth, so a shell knows whether a root-level back should
fall through to the platform (activity finish). Mirrors
RouterDeepLinks’s shape and, like it, is the ONLY place in the facade
that sees both frust-widgets’ NavigatorController and
frust-reactive’s back-press source together — see BackHandler’s doc
for the consume/dedupe and timing contracts. Call BackHandler::track
from every Component::build.
Convenience constructor equivalent to BackHandler::new — see its docs and
RouterDeepLinks/router_with_deep_links
for the mirrored API shape.
Note that back handling is automatic for any app using
frust::navigator; this explicit surface is
only needed when an app wants a handle it drives directly (e.g. Huddle).
use frust::{
AnyView, BackHandler, Component, NavigatorController, any, attach_back_handler,
navigator, text,
};
#[derive(Default)]
struct App;
struct AppState {
back: BackHandler<AppState>,
}
impl Component for App {
type State = AppState;
fn init(&self) -> AppState {
let nav: NavigatorController<AppState> = NavigatorController::new();
AppState {
back: attach_back_handler(nav),
}
}
fn build(&self, state: &mut AppState) -> AnyView<AppState> {
// Called every rebuild: consumes a new back press (via `request_back`)
// and keeps the framework's handles-back interest in sync. The
// `frust::navigator` call auto-wires the SAME controller — one press
// still pops exactly once (shared consumption source).
state.back.track();
let controller = state.back.controller();
any(navigator(controller, || any(text("home"))))
}
}
frust::app!(App);