Let's say I have two `@Composable () -> Unit` bloc...
# compose
j
Let's say I have two
@Composable () -> Unit
blocks and I need to animate (ideally using AnimatedContent or something similarly trivial) from one to another based on the fact it the first lambda "renders" anything. I hoped that new
GraphicsLayer
api would help here, yet I cannot come up with anything reasonable. The only implementation I was able to do was one based on subcomposition (in thread) or using nullable blocks, but that's the thing I want to rewrite. Any other ideas?
Copy code
SubcomposeLayout { constraints ->
        val errorPlaceable = subcompose("error") {
            error()
        }.firstOrNull()?.measure(constraints)
        val infoPlaceable = subcompose("info") {
            info()
        }.firstOrNull()?.measure(constraints)

        val hasError = errorPlaceable != null && errorPlaceable.height > 0
        val hasInfo = infoPlaceable != null && infoPlaceable.height > 0
        val state = when {
            hasError -> Message.Error(error)
            hasInfo -> <http://Message.Info|Message.Info>(info)
            else -> null
        }

        val messagePlaceable = subcompose("message") {
            AnimatedContent(state) { state -> ... }
        }.first().measure(constraints)

        layout(messagePlaceable.width, messagePlaceable.height) {
            messagePlaceable.placeRelative(0, 0)
        }
    }
b
Hoist the state that is determining if anything is rendered in error, info or message and use that to determine what to do instead?
j
yeah, that would work, but I'm not sure it is better. (in comparison to nullable lambdas.) I'm curious if this is solvable in compose with the signature I want: two nonnulable compose blocks.