You can configure the way local images will be loaded in Image component by providing a class that implements this logic, which was added to Beagle iOS in version 2.1.0.
The ImageProviderProtocol protocol consists of only one method called loadImageProvider(id:) that will be used to retrieve your local image.
public protocol ImageProviderProtocol {
func loadImageProvider(id: String) -> UIImage?
}
The fetchImage method takes 1 parameter:
In Beagle iOS, we have a struct called ImageProvider that retrieves the image using UIImage(named: id, in: mainBundle)
where mainBundle
is the bundle configured in BeagleDependencies
.
struct ImageProvider: ImageProviderProtocol {
@Injected var mainBundle: BundleProtocol
func loadImageProvider(id: String) -> UIImage? {
return UIImage(named: id, in: self.mainBundle.bundle, compatibleWith: nil)
}
}
To replace the class responsible for loading local images on Beagle, follow the steps below:
ImageImageProviderProtocol
Implement the ImageImageProviderProtocol
in the class (or struct) you wish to use, in this case we created a class CustomImageProvider
that will be used as an example:
struct CustomImageProvider: ImageProviderProtocol {
func loadImageProvider(id: String) -> UIImage? {
// your implementation
}
}
In AppDelegate or in Beagle environment settings class, assign the instance of CustomImageProvider
to the imageProvider
attribute present in BeagleDependencies
:
let dependencies = BeagleDependencies()
dependencies.imageProvider = CustomImageProvider()
BeagleConfigurator.setup(dependencies: dependencies)
Done! Beagle will now use your imageProvider with all the necessary modifications and settings to retrieve your local images.
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.