Call existing Fetcher from a custom Fetcher
AChep opened this issue · comments
Artem Chepurnyi commented
Is your feature request related to a problem? Please describe.
HTTP request HTTP request
X ------------> String ------------> Image
The current architecture with Mapper
s and Fetcher
s does not give me enough flexibility. It seems like the only option here is to create a custom Fetcher
that duplicates the functionality of the internal HttpUriFetcher
and also does the first data conversion request too.
Colin White commented
It's already possible to call an existing fetcher using an ImageLoader
's ComponentRegistry
in Coil 2.x. E.g.:
class CustomFetcher(data: Uri, options: Options, imageLoader: ImageLoader) {
override suspend fun fetch(): FetchResult? {
// Pass 1 to skip our custom fetcher.
val (fetcher) = imageLoader.components.newFetcher(data, options, imageLoader, startIndex = 1)
val result = fetcher.fetch()
return result
}
class Factory : Fetcher.Factory<Uri> {
override fun create(data: Uri, options: Options, imageLoader: ImageLoader): Fetcher? {
if (data.scheme != "http" && data.scheme != "https") return null
return CustomFetcher(data, options, imageLoader)
}
}
}