I'm trying to build an UI that contains a search bar inside a LazyColumn layout. The only problem is that the TextField loses focus if it is not at the top of the screen.
Code:
val listState = rememberLazyListState()
LazyColumn(
modifier = Modifier.padding(horizontal = 16.dp),
state = listState,
) {
items(7) { // it works with 5 items, but with 7 it doesn't
QuickStart()
}
var text by remember { mutableStateOf(value = "") }
TextField(
value = TextFieldValue(text = text),
onValueChange = { text = it.text }
)
}
I've shared gifs visualizing the issue.
Explanation: The TextField view gets focus and then loses it, therefore the system closes the keyboard.
Explanation: The view works as expected when there are not many elements above the TextField. It stops working after adding 7 elements above it.
Is there any solution, so that i can add the edittext somewhere further in the list?