Lucas Kivi
01/10/2023, 12:38 AMCircularProgressIndicator and Text. I want the button to stay the same size across content changes. This is easy enough if we just convert the text size in Sp to Dp and set the CircularProgressIndicator ’s size padding accordingly. However, when we consider that the text may become multiple lines when font size is increased for accessibility this solution no longer works.
I am considering building a SubcomposeLayout implementation that measures the Text and sets the button height accordingly and then can conditionally forego placing the Text . This seems a little computationally expensive. I don’t think Intrinsics will solve my problem. Does anyone have a suggestion for me before I build out my abstract SubcomposeLayout solution?Francesc
01/10/2023, 12:48 AMConstraints.fixed(width = constraints.maxWidth, height = max(all children height))
then lay one child or the other based on your logicFrancesc
01/10/2023, 12:50 AMLucas Kivi
01/10/2023, 12:51 AMLucas Kivi
01/10/2023, 12:51 AMLucas Kivi
01/10/2023, 12:51 AMLayout, right?Francesc
01/10/2023, 12:52 AMBox to wrap both childrenLucas Kivi
01/10/2023, 12:56 AMBox how do you extract it’s Intrinsic height prior to Composition?
For example we want to see the height of height of the Text here
Box {
Text("Intrinsics are fun")
}Francesc
01/10/2023, 12:57 AMBox (or CrossFade) if your height is fixed. If not, use a layout, then use the measure the required height use maxIntrinsicHeight for each composable, then use the max of those heights to set the actual height of the Layout. See this https://developer.android.com/jetpack/compose/layouts/intrinsic-measurements#intrinsics-in-layoutsLucas Kivi
01/10/2023, 12:58 AMSpFrancesc
01/10/2023, 1:00 AMLucas Kivi
01/10/2023, 1:01 AMLucas Kivi
01/10/2023, 1:01 AMAhaisting
01/10/2023, 1:03 AMalpha on the Text as a simple hack… probably doesn’t satiate you, but nobody has to know 😸Lucas Kivi
01/10/2023, 1:04 AMLucas Kivi
01/10/2023, 1:11 AMText and the CircularProgressIndicator into the Layout , measure them, and then withhold placement of one or the other. It seems difficult to do this robustly using Intrinsics .Lucas Kivi
01/10/2023, 1:12 AMLucas Kivi
01/10/2023, 1:12 AMAlex Vanyo
01/10/2023, 1:23 AMthen can conditionally forego placingThat’s probably the cleanest solution, and no need to use
SubcomposeLayout or anything!Alex Vanyo
01/10/2023, 1:26 AMplace by passing a Modifier to the component you want to take up space, but don’t show:
Modifier.layout {
val placeable = measurable.measure(constraints)
layout(placeable.measuredWidth, placeable.measuredHeight) {
if (showProgressIndicator) {
placeable.place(0, 0)
}
}
}Lucas Kivi
01/10/2023, 1:35 AMLucas Kivi
01/10/2023, 1:35 AMAlex Vanyo
01/10/2023, 1:36 AMif (showProgressIndicator) {
Modifier
} else {
Modifier.layout {
val placeable = measurable.measure(constraints)
layout(placeable.measuredWidth, placeable.measuredHeight) {}
}
}Lucas Kivi
01/10/2023, 1:39 AMAlex Vanyo
01/10/2023, 1:42 AMLucas Kivi
01/10/2023, 1:43 AMLucas Kivi
01/10/2023, 1:52 AM