Skip to content

Commit

Permalink
Create destinations from a TypedNavBackStackEntry (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
eygraber authored May 28, 2024
1 parent 7e3dd08 commit a4a377b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public actual inline fun <reified T : Any> NavGraphBuilder.viceComposable(
AnimatedContentTransitionScope<NavBackStackEntry>.() ->
@JvmSuppressWildcards SizeTransform?
)?,
crossinline destinationFactory: (T) -> ViceDestination<*, *, *, *>,
crossinline destinationFactory: (TypedNavBackStackEntry<T>) -> ViceDestination<*, *, *, *>,
) {
composable<T>(
typeMap,
Expand All @@ -41,21 +41,21 @@ public actual inline fun <reified T : Any> NavGraphBuilder.viceComposable(
popExitTransition,
sizeTransform,
) {
remember(it) { destinationFactory(it.toRoute<T>()) }.Vice()
remember(it) { destinationFactory(TypedNavBackStackEntry(it.toRoute<T>(), it)) }.Vice()
}
}

public actual inline fun <reified T : Any> NavGraphBuilder.viceDialog(
typeMap: Map<KType, @JvmSuppressWildcards NavType<*>>,
deepLinks: List<NavDeepLink>,
dialogProperties: DialogProperties,
crossinline destinationFactory: (T) -> ViceDestination<*, *, *, *>,
crossinline destinationFactory: (TypedNavBackStackEntry<T>) -> ViceDestination<*, *, *, *>,
) {
dialog<T>(
typeMap,
deepLinks,
dialogProperties,
) {
remember(it) { destinationFactory(it.toRoute<T>()) }.Vice()
remember(it) { destinationFactory(TypedNavBackStackEntry(it.toRoute<T>(), it)) }.Vice()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public actual inline fun <reified T : Any> NavGraphBuilder.viceComposable(
AnimatedContentTransitionScope<NavBackStackEntry>.() ->
@JvmSuppressWildcards SizeTransform?
)?,
crossinline destinationFactory: (T) -> ViceDestination<*, *, *, *>,
crossinline destinationFactory: (TypedNavBackStackEntry<T>) -> ViceDestination<*, *, *, *>,
) {
@Suppress("NotImplementedDeclaration")
TODO("Not implemented yet; waiting for CMP navigation to support type safe APIs")
Expand All @@ -37,7 +37,7 @@ public actual inline fun <reified T : Any> NavGraphBuilder.viceDialog(
typeMap: Map<KType, @JvmSuppressWildcards NavType<*>>,
deepLinks: List<NavDeepLink>,
dialogProperties: DialogProperties,
crossinline destinationFactory: (T) -> ViceDestination<*, *, *, *>,
crossinline destinationFactory: (TypedNavBackStackEntry<T>) -> ViceDestination<*, *, *, *>,
) {
@Suppress("NotImplementedDeclaration")
TODO("Not implemented yet; waiting for CMP navigation to support type safe APIs")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.eygraber.vice.nav

import androidx.navigation.NavBackStackEntry

public data class TypedNavBackStackEntry<T : Any>(
public val route: T,
public val entry: NavBackStackEntry,
)
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public expect inline fun <reified T : Any> NavGraphBuilder.viceComposable(
AnimatedContentTransitionScope<NavBackStackEntry>.() ->
@JvmSuppressWildcards SizeTransform?
)? = null,
crossinline destinationFactory: (T) -> ViceDestination<*, *, *, *>,
crossinline destinationFactory: (TypedNavBackStackEntry<T>) -> ViceDestination<*, *, *, *>,
)

public fun NavGraphBuilder.viceDialog(
Expand All @@ -86,5 +86,5 @@ public expect inline fun <reified T : Any> NavGraphBuilder.viceDialog(
typeMap: Map<KType, @JvmSuppressWildcards NavType<*>> = emptyMap(),
deepLinks: List<NavDeepLink> = emptyList(),
dialogProperties: DialogProperties = DialogProperties(),
crossinline destinationFactory: (T) -> ViceDestination<*, *, *, *>,
crossinline destinationFactory: (TypedNavBackStackEntry<T>) -> ViceDestination<*, *, *, *>,
)

0 comments on commit a4a377b

Please sign in to comment.