Skip to main content

NavController

Struct NavController 

Source
pub struct NavController<R: Clone + 'static> { /* private fields */ }
Expand description

The back stack of a NavHost — Android’s NavController.

It is Copy, so it moves into any number of move closures: move || nav.navigate(Screen::Detail { id }). R is the route type, usually an enum whose variants carry the screen’s arguments.

Implementations§

Source§

impl<R: Clone + PartialEq + 'static> NavController<R>

Source

pub fn navigate(&self, route: R)

Pushes route on top of the back stack — Android’s navigate(route).

Source

pub fn navigate_with(&self, route: R, options: NavOptions<R>)

Navigates to route the way options say — Android’s navigate(route) { popUpTo(...); launchSingleTop = true }.

Source

pub fn pop_back_stack(&self) -> bool

Pops the top entry and returns whether there was one — Android’s popBackStack(). Popping the last entry leaves the host empty.

Source

pub fn pop_back_stack_to(&self, route: &R, inclusive: bool) -> bool

Pops the entries above the topmost route, and that entry too when inclusive, and returns whether anything was popped — Android’s popBackStack(route, inclusive).

Source

pub fn navigate_up(&self) -> bool

Pops the top entry when there is one beneath it, and returns whether it did — Android’s navigateUp().

Source

pub fn current_route(&self) -> Option<R>

The route on top of the back stack, None once everything is popped. Reading it in a composable recomposes that composable when it changes — Android’s currentBackStackEntryAsState().

Source

pub fn back_stack(&self) -> Vec<R>

Every route on the back stack, bottom first. Reading it in a composable recomposes that composable when it changes — Android’s currentBackStack.

Source

pub fn composing_entry(&self) -> Option<NavBackStackEntry<R>>

The entry whose screen or dialog composes the caller, when this controller’s host shows it — the NavBackStackEntry that Android’s NavHost gives each destination. Call it while composing. It does not subscribe the caller, and it is None once the entry is popped.

Source

pub fn previous_back_stack_entry(&self) -> Option<NavBackStackEntry<R>>

The entry beneath the top one, which a pop shows — Android’s previousBackStackEntry. It does not subscribe the caller.

Source

pub fn back_stack_entry(&self, route: &R) -> Option<NavBackStackEntry<R>>

The topmost entry of route — Android’s getBackStackEntry(route). It does not subscribe the caller.

Trait Implementations§

Source§

impl<R: Clone + 'static> Clone for NavController<R>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R: Clone + 'static> Copy for NavController<R>

Source§

impl<R: Clone + 'static> PartialEq for NavController<R>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<R> Freeze for NavController<R>
where MutableState<BackStack<R>>: Freeze,

§

impl<R> RefUnwindSafe for NavController<R>
where MutableState<BackStack<R>>: RefUnwindSafe,

§

impl<R> Send for NavController<R>
where MutableState<BackStack<R>>: Send,

§

impl<R> Sync for NavController<R>
where MutableState<BackStack<R>>: Sync,

§

impl<R> Unpin for NavController<R>
where MutableState<BackStack<R>>: Unpin,

§

impl<R> UnsafeUnpin for NavController<R>
where MutableState<BackStack<R>>: UnsafeUnpin,

§

impl<R> UnwindSafe for NavController<R>
where MutableState<BackStack<R>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.