diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchBarViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchBarViewModel.kt index 15aa74ace..71bbe24c1 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchBarViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchBarViewModel.kt @@ -26,6 +26,7 @@ import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue +import androidx.compose.ui.focus.FocusRequester import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import com.vitorpamplona.amethyst.model.Account @@ -43,6 +44,7 @@ import kotlinx.coroutines.flow.asStateFlow class SearchBarViewModel( val account: Account, ) : ViewModel() { + val focusRequester = FocusRequester() var searchValue by mutableStateOf("") private var _searchResultsUsers = MutableStateFlow>(emptyList()) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchScreen.kt index 7730ab014..9c7f432d9 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/SearchScreen.kt @@ -52,7 +52,6 @@ import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalLifecycleOwner @@ -91,7 +90,6 @@ import com.vitorpamplona.amethyst.ui.theme.StdTopPadding import com.vitorpamplona.amethyst.ui.theme.placeholderText import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.FlowPreview -import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.distinctUntilChanged @@ -148,6 +146,10 @@ fun SearchScreen( val listState = rememberLazyListState() + LaunchedEffect(searchBarViewModel.focusRequester) { + searchBarViewModel.focusRequester.requestFocus() + } + DisappearingScaffold( isInvertedLayout = false, topBar = { @@ -234,15 +236,6 @@ private fun SearchTextField( modifier: Modifier, onTextChanges: (String) -> Unit, ) { - val focusRequester = remember { FocusRequester() } - - LaunchedEffect(Unit) { - launch { - delay(100) - focusRequester.requestFocus() - } - } - Row( modifier = modifier.padding(10.dp).fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, @@ -264,7 +257,7 @@ private fun SearchTextField( Modifier .weight(1f, true) .defaultMinSize(minHeight = 20.dp) - .focusRequester(focusRequester), + .focusRequester(searchBarViewModel.focusRequester), placeholder = { Text( text = stringRes(R.string.npub_hex_username),