Hey folks, I believe I just found a bug involving ...
# compose
c
Hey folks, I believe I just found a bug involving a
Box
with
scale
set to 0f and content with an
onClick
handler. When scale is 0f, the content’s
onClick
handler will be applied to the whole window. Reproducible code coming below, replying to myself.
Copy code
@Composable
private fun ShrinkAnimationContent(
    fade: Boolean,
    modifier: Modifier,
    progress: Float,
    content: @Composable () -> Unit,
) {
    Box(
        modifier = modifier
            .wrapContentSize()
            .scale(progress)
//            .scale(if (progress == 0f) 0.0001f else progress)
            .alpha(
                when {
                    fade -> progress
                    else -> 1f
                }
            )
    ) {
        content()
    }
}

@Preview
@Composable
private fun ShrinkAnimationContentBrokenPreview() {
    val (count, setCount) = remember { mutableStateOf(0) }

    Column(modifier = Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) {
        ShrinkAnimationContent(fade = false, modifier = Modifier, progress = 0f) {
            Button(onClick = { setCount(count.inc()) }) {
                Text("Click Me")
            }
        }
        Spacer(modifier = Modifier.requiredHeight(24.dp))
        Text("The count is $count")
    }
}
z
Did you file a bug? Tracker is linked in the channel topic
c
Try running that. You’ll find that you can tap anywhere on the screen and it will behave like you clicked the button. Then comment the
scale(progress)
and uncomment the line below it and you’ll see that it works as expected.
Haven’t filed yet, I literally just found it and it feels so crazy so I wanted to share in case someone could point out something I’m overlooking.