Skip to content

Commit

Permalink
Merge pull request #119 from NordicPlayground/dependency/navigation
Browse files Browse the repository at this point in the history
Navigation library updated
  • Loading branch information
philips77 authored Dec 5, 2024
2 parents 534379b + 37ba2be commit d59f51d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
1 change: 1 addition & 0 deletions navigation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ android {
}

dependencies {
implementation(libs.androidx.navigation.compose)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<NavigationDestination>,
modifier: Modifier = Modifier,
enterTransition:
(@JvmSuppressWildcards
AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition) =
{
fadeIn(animationSpec = tween(700))
},
exitTransition:
(@JvmSuppressWildcards
AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition) =
{
fadeOut(animationSpec = tween(700))
},
popEnterTransition:
(@JvmSuppressWildcards
AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition) =
enterTransition,
popExitTransition:
(@JvmSuppressWildcards
AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition) =
exitTransition,
sizeTransform:
(@JvmSuppressWildcards
AnimatedContentTransitionScope<NavBackStackEntry>.() -> SizeTransform?)? =
null,
) {
val navHostController = rememberNavController()

Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down

0 comments on commit d59f51d

Please sign in to comment.