Understand the ImageLoader API and ImageAction lifecycle
masterThe ImageLoader is the primary entry point for image loading. It provides an async method that takes an ImageRequest and returns a Flow<ImageAction>.
ImageAction is a sealed interface representing the lifecycle of an image load request. It is divided into three main states:
Loading: Indicates the request is in progress. This includesImageEventsubtypes likeStart,StartWithMemory,StartWithDisk, andStartWithFetch.Success: Indicates the image was loaded successfully. Common implementations includeImageResult.OfBitmap,ImageResult.OfImage, andImageResult.OfPainter.Failure: Indicates an error occurred. It contains aThrowablevia theerrorproperty. Common implementations includeImageResult.OfErrorandImageResult.OfSource.
interface ImageLoader {
fun async(request: ImageRequest): Flow<ImageAction>
}
sealed interface ImageAction {
sealed interface Loading : ImageAction
sealed interface Success : ImageAction
sealed interface Failure : ImageAction {
val error: Throwable
}
}