basic bottom navbar setup
This commit is contained in:
parent
8ae7995a96
commit
a627a8b279
13 changed files with 226 additions and 6 deletions
|
|
@ -67,6 +67,9 @@ dependencies {
|
|||
// Optional - Integration with activities
|
||||
implementation(libs.androidx.activity.compose)
|
||||
|
||||
//Compose navigation
|
||||
implementation(libs.androidx.navigation.compose)
|
||||
|
||||
implementation(libs.androidx.core.ktx)
|
||||
implementation(libs.androidx.appcompat)
|
||||
implementation(libs.material)
|
||||
|
|
|
|||
|
|
@ -11,12 +11,7 @@ class MainActivity : ComponentActivity(){
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContent {
|
||||
NavigationBar()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun NavigationBar() {
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
package de.cdaut.dbtapp.components
|
||||
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.NavigationBar
|
||||
import androidx.compose.material3.NavigationBarItem
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import de.cdaut.dbtapp.navigation.BottomNavigationItem
|
||||
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
private fun BottomNavigationBar() {
|
||||
var navigationSelectedItem by remember {
|
||||
mutableIntStateOf(
|
||||
BottomNavigationItem().bottomNavigationItems()
|
||||
.find { item -> item.label == "Home" }!!.idx
|
||||
)
|
||||
}
|
||||
val navController = rememberNavController()
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
bottomBar = {
|
||||
NavigationBar {
|
||||
BottomNavigationItem().bottomNavigationItems().sortedBy { item -> item.idx }
|
||||
.forEachIndexed { index, item ->
|
||||
NavigationBarItem(
|
||||
selected = index == navigationSelectedItem,
|
||||
label = {
|
||||
if (index == navigationSelectedItem) {
|
||||
Text(item.label)
|
||||
}
|
||||
},
|
||||
icon = {
|
||||
Icon(
|
||||
item.icon,
|
||||
contentDescription = item.label
|
||||
)
|
||||
},
|
||||
onClick = {
|
||||
navigationSelectedItem = index
|
||||
navController.navigate(item.route) {
|
||||
popUpTo(navController.graph.findStartDestination().id)
|
||||
launchSingleTop = true
|
||||
restoreState = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
) { paddingVals ->
|
||||
Text("Test $paddingVals")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package de.cdaut.dbtapp.navigation
|
||||
|
||||
import android.content.res.Resources
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.MenuBook
|
||||
import androidx.compose.material.icons.filled.CalendarToday
|
||||
import androidx.compose.material.icons.filled.Checklist
|
||||
import androidx.compose.material.icons.filled.Home
|
||||
import androidx.compose.material.icons.filled.MenuBook
|
||||
import androidx.compose.material.icons.outlined.Star
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import de.cdaut.dbtapp.R
|
||||
import de.cdaut.dbtapp.navigation.BottomNavigationItem
|
||||
|
||||
data class BottomNavigationItem(
|
||||
val label: String = "",
|
||||
val icon: ImageVector = Icons.Filled.Home,
|
||||
val route: String = "",
|
||||
val idx: Int = 0
|
||||
) {
|
||||
fun bottomNavigationItems(): List<BottomNavigationItem> {
|
||||
return listOf(
|
||||
BottomNavigationItem(
|
||||
label = Resources.getSystem().getString(R.string.label_tracking),
|
||||
icon = Icons.Filled.CalendarToday,
|
||||
route = Screens.Tracking.route,
|
||||
idx = 0
|
||||
),
|
||||
BottomNavigationItem(
|
||||
label = Resources.getSystem().getString(R.string.label_skillslist),
|
||||
icon = Icons.AutoMirrored.Filled.MenuBook,
|
||||
route = Screens.Skillslist.route,
|
||||
idx = 1
|
||||
),
|
||||
BottomNavigationItem(
|
||||
label = Resources.getSystem().getString(R.string.label_home),
|
||||
icon = Icons.Filled.Home,
|
||||
route = Screens.Home.route,
|
||||
idx = 2
|
||||
),
|
||||
BottomNavigationItem(
|
||||
label = Resources.getSystem().getString(R.string.label_favourites),
|
||||
icon = Icons.Outlined.Star,
|
||||
route = Screens.Favourites.route,
|
||||
idx = 3
|
||||
),
|
||||
BottomNavigationItem(
|
||||
label = Resources.getSystem().getString(R.string.label_skillschains),
|
||||
icon = Icons.Filled.Checklist,
|
||||
route = Screens.Skillschains.route,
|
||||
idx = 4
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package de.cdaut.dbtapp.navigation
|
||||
|
||||
sealed class Screens(val route: String) {
|
||||
object Home : Screens("home_route")
|
||||
object Tracking : Screens("tracking_route")
|
||||
object Skillslist : Screens("skillslist_route")
|
||||
object Favourites : Screens("favourites_route")
|
||||
object Skillschains : Screens("skillschains_route")
|
||||
}
|
||||
9
DBTApp/app/src/main/res/values-de/strings.xml
Normal file
9
DBTApp/app/src/main/res/values-de/strings.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">DBTApp</string>
|
||||
<string name="label_home">Home</string>
|
||||
<string name="label_skillslist">Skills</string>
|
||||
<string name="label_tracking">Tracking</string>
|
||||
<string name="label_favourites">Favoriten</string>
|
||||
<string name="label_skillschains">Skillsketten</string>
|
||||
</resources>
|
||||
|
|
@ -1,3 +1,8 @@
|
|||
<resources>
|
||||
<string name="app_name">DBTApp</string>
|
||||
<string name="label_home">Home</string>
|
||||
<string name="label_skillslist">Skillslist</string>
|
||||
<string name="label_tracking">Tracking</string>
|
||||
<string name="label_favourites">Favourites</string>
|
||||
<string name="label_skillschains">Skills Chains</string>
|
||||
</resources>
|
||||
Loading…
Add table
Add a link
Reference in a new issue