Skip to content

Commit

Permalink
implement generic popUpTo()
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Sep 7, 2022
1 parent ba95f19 commit a332bea
Showing 1 changed file with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,43 @@ package com.kiwi.navigationcompose.typed

import androidx.navigation.NavController
import androidx.navigation.NavOptions
import androidx.navigation.NavOptionsBuilder
import androidx.navigation.Navigator
import androidx.navigation.PopUpToBuilder
import kotlinx.serialization.ExperimentalSerializationApi

/**
* Navigates to the passed Route.
*/
public fun NavController.navigate(
destination: Route,
route: Route,
navOptions: NavOptions? = null,
navigatorExtras: Navigator.Extras? = null,
) {
navigate(destination.url, navOptions, navigatorExtras)
navigate(route.url, navOptions, navigatorExtras)
}

@ExperimentalSerializationApi
public inline fun <reified T : Destination> NavOptions.Builder.setPopUpTo(
inclusive: Boolean,
saveState: Boolean = false,
): NavOptions.Builder {
return setPopUpTo(createRoutePattern<T>(), inclusive, saveState)
}

/**
* Navigates to the passed Route.
*/
public fun NavController.navigate(
route: Route,
builder: NavOptionsBuilder.() -> Unit,
) {
navigate(route.url, builder)
}

@ExperimentalSerializationApi
public inline fun <reified T : Destination> NavOptionsBuilder.popUpTo(
noinline popUpToBuilder: PopUpToBuilder.() -> Unit = {},
) {
popUpTo(createRoutePattern<T>(), popUpToBuilder)
}

0 comments on commit a332bea

Please sign in to comment.