Make bottom nav icons part of destination classes

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-10-30 14:22:16 +05:30
parent 41521cca95
commit b195c0d203
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
2 changed files with 5 additions and 10 deletions

View file

@ -62,14 +62,7 @@ fun LobstersApp() {
val currentRoute = navBackStackEntry?.arguments?.getString(KEY_ROUTE)
destinations.forEach { screen ->
BottomNavigationItem(
icon = {
IconResource(
resourceId = when (screen) {
Destination.Hottest -> R.drawable.ic_whatshot_24px
Destination.Saved -> R.drawable.ic_favorite_24px
}
)
},
icon = { IconResource(resourceId = screen.badgeRes) },
label = { Text(stringResource(id = screen.labelRes)) },
selected = currentRoute == screen.route,
onClick = {

View file

@ -1,5 +1,6 @@
package dev.msfjarvis.lobsters.ui
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import dev.msfjarvis.lobsters.R
@ -9,7 +10,8 @@ import dev.msfjarvis.lobsters.R
sealed class Destination(
val route: String,
@StringRes val labelRes: Int,
@DrawableRes val badgeRes: Int,
) {
object Hottest : Destination("hottest", R.string.hottest_posts)
object Saved : Destination("saved", R.string.saved_posts)
object Hottest : Destination("hottest", R.string.hottest_posts, R.drawable.ic_whatshot_24px)
object Saved : Destination("saved", R.string.saved_posts, R.drawable.ic_favorite_24px)
}