pub struct NavBackStackEntry<R: Clone + 'static> { /* private fields */ }Expand description
One visit on a NavController’s back stack — Android’s
NavBackStackEntry.
Its route carries the screen’s arguments. Other screens leave it values
with Self::set_result, as Android’s savedStateHandle does, and its
screen reads them with Self::result. A screen returns a result to the
one beneath it this way:
use cranpose_navigation::NavController;
#[derive(Clone, PartialEq)]
enum Screen {
Home,
PickColor,
}
#[derive(Clone)]
struct Picked(u32);
fn pick(nav: NavController<Screen>, color: u32) {
if let Some(home) = nav.previous_back_stack_entry() {
home.set_result(Picked(color));
}
nav.pop_back_stack();
}
// In the home screen, while composing:
fn picked(nav: NavController<Screen>) -> Option<u32> {
let Picked(color) = nav.composing_entry()?.result::<Picked>()?;
Some(color)
}The type of a value is its key, so an entry holds one value of each type;
a newtype per result keeps two results of one type apart. Results live in
memory: a popped entry drops them, and a restored back stack starts
without them. A screen that shows a result for longer takes it into its
own saved state, such as rememberSaveable.
Implementations§
Sourcepub fn route(&self) -> Option<R>
pub fn route(&self) -> Option<R>
The entry’s route, with the screen’s arguments; None once it is
popped. It does not subscribe the caller: an entry keeps its route.
Sourcepub fn result<T: Clone + 'static>(&self) -> Option<T>
pub fn result<T: Clone + 'static>(&self) -> Option<T>
The value of type T that a screen left for this entry. Reading it in
a composable recomposes that composable when the value changes —
Android’s savedStateHandle.getStateFlow(key).
Sourcepub fn set_result<T: 'static>(&self, value: T)
pub fn set_result<T: 'static>(&self, value: T)
Leaves value for this entry, in place of its earlier value of type
T — Android’s savedStateHandle[key] = value. Does nothing once the
entry is popped.
Sourcepub fn take_result<T: Clone + 'static>(&self) -> Option<T>
pub fn take_result<T: Clone + 'static>(&self) -> Option<T>
Removes the value of type T and returns it — Android’s
savedStateHandle.remove(key). A screen calls it once it has acted on
a result, from an effect or a callback.