Jeevan Deep Singh
04/10/2023, 10:52 AMcompose-bom
to 2023.03.00
from 2022.12.00
, and my AndroidView
inside constraintLayout
has started breaking.
can someone help me figuring out the issue?
attaching screenshot and minimal code to reproduce the issue in the threadJeevan Deep Singh
04/10/2023, 10:53 AM@Composable
fun RandomColorAndroidView(modifier: Modifier = Modifier) {
AndroidView(
modifier = modifier,
factory = { context ->
FrameLayout(context).apply {
setBackgroundColor(getRandomColor())
}
},
update = { view ->
// update the view if needed
},
)
}
@Composable
fun RandomColorFrameLayoutsInConstraintLayout() {
ConstraintLayout(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colors.background)
) {
val (androidView1Ref, androidView2Ref, androidView3Ref) = createRefs()
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)
}
)
}
}
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))
}
Jeevan Deep Singh
04/10/2023, 10:53 AM2022.12.00
Jeevan Deep Singh
04/10/2023, 10:54 AM2023.03.00