What is the alternative to intrinsics. I am getti...
# compose
d
What is the alternative to intrinsics. I am getting an error with using it with a complex view which does not support intrinsics
Java.lang.IllegalStateException: Asking for intrinsic measurements of SubcomposeLayout layouts is not supported. This includes components that are built on top of SubcomposeLayout, such as lazy lists, BoxWithConstraints, TabRow, etc. To mitigate this: - if intrinsic measurements are used to achieve 'match parent' sizing,, consider replacing the parent of the component with a custom layout which controls the order in which children are measured, making intrinsic measurement not needed - adding a size modifier to the component, in order to fast return the queried intrinsic measurement.
I am not trying to do match parent and size isnt going to work for me
k
“What is the alternative to intrinsics” - what is it that you’re trying to do? It’s difficult to suggest an alternative without any context.
d
Here is the example using intrinsics. If I use MarxistRow. Then inside have a BoxWithConstraints like below it crashes
Copy code
BoxWithConstraints(
    modifier = Modifier
        .fillMaxWidth()
) {
    val maxWidth = with(LocalDensity.current) {
        constraints.maxWidth.toDp()
    }
    Column {
        Text(
            modifier = Modifier.padding(bottom = 2.dp),
            text = "Test",
        )
    }
}
The example of using BoxWithConstraints is trivial but I have a bunch of things that violate the intrinsics limitations. So want to know what the alternative for intrinsics is to solve the same use case that marxistrow
k
But again, what is the use case?
d
I want to wrap everything with MarxistRow. The reason why I need that is https://kotlinlang.slack.com/archives/CJLTWPH7S/p1668110705848269?thread_ts=1668110653.982419&cid=CJLTWPH7S So maybe is it possible to create the MarxistRow without intrinsics
z
It’s not, efficiently. It uses them for a reason.
k
I don’t think you can create a general-purpose container that can host any possible child composables, unless you have something “trivial” like a
Box
.
And again, I’m still not clear on what is the use case. Wrapping everything in a certain container composable is a solution, but what is the problem?
d
Yeah I guess I am looking for a general purpose container which like you said is not possible. Essentially I want a row that lays out the components like it was done in the above kotlin slack(Which has the use case). So I want to use that new row instead of the existing row in compose. Sounds like its just not possible
k
At some point you will run into a circular problem along the lines of “the parent will expand to fit the tallest child, while the only child wants to be exactly half as tall as the parent”, or nesting scrollable containers, or any other similar loop where the parent needs info from the children to lay them out, and the children need info from the parent to decide how much space they want.
2243 Views