Hey guys, I've noticed a bug in scrollable columns...
# compose
r
Hey guys, I've noticed a bug in scrollable columns when they have TextFields when I click on a TextField that will be below the screen when the keyboard shows up -> things gets messed up anyone encountered this? and is it a compose known bug, or something wrong with how I implemented it (doubt that)? code in the thread 🧵
Copy code
setContent {
            val parentScrollState = rememberScrollState()
            Scaffold(
                modifier = Modifier
                    .fillMaxSize()
                    .background(Color.White),
            ) {
                Column(
                    modifier = Modifier
                        .fillMaxSize()
                        .padding(it)
                ) {
                    Row(
                        modifier = Modifier
                            .fillMaxWidth()
                            .height(60.dp)
                            .background(color = Color.White)
                            .padding(horizontal = 16.dp, vertical = 12.dp),
                        horizontalArrangement = Arrangement.SpaceBetween,
                        verticalAlignment = Alignment.CenterVertically
                    ) {
                        Text(
                            text = "Testing",
                            style = TextStyle(
                                fontSize = 20.sp
                            ),
                            color = Color.Green,
                            maxLines = 1,
                            overflow = TextOverflow.Ellipsis
                        )
                    }
                    Column(
                        modifier = Modifier
                            .fillMaxSize()
                            .verticalScroll(parentScrollState)
                            .padding(16.dp)
                    ) {
                        repeat(20) {
                            TextField(it.toString(), {})
                            Spacer(modifier = Modifier.height(16.dp))
                        }
                    }
                }
            }
        }
I was able to fix this by positioning the focused text field and then scrolling to the field with
parentScrollState.scrollTo(textFieldOffset.y)
but thats not optimal, it should work out of the box
h
What is your activity's soft input method? Is it
ADJUST_PAN
or
ADJUST_RESIZE
, or something else? Are you handling window insets yourself? Do you call
enableEdgeToEdge
in your Activity?
And what things get messed up here? It is hard to understand what is going wrong from this recording. AFAICT the focused TextField stays on top of the keyboard.
r
Check the top bar
The whole screen gets pushes up, even the not scrollable parts
And i can’t scroll back down, maybe i did it too fast in the video so its not visible
h
that seems like you are using softInputMethod
ADJUST_PAN
. Can you try using
ADJUST_RESIZE
?
r
I went out for a bit, will check once I’m back But I don’t think this is the issue Because if I scroll down a bit before selecting a text field, it works fine (it scrolls to the needed field automatically) But if I’m at the top, it doesn’t scroll the list, but shifts the whole screen up
h
that is exactly how it should work if the adjustment is configured as panning. Since you are already at the top of your scrollable region, a focused TextField doesn't have many options to bring itself into view. At this point the activity takes control and pans its content enough to make TextField visible. When the activity pans the content, it doesn't become scrollable. To see the top bar again, you would have to close the keyboard.
https://developer.android.com/guide/topics/manifest/activity-element.html "adjustPan" The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.
r
yup you're right
I handle the
imePadding
almost everywhere my self, so I set it to
adjustNothing
and its fixed
🎉 1