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

Tab navigation icon issue #504

Open
the-best-is-best opened this issue Oct 28, 2024 · 0 comments
Open

Tab navigation icon issue #504

the-best-is-best opened this issue Oct 28, 2024 · 0 comments

Comments

@the-best-is-best
Copy link

the-best-is-best commented Oct 28, 2024

package au.nd52solution.ethnic.features.home.tabs

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.text.BasicText
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountBox
import androidx.compose.material.icons.filled.History
import androidx.compose.material.icons.filled.Home
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import cafe.adriel.voyager.navigator.tab.Tab
import cafe.adriel.voyager.navigator.tab.TabOptions

object AccountTab : Tab {
override val options: TabOptions
@composable
get() {
val title = "History"
val icon = rememberVectorPainter(Icons.Default.AccountBox)

        return remember {
            TabOptions(
                index = 0u,
                title = title,
                icon  = icon
            )
        }
    }

@Composable
override fun Content() {
    BasicText("Home Tab Content", modifier = Modifier.fillMaxSize())
}

}
package au.nd52solution.ethnic.features.home

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import au.nd52solution.ethnic.features.home.tabs.AccountTab
import au.nd52solution.ethnic.features.home.tabs.AvailabilityTab
import au.nd52solution.ethnic.features.home.tabs.HistoryTab
import au.nd52solution.ethnic.features.home.tabs.HomeTab
import cafe.adriel.voyager.core.screen.Screen
import cafe.adriel.voyager.navigator.tab.CurrentTab
import cafe.adriel.voyager.navigator.tab.Tab
import cafe.adriel.voyager.navigator.tab.TabNavigator

class HomeScreen: Screen {
@composable
override fun Content() {
TabNavigator(HomeTab) {tabNavigator ->
Scaffold(
content = {
CurrentTab()
},
bottomBar = {
BottomNavigationBar(tabNavigator)
}
)
}

}

}

@composable
fun BottomNavigationBar(tabNavigator: TabNavigator) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp),
horizontalArrangement = Arrangement.SpaceEvenly,
verticalAlignment = Alignment.CenterVertically
) {
// Create a custom "bottom navigation item" for each tab
BottomNavItem(tab = HomeTab, tabNavigator = tabNavigator)
BottomNavItem(tab = HistoryTab, tabNavigator = tabNavigator)
BottomNavItem(tab = AvailabilityTab, tabNavigator = tabNavigator)
BottomNavItem(tab = AccountTab, tabNavigator = tabNavigator)

}

}

@composable
fun BottomNavItem(tab: Tab, tabNavigator: TabNavigator) {
val isSelected = tabNavigator.current == tab
val color = if (isSelected) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onBackground

Column(
    modifier = Modifier
        .clickable { tabNavigator.current = tab }
        .padding(8.dp),
    horizontalAlignment = Alignment.CenterHorizontally
) {
    Box(
        modifier = Modifier
            .size(24.dp)
            .background(color)
    )
    Text(
        text = tab.options.title,
        color = color,
        style = MaterialTheme.typography.bodyMedium
    )
}

} icons not display

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant