wintersoldier
04/12/2023, 2:01 PMChris Arriola
04/12/2023, 4:02 PMwintersoldier
04/12/2023, 4:20 PM@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))
}
Chris Arriola
04/12/2023, 4:47 PM2023.04.00
2023.04.00
and it appears to still be an issuewintersoldier
04/12/2023, 5:28 PMandylamax
04/16/2023, 8:06 AMChris Arriola
04/18/2023, 6:49 PM1.5.0-alpha02