Chris Grigg
03/18/2021, 8:58 PMBox
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.Chris Grigg
03/18/2021, 8:58 PM@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")
}
}
Zach Klippenstein (he/him) [MOD]
03/18/2021, 8:58 PMChris Grigg
03/18/2021, 8:59 PMscale(progress)
and uncomment the line below it and you’ll see that it works as expected.Chris Grigg
03/18/2021, 8:59 PMChris Grigg
03/18/2021, 9:07 PM