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

Fudge

08/29/2021, 5:50 PM
Consider the `FancyTextField`:
Copy code
@Composable
fun FancyTextField(value: String, onValueChange: (String) -> Unit, modifier: Modifier = Modifier) {
    Column(modifier) {
        TextField(value, onValueChange)
        Text("fancy!")
    }
}
While looking innocent, this code breaks the passed modifiers. If I pass for example
Modifier.fillMaxWidth()
, then only the
Column
will have expanded width, and the
TextField
will stay the same size, meaning that
fillMaxWidth
will not make
FancyTextField
fill max width (in practice). Obviously passing a modifier to
TextFIeld
(instead or in addition) won't work well. So how should
FancyTextField
be declared in such a way that modifiers work as expected?
a

Adam Powell

08/29/2021, 6:29 PM
You'll want to file a feature request to add a parameter to row/column to propagate the cross-axis minimum size to children. I thought we had this, apparently not
a custom
Layout
that arranges things in a column that propagates this is pretty simple to write until then, provided you don't need to also implement weight and alignment lines like the stock
Column
does
f

Fudge

08/29/2021, 6:33 PM
I see what you mean. I tried to implement a full-blown Column with alignment and all (on a different platform) a while ago and it was not easy 😅
a

Adam Powell

08/29/2021, 6:38 PM
yeah, but the basic version you seem to want here shouldn't be more than 12-20 lines of code or so 🙂
a bit more if you want to make this behavior controllable per-child via modifiers in your own custom layout scope or something, but depending on the use case it's probably not necessary
z

Zach Klippenstein (he/him) [MOD]

08/29/2021, 10:42 PM
Please post the issue here once you file it so future readers finding this thread can star it 🙂
☝️ 1
f

Fudge

08/30/2021, 7:32 AM
good idea https://issuetracker.google.com/issues/198064320 Although I note that this issue is quite unsearchable. I couldn't describe it as a simple phrase.