Fix layout spacing and state handling in new UI: ensure bottom bar always visible via Scaffold, use rememberSaveable for selectedTab with fallback to 'home', remove duplicate innerPadding usage causing blank space under top bar, keep map and list cached between tab switches to avoid reloads, nearby list now shows cached results immediately and refreshes in background.

This commit is contained in:
2025-10-02 12:37:47 +02:00
parent 085e147862
commit cc4a99effb

View File

@@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
@@ -51,6 +52,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@@ -316,7 +318,7 @@ fun KlottrAppShell(
}
) { padding ->
if (useNewUi) {
var selectedTab by remember { mutableStateOf("home") }
var selectedTab by rememberSaveable { mutableStateOf("home") }
Scaffold(
topBar = {
CenterAlignedTopAppBar(
@@ -368,9 +370,12 @@ fun KlottrAppShell(
},
floatingActionButtonPosition = androidx.compose.material3.FabPosition.Center,
content = { innerPadding ->
if (selectedTab !in listOf("home", "nearby", "menu")) {
selectedTab = "home"
}
// VIKTIGT: vi komponerar ALLA flikar alltid, och växlar bara synlighet.
// => MapContent förstörs inte när du byter flik, så kartan slipper “blinka”.
Box(Modifier.fillMaxSize()) {
Box(Modifier.fillMaxSize().consumeWindowInsets(innerPadding)) {
// === HEM ===
Box(
@@ -508,7 +513,7 @@ fun KlottrAppShell(
}
// Layout (övre halvan karta, undre halvan lista). Vi ger innerPadding här.
Column(Modifier.fillMaxSize().padding(innerPadding)) {
Column(Modifier.fillMaxSize()) {
// Övre halvan: karta (ligger kvar i minnet eftersom hela lagret alltid finns)
Box(modifier = Modifier.weight(1f).fillMaxWidth()) {
MapContent(