Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support tab active icon #511

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/navigation/tab-navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ object HomeTab : Tab {
get() {
val title = stringResource(R.string.home_tab)
val icon = rememberVectorPainter(Icons.Default.Home)
val activeIcon = rememberVectorPainter(Icons.Outlined.FavoriteBorder)

return remember {
TabOptions(
index = 0u,
title = title,
icon = icon
icon = icon,
activeIcon = activeIcon
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,16 @@ class TabNavigationActivity : ComponentActivity() {
BottomNavigationItem(
selected = tabNavigator.current.key == tab.key,
onClick = { tabNavigator.current = tab },
icon = { Icon(painter = tab.options.icon!!, contentDescription = tab.options.title) }
icon = {
Icon(
painter = if (tabNavigator.current.key == tab.key) {
tab.options.activeIcon!!
} else {
tab.options.icon!!
},
contentDescription = tab.options.title
)
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cafe.adriel.voyager.sample.tabNavigation.tabs

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.outlined.Favorite
import androidx.compose.material.icons.outlined.FavoriteBorder
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.vector.rememberVectorPainter
Expand All @@ -14,12 +16,14 @@ object FavoritesTab : Tab {
@Composable
get() {
val icon = rememberVectorPainter(Icons.Default.Favorite)
val activeIcon = rememberVectorPainter(Icons.Outlined.FavoriteBorder)

return remember {
TabOptions(
index = 1u,
title = "Favorites",
icon = icon
icon = icon,
activeIcon = activeIcon
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cafe.adriel.voyager.sample.tabNavigation.tabs

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.outlined.Home
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.vector.rememberVectorPainter
Expand All @@ -14,12 +15,14 @@ object HomeTab : Tab {
@Composable
get() {
val icon = rememberVectorPainter(Icons.Default.Home)
val activeIcon = rememberVectorPainter(Icons.Outlined.Home)

return remember {
TabOptions(
index = 0u,
title = "Home",
icon = icon
icon = icon,
activeIcon = activeIcon
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cafe.adriel.voyager.sample.tabNavigation.tabs

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.outlined.Person
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.vector.rememberVectorPainter
Expand All @@ -14,12 +15,14 @@ object ProfileTab : Tab {
@Composable
get() {
val icon = rememberVectorPainter(Icons.Default.Person)
val activeIcon = rememberVectorPainter(Icons.Outlined.Person)

return remember {
TabOptions(
index = 2u,
title = "Profile",
icon = icon
icon = icon,
activeIcon = activeIcon
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public fun CurrentTab() {
public data class TabOptions(
val index: UShort,
val title: String,
val icon: Painter? = null
val icon: Painter? = null,
val activeIcon: Painter? = null
)

public interface Tab : Screen {
Expand Down