-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand onSuccess to function parameter #93
Comments
So something like: @OptIn(ExperimentalKamelApi::class)
@Composable
public fun KamelImage(
resource: Resource<Painter>,
contentDescription: String?,
modifier: Modifier = Modifier,
alignment: Alignment = Alignment.Center,
contentScale: ContentScale = ContentScale.Fit,
alpha: Float = DefaultAlpha,
colorFilter: ColorFilter? = null,
onLoading: @Composable (BoxScope.(Float) -> Unit)? = null,
onFailure: @Composable (BoxScope.(Throwable) -> Unit)? = null,
onSuccess: (() -> Unit)? = null,
contentAlignment: Alignment = Alignment.Center,
animationSpec: FiniteAnimationSpec<Float>? = null,
) {
val displayOnSuccess: @Composable (BoxScope.(Painter) -> Unit) = { painter ->
Image(
painter,
contentDescription,
Modifier.fillMaxSize(),
alignment,
contentScale,
alpha,
colorFilter
)
onSuccess?.invoke()
}
KamelImageBox(
resource,
modifier,
contentAlignment,
animationSpec,
onLoading,
onFailure,
displayOnSuccess,
)
} ? I can't really think of a common use case where you want to trigger something when an image loads. Do you have any any example use cases? Also, you can always just use |
Pretty much. I'd appreciate the opportunity to run a function only once when it's loaded.
One I'd use personally is a fade-in effect dependent on the KamelImage child component has loaded.
Hadn't thought of that in all honesty. Nontheless, I still think making |
I noticed KamelImage already has an
onSuccess
function stored as a val. It'd be nice to append more code to it for cases like state management when images are loaded, instead of running multiple times inonLoading
.The text was updated successfully, but these errors were encountered: