SwipeDismissableNavHost

Composable Function

Android
@Composable
public fun SwipeDismissableNavHost(
    navController: NavHostController,
    startDestination: String,
    modifier: Modifier = Modifier,
    userSwipeEnabled: Boolean = true,
    state: SwipeDismissableNavHostState = rememberSwipeDismissableNavHostState(),
    route: String? = null,
    builder: NavGraphBuilder.() -> Unit,
): Unit

Provides a place in the Compose hierarchy for self-contained navigation to occur, with backwards navigation provided by a swipe gesture.

Once this is called, any Composable within the given NavGraphBuilder can be navigated to from the provided navController.

The builder passed into this method is remembered. This means that for this NavHost, the contents of the builder cannot be changed.

During a swipe-to-dismiss gesture, the previous navigation level (if any) is shown in the background. BackgroundScrimColor and ContentScrimColor of it are taken from LocalSwipeToDismissBackgroundScrimColor and LocalSwipeToDismissContentScrimColor.

Below API level 36, content of the current navigation level is displayed within a BasicSwipeToDismissBox to detect swipe back gestures.

API level 36 onwards, SwipeDismissableNavHost listens to platform predictive back events for navigation, and BasicSwipeToDismissBox is not used for swipe gesture detection.

Example of a SwipeDismissableNavHost alternating between 2 screens:

Example of a SwipeDismissableNavHost for which a destination has a named argument:

Parameters

navControllerThe navController for this host
startDestinationThe route for the start destination
modifierThe modifier to be applied to the layout
userSwipeEnabledBoolean Whether swipe-to-dismiss gesture is enabled.
stateState containing information about ongoing swipe and animation. This parameter is unused API level 36 onwards, because the platform supports predictive back and SwipeDismissableNavHost uses platform gestures to detect the back gestures.
routeThe route for the graph
builderThe builder used to construct the graph
Android
@Composable
public fun SwipeDismissableNavHost(
    navController: NavHostController,
    graph: NavGraph,
    modifier: Modifier = Modifier,
    userSwipeEnabled: Boolean = true,
    state: SwipeDismissableNavHostState = rememberSwipeDismissableNavHostState(),
)

Provides a place in the Compose hierarchy for self-contained navigation to occur, with backwards navigation provided by a swipe gesture.

Once this is called, any Composable within the given NavGraphBuilder can be navigated to from the provided navController.

The builder passed into this method is remembered. This means that for this NavHost, the contents of the builder cannot be changed.

During a swipe-to-dismiss gesture, the previous navigation level (if any) is shown in the background. BackgroundScrimColor and ContentScrimColor of it are taken from LocalSwipeToDismissBackgroundScrimColor and LocalSwipeToDismissContentScrimColor.

Below API level 36, content of the current navigation level is displayed within a BasicSwipeToDismissBox to detect swipe back gestures.

API level 36 onwards, SwipeDismissableNavHost listens to platform predictive back events for navigation, and BasicSwipeToDismissBox is not used for swipe gesture detection. Therefore, Modifier.edgeSwipeToDismiss is not compatible with SwipeDismissableNavHost for API level 36 onwards.

Example of a SwipeDismissableNavHost alternating between 2 screens:

Example of a SwipeDismissableNavHost for which a destination has a named argument:

Parameters

navControllerNavHostController for this host
graphGraph for this host
modifierModifier to be applied to the layout
userSwipeEnabledBoolean Whether swipe-to-dismiss gesture is enabled.
stateState containing information about ongoing swipe and animation. This parameter is unused API level 36 onwards, because the platform supports predictive back and SwipeDismissableNavHost uses platform gestures to detect the back gestures.
Android

Deprecated This overload is provided for backwards compatibility. A newer overload is available with an additional userSwipeEnabled param.

@Composable
public fun SwipeDismissableNavHost(
    navController: NavHostController,
    startDestination: String,
    modifier: Modifier = Modifier,
    state: SwipeDismissableNavHostState = rememberSwipeDismissableNavHostState(),
    route: String? = null,
    builder: NavGraphBuilder.() -> Unit,
): Unit

Provides a place in the Compose hierarchy for self-contained navigation to occur, with backwards navigation provided by a swipe gesture.

Once this is called, any Composable within the given NavGraphBuilder can be navigated to from the provided navController.

The builder passed into this method is remembered. This means that for this NavHost, the contents of the builder cannot be changed.

Content is displayed within a BasicSwipeToDismissBox, showing the current navigation level. During a swipe-to-dismiss gesture, the previous navigation level (if any) is shown in the background. BackgroundScrimColor and ContentScrimColor of it are taken from LocalSwipeToDismissBackgroundScrimColor and LocalSwipeToDismissContentScrimColor.

Example of a SwipeDismissableNavHost alternating between 2 screens:

Example of a SwipeDismissableNavHost for which a destination has a named argument:

Parameters

navControllerThe navController for this host
startDestinationThe route for the start destination
modifierThe modifier to be applied to the layout
stateState containing information about ongoing swipe and animation.
routeThe route for the graph
builderThe builder used to construct the graph
Android

Deprecated This overload is provided for backwards compatibility. A newer overload is available with an additional userSwipeEnabled param.

@Composable
public fun SwipeDismissableNavHost(
    navController: NavHostController,
    graph: NavGraph,
    modifier: Modifier = Modifier,
    state: SwipeDismissableNavHostState = rememberSwipeDismissableNavHostState(),
): Unit

Provides a place in the Compose hierarchy for self-contained navigation to occur, with backwards navigation provided by a swipe gesture.

Once this is called, any Composable within the given NavGraphBuilder can be navigated to from the provided navController.

The builder passed into this method is remembered. This means that for this NavHost, the contents of the builder cannot be changed.

Content is displayed within a BasicSwipeToDismissBox, showing the current navigation level. During a swipe-to-dismiss gesture, the previous navigation level (if any) is shown in the background. BackgroundScrimColor and ContentScrimColor of it are taken from LocalSwipeToDismissBackgroundScrimColor and LocalSwipeToDismissContentScrimColor.

Example of a SwipeDismissableNavHost alternating between 2 screens:

Example of a SwipeDismissableNavHost for which a destination has a named argument:

Parameters

navControllerNavHostController for this host
graphGraph for this host
modifierModifier to be applied to the layout
stateState containing information about ongoing swipe and animation.