I'm having some issues understanding how the layou...
# compose
s
I'm having some issues understanding how the layout work exactly. I have a LazyColumn that fills a part of the screen. If I wrap that in a SelectionContainer, it no longer fills the screen until there's enough content, and then it pushes the TextField off the screen. The following works as expected:
Copy code
Column(modifier = Modifier.fillMaxSize()) {
    LazyColumn(
        modifier = Modifier
            .fillMaxWidth()
            .weight(1f)
    ) {
        items(lines) { line ->
            Text(line)
        }
    }
    TextField(...)
}
If I put a SelectionContainer around the LazyColumn with the same modifier, it doesn't work as I expected. Anyone know why?
đź§µ 1
a
Modifier.weight()
only works on the direct children of a
Row
or
Column
.
SelectionContainer
is also a layout so setting weight on its children won't work.
In your case you need to use weight modifier on `SelectionContainer`:
Copy code
SelectionContainer(modifier = Modifier.weight(1f)) {
    LazyColumn(modifier = Modifier.fillMaxSize())
}
s
Ok, that makes sense. The problem is in that case, the
TextField
is pushed off the bottom of the screen and the
SelectionContainer
fills the entire window.
It seems that setting the weight on
SelectionContainer
does not do anything. It does not fill the remaining space.
There's probably a better way, but my solution was:
Copy code
BoxWithConstraints(modifier = Modifier.fillMaxWidth().weight(1f)) {
    val height = maxHeight
    SelectionContainer {
        LazyColumn(modifier = Modifier.fillMaxWidth().height(height)) { }
    }
}
a
It’s definitely an overkill to use
BoxWithConstraints
for something like this. I tried the code I posted above and it does work.