Skip to main content

Crate cranpose_navigation

Crate cranpose_navigation 

Source
Expand description

§cranpose-navigation

cranpose-navigation provides a typed back stack and a composable NavHost. Routes can carry screen arguments, and each stack entry owns a view-model store.

Depend directly on cranpose-navigation when a Cranpose app needs screen navigation. The feature set is empty. The app also needs its usual cranpose host and renderer features; the navigation crate brings UI, animation, and cranpose-coroflow APIs as dependencies.

§Define routes and screens

rememberNavController stores the stack in the current composition. NavHost maps each route to a screen, while a screen callback can push a typed route:

use cranpose_navigation::{NavHost, rememberNavController};
use cranpose_ui::composable;

#[derive(Clone, PartialEq)]
enum Screen {
    Home,
    Detail { id: u32 },
}

#[composable]
fn App() {
    let nav = rememberNavController(Screen::Home);
    NavHost(nav, move |screen| match screen {
        Screen::Home => HomeScreen(move || nav.navigate(Screen::Detail { id: 7 })),
        Screen::Detail { id } => DetailScreen(id),
    });
}

#[composable]
fn HomeScreen(_open_detail: impl Fn() + 'static) {}

#[composable]
fn DetailScreen(_id: u32) {}

NavHost crossfades between screens and connects platform back requests to stack pop. Use NavHostWith for a custom transition and NavController::navigate_with for pop-up and single-top options.

§Android API map

Android APICranpose API
rememberNavController() and startDestinationrememberNavController, NavController
NavHost and typed destinationsNavHost with a route match
Enter and exit transitionsNavHostWith
navigate, popBackStack, navigateUpnavigate, pop_back_stack, navigate_up
popUpTo, inclusive pop, single topnavigate_with, NavOptions
Current back-stack entrycurrent_route, back_stack
View model scoped to a back-stack entrycranpose_coroflow::viewModel inside a screen

Structs§

NavController
The back stack of a NavHost — Android’s NavController.
NavOptions
How NavController::navigate_with changes the back stack — Android’s NavOptions.

Functions§

NavHost
Shows the screen on top of controller’s back stack — Android’s NavHost.
NavHostWith
NavHost with its own transition between screens — Compose’s NavHost(enterTransition, exitTransition) for a fade.
rememberNavController
A NavController whose back stack starts at start — Android’s rememberNavController() plus NavHost(startDestination).