4

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.

Not Working Example

Explanation: The view works as expected when there are not many elements above the TextField. It stops working after adding 7 elements above it.

Working Example

Is there any solution, so that i can add the edittext somewhere further in the list?

  • 1
    upgrade androidx.compose.foundation:foundation to 1.4.0-beta01 solves this issue. https://issuetracker.google.com/issues/179203700 – bilabila Feb 16 '23 at 08:18

0 Answers0