Load and display images from PlatformFile using Coil
PlatformFile
objects using Coil’s powerful image loading capabilities.
addPlatformFileSupport()
extension function to register the necessary components within Coil’s pipeline, enabling it to handle PlatformFile
objects:
PlatformFileMapper
: Maps the PlatformFile
object to a data type that Coil’s fetchers can understand.PlatformFileFetcher
: Handles the actual loading of the image data from the PlatformFile
.PlatformFileKeyer
: Generates stable cache keys for PlatformFile
objects, allowing Coil to effectively cache the loaded images.AsyncImage
composable with PlatformFile
objects:
PlatformFile
through mechanisms like the document picker, your app gets temporary, scoped access permission. To ensure Coil can load the image data while this permission is active, FileKit provides the securelyAccessFile
extension function for AsyncImagePainter.State
.
Use this function within the onState
callback of AsyncImage
:
startAccessingSecurityScopedResource()
when Coil starts loading (State.Loading
) and stopAccessingSecurityScopedResource()
when it finishes (State.Success
or State.Error
), ensuring the file remains accessible throughout the loading process.