diff --git a/navigation/build.gradle.kts b/navigation/build.gradle.kts index 755b543e..d841ea31 100644 --- a/navigation/build.gradle.kts +++ b/navigation/build.gradle.kts @@ -53,4 +53,5 @@ android { } dependencies { + implementation(libs.androidx.navigation.compose) } diff --git a/navigation/src/main/java/no/nordicsemi/android/common/navigation/NavigationView.kt b/navigation/src/main/java/no/nordicsemi/android/common/navigation/NavigationView.kt index ae171d6a..d13c1ccd 100644 --- a/navigation/src/main/java/no/nordicsemi/android/common/navigation/NavigationView.kt +++ b/navigation/src/main/java/no/nordicsemi/android/common/navigation/NavigationView.kt @@ -33,13 +33,20 @@ package no.nordicsemi.android.common.navigation import android.app.Activity import android.os.Bundle -import androidx.activity.compose.BackHandler +import androidx.compose.animation.AnimatedContentTransitionScope +import androidx.compose.animation.EnterTransition +import androidx.compose.animation.ExitTransition +import androidx.compose.animation.SizeTransform +import androidx.compose.animation.core.tween +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle +import androidx.navigation.NavBackStackEntry import androidx.navigation.NavGraph.Companion.findStartDestination import androidx.navigation.NavGraphBuilder import androidx.navigation.compose.NavHost @@ -59,11 +66,40 @@ import no.nordicsemi.android.common.navigation.internal.navigate * * @param destinations The list of possible destinations. * @param modifier The modifier to be applied to the layout. + * @param enterTransition callback to define enter transitions for destination in this host + * @param exitTransition callback to define exit transitions for destination in this host + * @param popEnterTransition callback to define popEnter transitions for destination in this host + * @param popExitTransition callback to define popExit transitions for destination in this host + * @param sizeTransform callback to define the size transform for destinations in this host */ @Composable fun NavigationView( destinations: List, modifier: Modifier = Modifier, + enterTransition: + (@JvmSuppressWildcards + AnimatedContentTransitionScope.() -> EnterTransition) = + { + fadeIn(animationSpec = tween(700)) + }, + exitTransition: + (@JvmSuppressWildcards + AnimatedContentTransitionScope.() -> ExitTransition) = + { + fadeOut(animationSpec = tween(700)) + }, + popEnterTransition: + (@JvmSuppressWildcards + AnimatedContentTransitionScope.() -> EnterTransition) = + enterTransition, + popExitTransition: + (@JvmSuppressWildcards + AnimatedContentTransitionScope.() -> ExitTransition) = + exitTransition, + sizeTransform: + (@JvmSuppressWildcards + AnimatedContentTransitionScope.() -> SizeTransform?)? = + null, ) { val navHostController = rememberNavController() @@ -114,6 +150,11 @@ fun NavigationView( modifier = modifier, navController = navHostController, startDestination = destinations.first().id.name, + enterTransition = enterTransition, + exitTransition = exitTransition, + popEnterTransition = popEnterTransition, + popExitTransition = popExitTransition, + sizeTransform = sizeTransform, ) { create(destinations, navigation) } diff --git a/navigation/src/main/java/no/nordicsemi/android/common/navigation/internal/NavController+Bundle.kt b/navigation/src/main/java/no/nordicsemi/android/common/navigation/internal/NavController+Bundle.kt index 8dfe573e..f29d6cb5 100644 --- a/navigation/src/main/java/no/nordicsemi/android/common/navigation/internal/NavController+Bundle.kt +++ b/navigation/src/main/java/no/nordicsemi/android/common/navigation/internal/NavController+Bundle.kt @@ -33,7 +33,6 @@ package no.nordicsemi.android.common.navigation.internal import android.annotation.SuppressLint import android.os.Bundle -import androidx.core.net.toUri import androidx.navigation.* //FIXME Fix NavGraph methods() can only be called from within the same library group. @@ -45,14 +44,8 @@ internal fun NavController.navigate( navOptions: NavOptions? = null, navigatorExtras: Navigator.Extras? = null ) { - val routeLink = NavDeepLinkRequest - .Builder - .fromUri(NavDestination.createRoute(route).toUri()) - .build() - - val deepLinkMatch = graph.matchDeepLink(routeLink) - if (deepLinkMatch != null) { - val destination = deepLinkMatch.destination + val destination = findDestination(route) + if (destination != null) { val id = destination.id navigate(id, args, navOptions, navigatorExtras) } else {