forked from openMF/mifos-x-field-officer-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMifosNavigationBar.kt
More file actions
70 lines (67 loc) · 2.48 KB
/
Copy pathMifosNavigationBar.kt
File metadata and controls
70 lines (67 loc) · 2.48 KB
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
/*
* Copyright 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package cmp.navigation.components
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.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.sp
import cmp.navigation.navigation.HomeDestinationsScreen
@Composable
fun MifosNavigationBar(
route: String,
modifier: Modifier = Modifier,
onRouteSelected: (targetRoute: String) -> Unit,
) {
val tabs = rememberSaveable {
listOf(
HomeDestinationsScreen.SearchScreen,
HomeDestinationsScreen.ClientListScreen,
HomeDestinationsScreen.CenterListScreen,
HomeDestinationsScreen.GroupListScreen,
)
}
val isAnyTabSelected = remember(route) { tabs.any { route.contains(it.route) } }
NavigationBar(modifier = modifier) {
tabs.forEach { item ->
val targetRoute = item.route
val selected =
if (isAnyTabSelected) route.contains(targetRoute) else targetRoute == HomeDestinationsScreen.SearchScreen.route
NavigationBarItem(
icon = {
item.icon?.let {
Icon(
imageVector = it,
contentDescription = item.title,
tint = if (selected) Color.Black else Color.Black.copy(0.7f),
)
}
},
label = {
Text(
text = item.title,
maxLines = 1,
fontSize = 12.sp,
textAlign = TextAlign.Center,
color = if (selected) Color.Black else Color.Black.copy(0.7f),
)
},
selected = selected,
onClick = { onRouteSelected(targetRoute) },
)
}
}
}