mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-18 03:17:03 +05:30
Make bottom nav icons part of destination classes
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
41521cca95
commit
b195c0d203
2 changed files with 5 additions and 10 deletions
|
@ -62,14 +62,7 @@ fun LobstersApp() {
|
||||||
val currentRoute = navBackStackEntry?.arguments?.getString(KEY_ROUTE)
|
val currentRoute = navBackStackEntry?.arguments?.getString(KEY_ROUTE)
|
||||||
destinations.forEach { screen ->
|
destinations.forEach { screen ->
|
||||||
BottomNavigationItem(
|
BottomNavigationItem(
|
||||||
icon = {
|
icon = { IconResource(resourceId = screen.badgeRes) },
|
||||||
IconResource(
|
|
||||||
resourceId = when (screen) {
|
|
||||||
Destination.Hottest -> R.drawable.ic_whatshot_24px
|
|
||||||
Destination.Saved -> R.drawable.ic_favorite_24px
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
label = { Text(stringResource(id = screen.labelRes)) },
|
label = { Text(stringResource(id = screen.labelRes)) },
|
||||||
selected = currentRoute == screen.route,
|
selected = currentRoute == screen.route,
|
||||||
onClick = {
|
onClick = {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package dev.msfjarvis.lobsters.ui
|
package dev.msfjarvis.lobsters.ui
|
||||||
|
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import dev.msfjarvis.lobsters.R
|
import dev.msfjarvis.lobsters.R
|
||||||
|
|
||||||
|
@ -9,7 +10,8 @@ import dev.msfjarvis.lobsters.R
|
||||||
sealed class Destination(
|
sealed class Destination(
|
||||||
val route: String,
|
val route: String,
|
||||||
@StringRes val labelRes: Int,
|
@StringRes val labelRes: Int,
|
||||||
|
@DrawableRes val badgeRes: Int,
|
||||||
) {
|
) {
|
||||||
object Hottest : Destination("hottest", R.string.hottest_posts)
|
object Hottest : Destination("hottest", R.string.hottest_posts, R.drawable.ic_whatshot_24px)
|
||||||
object Saved : Destination("saved", R.string.saved_posts)
|
object Saved : Destination("saved", R.string.saved_posts, R.drawable.ic_favorite_24px)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue