https://kotlinlang.org logo
#compose
Title
# compose
f

Filip Stanis

01/25/2022, 6:32 PM
I'm wrapping a multiline
TextField
in a scrollable column and I realized that by default the column won't scroll to the bottom if it goes off screen. Attached gif of what I mean - the
TextField
grows until it reached the height of the
Column
, then it goes off-screen - but I can still scroll to it. Can I make the scroll position follow focus? I'd expected that to happen by default, maybe I'm doing something wrong?
Copy code
val scrollState by remember { mutableStateOf(ScrollState(0)) }
var value by remember { mutableStateOf("") }
Column(
    Modifier
        .padding(8.dp)
        .height(60.dp)
        .verticalScroll(scrollState)
) {
    BasicTextField(
        modifier = Modifier
            .fillMaxWidth()
            .background(Color.White)
            .padding(8.dp),
        value = value,
        onValueChange = { value = it }
    )
}
I guess I could call
scrollTo(Int.MAX_VALUE)
on every change of text. Not sure if that's ideal though.
29 Views