Hello! I've recently upgraded my compose-bom from ...
# compose
w
Hello! I've recently upgraded my compose-bom from version 2022.12.00 to 2023.03.00, and now I'm experiencing issues with my AndroidView within a ConstraintLayout. Currently for the compostables, constraints are not getting applied, Could anyone please assist me in identifying the problem.
c
Have you filed an issue about this and do you have a code snippet to share?
Will surface this feedback to eng once I get more context
w
I haven’t filed an issue yet, which I can do soon. Sharing the code snippet,
Copy code
@Composable
fun RandomColorAndroidView(modifier: Modifier = Modifier) {
    AndroidView(
        modifier = modifier,
        factory = { context ->
            FrameLayout(context).apply {
                setBackgroundColor(getRandomColor())
            }
        },
        update = { view ->
            // update the view if needed
        },
    )
}
Copy code
@Composable
fun RandomColorFrameLayoutsInConstraintLayout() {
    ConstraintLayout(
        modifier = Modifier
            .fillMaxSize()
            .background(MaterialTheme.colors.background)
    ) {
        val (androidView1Ref, androidView2Ref, androidView3Ref) = createRefs()
Copy code
RandomColorAndroidView(
            modifier = Modifier
                .size(50.dp)
                .constrainAs(androidView1Ref) {
                    start.linkTo(parent.start)
                    top.linkTo(<http://parent.top|parent.top>)
                    bottom.linkTo(parent.bottom)
                }
        )
        RandomColorAndroidView(
            modifier = Modifier
                .size(40.dp)
                .constrainAs(androidView2Ref) {
                    start.linkTo(androidView1Ref.end)
                    top.linkTo(<http://parent.top|parent.top>)
                    bottom.linkTo(parent.bottom)
                }
        )
        RandomColorAndroidView(
            modifier = Modifier
                .size(30.dp)
                .constrainAs(androidView3Ref) {
                    start.linkTo(androidView2Ref.end)
                    top.linkTo(<http://parent.top|parent.top>)
                    bottom.linkTo(parent.bottom)
                }
        )
    }
}
Copy code
private fun getRandomColor(): Int {
    val hue = Random.nextInt(360)
    val saturation = Random.nextFloat()
    val value = Random.nextFloat()
    return ColorUtils.HSLToColor(floatArrayOf(hue.toFloat(), saturation, value))
}
Please refer the above link for screenshots.
c
…which is fixed in the april release. can you test using the latest BOM?
2023.04.00
actually, i just tested on
2023.04.00
and it appears to still be an issue
i can file this on your behalf'
w
Thanks
a
#compose-android
c
FYI this issue is fixed in
1.5.0-alpha02