Skip to content

Commit

Permalink
Merge pull request #2 from kiwicom/popupto
Browse files Browse the repository at this point in the history
implement generic popUpTo()
  • Loading branch information
hrach authored Sep 7, 2022
2 parents 96aa148 + a332bea commit 88a8cd1
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 88a8cd1

Please sign in to comment.