make searchText non-saveable and add a comment

This commit is contained in:
Helium314 2025-03-31 20:12:52 +02:00
parent 452770566c
commit 7a57f5a24f

View file

@ -33,7 +33,6 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate import androidx.compose.ui.draw.rotate
@ -107,9 +106,12 @@ fun <T: Any?> SearchScreen(
menu: List<Pair<String, () -> Unit>>? = null, menu: List<Pair<String, () -> Unit>>? = null,
content: @Composable (ColumnScope.() -> Unit)? = null, content: @Composable (ColumnScope.() -> Unit)? = null,
) { ) {
var searchText by rememberSaveable(stateSaver = TextFieldValue.Saver) { mutableStateOf(TextFieldValue()) } // searchText and showSearch should have the same remember or rememberSaveable
Column(Modifier.fillMaxSize()) { // saveable survives orientation changes and switching between screens, but shows the
// keyboard in unexpected situations such as going back from another screen, which is rather annoying
var searchText by remember { mutableStateOf(TextFieldValue()) }
var showSearch by remember { mutableStateOf(false) } var showSearch by remember { mutableStateOf(false) }
Column(Modifier.fillMaxSize()) {
fun setShowSearch(value: Boolean) { fun setShowSearch(value: Boolean) {
showSearch = value showSearch = value