mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-28 23:53:03 +02:00
Do not bring the keyboard when the search field reappears.
This commit is contained in:
@@ -26,6 +26,7 @@ import androidx.compose.runtime.derivedStateOf
|
|||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
@@ -43,6 +44,7 @@ import kotlinx.coroutines.flow.asStateFlow
|
|||||||
class SearchBarViewModel(
|
class SearchBarViewModel(
|
||||||
val account: Account,
|
val account: Account,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
val focusRequester = FocusRequester()
|
||||||
var searchValue by mutableStateOf("")
|
var searchValue by mutableStateOf("")
|
||||||
|
|
||||||
private var _searchResultsUsers = MutableStateFlow<List<User>>(emptyList())
|
private var _searchResultsUsers = MutableStateFlow<List<User>>(emptyList())
|
||||||
|
@@ -52,7 +52,6 @@ import androidx.compose.runtime.rememberCoroutineScope
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
|
||||||
import androidx.compose.ui.focus.focusRequester
|
import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalLifecycleOwner
|
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 com.vitorpamplona.amethyst.ui.theme.placeholderText
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.FlowPreview
|
import kotlinx.coroutines.FlowPreview
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
import kotlinx.coroutines.flow.debounce
|
import kotlinx.coroutines.flow.debounce
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
@@ -148,6 +146,10 @@ fun SearchScreen(
|
|||||||
|
|
||||||
val listState = rememberLazyListState()
|
val listState = rememberLazyListState()
|
||||||
|
|
||||||
|
LaunchedEffect(searchBarViewModel.focusRequester) {
|
||||||
|
searchBarViewModel.focusRequester.requestFocus()
|
||||||
|
}
|
||||||
|
|
||||||
DisappearingScaffold(
|
DisappearingScaffold(
|
||||||
isInvertedLayout = false,
|
isInvertedLayout = false,
|
||||||
topBar = {
|
topBar = {
|
||||||
@@ -234,15 +236,6 @@ private fun SearchTextField(
|
|||||||
modifier: Modifier,
|
modifier: Modifier,
|
||||||
onTextChanges: (String) -> Unit,
|
onTextChanges: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val focusRequester = remember { FocusRequester() }
|
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
|
||||||
launch {
|
|
||||||
delay(100)
|
|
||||||
focusRequester.requestFocus()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = modifier.padding(10.dp).fillMaxWidth(),
|
modifier = modifier.padding(10.dp).fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
@@ -264,7 +257,7 @@ private fun SearchTextField(
|
|||||||
Modifier
|
Modifier
|
||||||
.weight(1f, true)
|
.weight(1f, true)
|
||||||
.defaultMinSize(minHeight = 20.dp)
|
.defaultMinSize(minHeight = 20.dp)
|
||||||
.focusRequester(focusRequester),
|
.focusRequester(searchBarViewModel.focusRequester),
|
||||||
placeholder = {
|
placeholder = {
|
||||||
Text(
|
Text(
|
||||||
text = stringRes(R.string.npub_hex_username),
|
text = stringRes(R.string.npub_hex_username),
|
||||||
|
Reference in New Issue
Block a user