carbaj0
08/30/2020, 3:23 PM@Composable
private fun ZoomControls(
zoom: Float,
onZoomChanged: (Float) -> Unit
) {
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) {
ZoomButton("-", onClick = { onZoomChanged(zoom * 0.8f) })
ZoomButton("+", onClick = { onZoomChanged(zoom * 1.2f) })
}
}
ZoomControls(zoom) {
zoom = it.coerceIn(MinZoom, MaxZoom)
}
This is a bit confusing since being a Composable, I expect the lambda to be a content: @Composable () -> Unit
instead of a callback.Zach Klippenstein (he/him) [MOD]
08/30/2020, 3:40 PMremember
, Button
, TextField
, etc. It doesn't make sense for callbacks to be composable, since they represent events, not descriptions of UI.carbaj0
08/30/2020, 4:09 PMZach Klippenstein (he/him) [MOD]
08/30/2020, 4:14 PM@Composable
, so it’s clear it’s not a composable.
If it’s seeing code using the trailing lambda syntax, like ZoomControls(zoom) { … }
, that’s confusing, there I’d agree and would probably rather write the lambda inside the parenthesis with an explicit parameter name (I’d do this for all callbacks). It would be nice to have a lint check warning against using trailing lambda syntax for callbacks.Adam Powell
08/30/2020, 4:41 PMonCommit
is due for a rename and a rework as it's a Unit-returning composable function where its presence or absence in the composition is significant. Same as a button or dialog. Its body lambda is not @Composable
nor should it be. Nor would I want to add trailing fingernail clippings and avoid the trailing lambda syntax for itlaunchInComposition
OnBackPressedHandler