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

Guy Bieber

10/01/2020, 6:55 PM
What happened to Modifier.weight in alpha04
😱 2
😫 1
Copy code
with(ColumnScope) { Modifier.weight(1f) }
g

Guy Bieber

10/01/2020, 7:06 PM
well that touches a lot of code
r

Rudolf Tammekivi

10/01/2020, 7:11 PM
I guess if you change composable function to be ColumnScope.MyButton then you get it automatically. Also if you use it in Column composable for example.
☝️ 2
z

Zach Klippenstein (he/him) [MOD]

10/01/2020, 7:16 PM
I think that’s the point.
Modifier.weight
doesn’t have any effect outside of `Column`/`Row` composables, so this change is probably intended to help prevent using it where it’s pointless.
3
Or just change your child composables to take
Modifier
parameters, and pass the weight modifier in from wherever the `Column`/`Row` is.
3
💡 1
g

Guy Bieber

10/01/2020, 8:11 PM
The problem is inside a Column you still have to do a with statement. It makes the code longer needlessly.
This works:
Copy code
Column(with(ColumnScope) {Modifier.weight(.15f) }) {}
This does not:
Copy code
Column(Modifier.weight(.15f)) {}
Why inside a column would I need to declare this?
Just a lot of busy work.
If I add scope to the functions is the easiest way to clean it up. Probably a smart thing to do.
z

Zach Klippenstein (he/him) [MOD]

10/01/2020, 9:01 PM
Copy code
Column(with(ColumnScope) {Modifier.weight(.15f) }) {}
Here the
weight
modifier only does something if the parent of this
Column
is also a column or row. It doesn’t matter which composable you apply the modifier too, it matters what its parent is.
e.g. This gives you two columns, side-by-side, which each take up half the width:
Copy code
Row {
  Column(Modifier.weight(.5f)) { … }
  Column(Modifier.weight(.5f)) { … }
}
This gives you two columns which are stacked on top of each other, with whatever size they want to be (that is, the weight modifier has no effect:
Copy code
Box {
  Column(with(ColumnScope) { Modifier.weight(.5f) }) { … }
  Column(with(RowScope) { Modifier.weight(.5f) }) { … }
}