Skip to content

Commit

Permalink
Clean up navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
boswelja committed Nov 17, 2024
1 parent b3cf309 commit b2187d3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ import com.imashnake.animite.navigation.R as navigationR
/**
* Search bar along with a Front Drop list.
*
* @param hasExtraPadding if the search bar should have extra bottom padding to accommodate the
* [com.imashnake.animite.navigation.NavigationBar].
* @param hasExtraPadding if the search bar should have extra bottom padding to accommodate the bottom navigation bar.
* @param onItemClick called when media with an ID and [MediaType] is clicked.
* @param modifier the [Modifier] to be applied to this Front Drop.
* @param viewModel [SearchViewModel] instance.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.imashnake.animite.navigation

import androidx.annotation.StringRes
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavDestination.Companion.hasRoute
import androidx.navigation.NavDestination.Companion.hierarchy

enum class NavigationBarPaths(
val route: Any,
val matchesDestination: (NavBackStackEntry) -> Boolean,
val icon: @Composable () -> Unit,
@StringRes val labelRes: Int
) {
Social(
route = SocialRoute,
matchesDestination = {
it.destination.hierarchy.any { it.hasRoute(SocialRoute::class) }
},
icon = {
Icon(ImageVector.vectorResource(R.drawable.social), contentDescription = stringResource(R.string.social))
},
labelRes = R.string.social
),
Home(
route = HomeRoute,
matchesDestination = {
it.destination.hierarchy.any { it.hasRoute(HomeRoute::class) }
},
icon = {
Icon(ImageVector.vectorResource(R.drawable.home), contentDescription = stringResource(R.string.home))
},
labelRes = R.string.home
),

Profile(
route = ProfileRoute(),
matchesDestination = {
it.destination.hierarchy.any { it.hasRoute(ProfileRoute::class) }
},
icon = {
Icon(ImageVector.vectorResource(R.drawable.profile), contentDescription = stringResource(R.string.profile))
},
labelRes = R.string.profile
),
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ fun NavigationScaffold(
NavigationBarPaths.entries.forEach { destination ->
item(
selected = currentBackStackEntry?.let { destination.matchesDestination(it) } == true,
onClick = { destination.navigateTo(navController) },
onClick = {
navController.navigate(destination.route) {
popUpTo(navController.graph.id) {
inclusive = true
}
}
},
icon = destination.icon
)
}
Expand Down

0 comments on commit b2187d3

Please sign in to comment.