Zoltan Demant
02/16/2024, 11:23 AMcoil3
). Id like to make the image clickable sometimes, but Im not sure what the best approach is. More details in 🧵Zoltan Demant
02/16/2024, 11:26 AMModifier.clickable
to my composable, but compose best practices tells me that this is likely a bad idea (I should apply the modifier to the root composable). I do like that its flexible though.
• My earlier approach was to simply declare onClick: (() -> Unit)?
for my composable, this makes the functionality clear, but I also end adding more and more to it over time.Zoltan Demant
02/16/2024, 11:28 AMZoltan Demant
02/16/2024, 11:28 AM@Composable
fun Awesomeness(
title: String?,
modifier: Modifier = Modifier,
) {
AnimatedContent(title) { current ->
if (current != null) {
Circle(
modifier = modifier, // nested usage
color = Color.Blue,
size = 40.dp,
content = {
Text(current)
},
)
} else {
Indicator(
modifier = modifier, // nested usage
size = Small,
)
}
}
}
Ian Lake
02/16/2024, 3:09 PMZoltan Demant
02/16/2024, 3:34 PMwhen (state) {
is Success -> {
Image(
modifier = Modifier
.clip(shape)
.conditional { onClick?.let { clickable(onClick = onClick) } },
painter = state.painter,
contentDescription = contentDescription,
)
}
is Error -> {
Icon(
icon = Theme.icons.networkError,
emphasis = Moderate,
)
}
is Loading -> {
Indicator(Medium)
}
is Empty -> Unit
}
Sean Proctor
02/16/2024, 8:17 PMSean Proctor
02/16/2024, 8:19 PMZoltan Demant
02/18/2024, 6:06 AMfun interface ImageScope {
@Composable
fun Image(modifier: Modifier)
}
@Composable
fun Image(
imageContent: @Composable (ImageScope) -> Unit
){}