slightly improve weird behavior

This commit is contained in:
Helium314 2025-02-11 22:16:18 +01:00
parent 9bb087b422
commit cb08d32d14
2 changed files with 5 additions and 2 deletions

View file

@ -113,6 +113,7 @@ fun <T: Any> SearchScreen(
) {
var searchText by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) }
Column(Modifier.fillMaxSize()) {
// todo: saving is good on orientation change, but bad on pressing back...
var showSearch by rememberSaveable { mutableStateOf(false) }
fun setShowSearch(value: Boolean) {
@ -120,7 +121,7 @@ fun <T: Any> SearchScreen(
if (!value) searchText = TextFieldValue()
}
BackHandler {
if (showSearch) setShowSearch(false)
if (showSearch || searchText.text.isNotEmpty()) setShowSearch(false)
else onClickBack()
}
Surface(

View file

@ -7,6 +7,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.LayoutDirection
import androidx.navigation.NavOptions
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
@ -100,7 +101,7 @@ fun SettingsNavHost(
ColorsScreen(isNight = true, onClickBack = ::goBack)
}
}
if (target.value != SettingsDestination.Settings)
if (target.value != SettingsDestination.Settings/* && target.value != navController.currentBackStackEntry?.destination?.route*/)
navController.navigate(route = target.value)
}
@ -128,5 +129,6 @@ object SettingsDestination {
navScope.launch { delay(10); navTarget.value = target }
} else
navTarget.value = target
navScope.launch { delay(50); navTarget.value = Settings }
}
}