fix: preserve tab on back and avoid nav bar overlap (0.4.5)
Keep the selected bottom tab when returning from host/event detail screens. Add navigation bar padding on scrollable detail screens. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -13,8 +13,8 @@ android {
|
||||
applicationId = "ru.kalinamall.seaca"
|
||||
minSdk = 26
|
||||
targetSdk = 35
|
||||
versionCode = 7
|
||||
versionName = "0.4.3"
|
||||
versionCode = 9
|
||||
versionName = "0.4.5"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
||||
@@ -28,6 +28,8 @@ import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.mutableStateOf as composeMutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
@@ -162,6 +164,8 @@ private fun SeacaApp(
|
||||
val role = repo.session.getRole()
|
||||
role == "operator" || role == "admin"
|
||||
}
|
||||
var mainTabIndex by rememberSaveable { mutableIntStateOf(MainTab.Dashboard.ordinal) }
|
||||
val mainTab = MainTab.entries[mainTabIndex.coerceIn(MainTab.entries.indices)]
|
||||
|
||||
SeacaTheme {
|
||||
if (!loggedIn) {
|
||||
@@ -183,6 +187,8 @@ private fun SeacaApp(
|
||||
composable("main") {
|
||||
MainShell(
|
||||
repo = repo,
|
||||
selectedTab = mainTab,
|
||||
onTabSelected = { mainTabIndex = it.ordinal },
|
||||
onOpenEvent = { nav.navigate("event/$it") },
|
||||
onOpenProblem = { nav.navigate("problem/$it") },
|
||||
onOpenHost = { nav.navigate("host/$it") },
|
||||
@@ -231,20 +237,20 @@ private enum class MainTab(val label: String) {
|
||||
@Composable
|
||||
private fun MainShell(
|
||||
repo: SacRepository,
|
||||
selectedTab: MainTab,
|
||||
onTabSelected: (MainTab) -> Unit,
|
||||
onOpenEvent: (Long) -> Unit,
|
||||
onOpenProblem: (Long) -> Unit,
|
||||
onOpenHost: (Long) -> Unit,
|
||||
onOpenDevice: () -> Unit,
|
||||
) {
|
||||
var tab by remember { mutableStateOf(MainTab.Dashboard) }
|
||||
|
||||
Scaffold(
|
||||
bottomBar = {
|
||||
NavigationBar {
|
||||
MainTab.entries.forEach { item ->
|
||||
NavigationBarItem(
|
||||
selected = tab == item,
|
||||
onClick = { tab = item },
|
||||
selected = selectedTab == item,
|
||||
onClick = { onTabSelected(item) },
|
||||
icon = {
|
||||
Icon(
|
||||
when (item) {
|
||||
@@ -270,7 +276,7 @@ private fun MainShell(
|
||||
},
|
||||
) { padding ->
|
||||
Box(Modifier.padding(padding)) {
|
||||
when (tab) {
|
||||
when (selectedTab) {
|
||||
MainTab.Dashboard -> DashboardScreen(repo)
|
||||
MainTab.Events -> EventsScreen(repo, onOpenEvent)
|
||||
MainTab.Problems -> ProblemsScreen(repo, onOpenProblem)
|
||||
|
||||
@@ -5,6 +5,7 @@ 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.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
@@ -215,7 +216,8 @@ fun DeviceScreen(repo: SacRepository, onLogout: () -> Unit) {
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(16.dp),
|
||||
.padding(16.dp)
|
||||
.navigationBarsPadding(),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
Text("Моё устройство", style = MaterialTheme.typography.titleLarge)
|
||||
@@ -275,7 +277,8 @@ private fun DetailFrame(
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(16.dp),
|
||||
.padding(16.dp)
|
||||
.navigationBarsPadding(),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
Button(onClick = onBack) { Text("Назад") }
|
||||
|
||||
Reference in New Issue
Block a user