Is there a way to measure composable without ever ...
# compose
v
Is there a way to measure composable without ever displaying or using it? Use case is in 🧵
I'm trying to implement kind of ExposedDropdownMenu monolitic composable. Input has all the possible values for dropdown so I want this composable to be of default width as list of `DropdownMenuItem`'s.
Copy code
@Composable
fun <T> DropdownSelector(
    items: List<T>,
    selectedValue: T,
    onSelect: (T) -> Unit,
    toString: @Composable (T) -> String,
    modifier: Modifier = Modifier,
) {
    var expanded by remember { mutableStateOf(false) }
    
    Column(modifier = modifier) {
        Row(
            modifier = Modifier
                .clickable { expanded = !expanded }
                .padding(8.dp)
        ) {
            Text(
                text = toString(selectedValue),
                modifier = Modifier
                    .weight(1f)
                    .align(Alignment.CenterVertically)
            )
            Spacer(modifier = Modifier.width(8.dp))
            ExpandableChevron(isExpanded = expanded)
        }
        
        DropdownMenu(
            expanded = expanded,
            onDismissRequest = { expanded = false },
        ) {
            items.forEach { value ->
                DropdownMenuItem(onClick = {
                    onSelect(value)
                    expanded = false
                }) {
                    Text(toString(value))
                }
            }
        }
    }
}
By default it tries to occupy as much horizontal space as possible which is not what I want. And I don't want to hardcode some width because of scalable fonts and all
Tried
SubcomposeLayout
and got
IllegalStateException: Asking for intrinsic measurements of SubcomposeLayout layouts is not supported
with none of my code
k
v
Tried intrinsic min width, yes. I don't think it can be applied to this case. If I use it on composable I get the result on screenshot