-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBottomNavigation.kt
79 lines (73 loc) · 2.74 KB
/
BottomNavigation.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.app.whakaara.ui.navigation
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.navigation.NavController
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.compose.rememberNavController
import com.whakaara.core.RootScreen
import com.whakaara.core.designsystem.theme.FontScalePreviews
import com.whakaara.core.designsystem.theme.ThemePreviews
import com.whakaara.core.designsystem.theme.WhakaaraTheme
@Composable
fun BottomNavigation(
navController: NavController,
currentSelectedScreen: RootScreen
) {
val navItems = listOf(
BottomNavItem.Alarm,
BottomNavItem.Timer,
BottomNavItem.Stopwatch
)
NavigationBar(
containerColor = Color.Transparent
) {
navItems.forEach { item ->
NavigationBarItem(
selected = currentSelectedScreen == item.rootScreen,
icon = { Icon(imageVector = item.icon, contentDescription = item.title) },
label = { Text(text = item.title) },
onClick = {
navController.navigateToRootScreen(item.rootScreen)
// Not working with deeplinks
// https://stackoverflow.com/questions/68456471/jetpack-compose-bottom-bar-navigation-not-responding-after-deep-linking
// https://github.com/android/architecture-components-samples/issues/1003
// https://issuetracker.google.com/issues/194301895
// https://slack-chats.kotlinlang.org/t/16380212/hello-i-have-a-question-related-to-deep-links-handling-with-
// {
// navController.graph.startDestinationRoute?.let { screenRoute ->
// popUpTo(screenRoute) {
// saveState = true
// }
// }
// launchSingleTop = true
// restoreState = true
// }
}
)
}
}
}
fun NavController.navigateToRootScreen(rootScreen: RootScreen) {
navigate(rootScreen.route) {
launchSingleTop = true
restoreState = true
popUpTo(graph.findStartDestination().id) {
saveState = true
}
}
}
@Composable
@ThemePreviews
@FontScalePreviews
fun BottomNavigationPreview() {
WhakaaraTheme {
BottomNavigation(
navController = rememberNavController(),
currentSelectedScreen = RootScreen.Alarm
)
}
}