Zach Klippenstein (he/him) [MOD]
08/10/2024, 6:32 PMModifier.weight
is intended to distribute "available space", and if the width constraint is infinity, then it can't do that (ā / anything = ā, and nodes can't have infinite measured width). If so, i'll file a CL to update the documentation.Stylianos Gakis
08/10/2024, 11:38 PMZach Klippenstein (he/him) [MOD]
08/11/2024, 12:23 AMStylianos Gakis
08/11/2024, 3:04 AMZach Klippenstein (he/him) [MOD]
08/11/2024, 3:07 PMStylianos Gakis
08/11/2024, 3:15 PMZach Klippenstein (he/him) [MOD]
08/11/2024, 3:40 PMHStack
and VStack
šStylianos Gakis
08/11/2024, 3:42 PMshikasd
08/11/2024, 4:17 PMZach Klippenstein (he/him) [MOD]
08/11/2024, 4:19 PMimport cursedlayouts.*
Zach Klippenstein (he/him) [MOD]
08/11/2024, 4:36 PMMeasurePolicy
classes or helper functions.
Eg if we had something like this:
interface ScopedMeasurePolicy<ContentScopeT> : MeasurePolicy {
val contentScope: ContentScopeT
}
@Composable
inline fun <ContentScopeT> Layout(
measurePolicy: ScopedMeasurePolicy<ContentScopeT>,
modifier: Modifier,
content: @Composable ContentScopeT.() -> Unit
)
Then we could provide stuff like:
open class StackMeasurePolicy(
val orientation: Orientation,
val defaultChildWeight: Float = Unspecified,
ā¦
): ScopedMeasurePolicy<StackScope> {
override val contentScope get() = StackScope
object StackScope {
fun Modifier.weight(ā¦): Modifier
fun Modifier.weightUnspecified(): Modifier
ā¦
}
But probably with more extension points, injectable logic for certain things, etc. Consumers can then just pass an instance to that layout composable:
@Composable
fun MySpecialRow(
modifier: Modifier = Modifier,
content: StackScope.() -> Unit
) {
val measurePolicy = remember {
StackMeasurePolicy(ā¦)
}
Layout(measurePolicy, modifier, content)
}
Zach Klippenstein (he/him) [MOD]
08/11/2024, 6:54 PMStylianos Gakis
08/11/2024, 7:43 PMColumn {
Stuff()
Spacer(weight(1f))
Spacer(height(8.dp))
MoreStuff()
}
To fight this. Because the weight can always evaluate to 0.dp and then they touch and basically it never is what we actually want in the places we put the weight inZach Klippenstein (he/him) [MOD]
08/12/2024, 2:57 PMweight
means ātake a fraction of the available spaceā, and 0-ā¾ļø constraints means ābe your natural sizeā, then the natural āavailableā width is the sum of all the childrenās max intrinsic widths, because the total width canāt be more than that. Iām mostly convinced this makes sense, but itās definitely arguable.
More importantly however, thatās moot because itās probably way too late to change this behavior for Row/Column.Zach Klippenstein (he/him) [MOD]
08/12/2024, 2:58 PMweight
modifier itself. Who would think to look at the weight modifier kdoc for information about weight behavior anyway? š So Iāll still fix this.Zach Klippenstein (he/him) [MOD]
08/12/2024, 2:59 PMZach Klippenstein (he/him) [MOD]
08/12/2024, 4:49 PMZach Klippenstein (he/him) [MOD]
08/12/2024, 5:51 PM@Composable
inline fun LinearLayout(content: @Composable () -> Unit)
š§