-
Notifications
You must be signed in to change notification settings - Fork 377
Advanced Usage
You can override global defaults by calling ImageService.Initialize method in platform specific project. You can globally enable transparency channel, disable fade animation, specify own logger, timeouts and a lot more.
public static void Initialize(int? maxCacheSize = null, HttpClient httpClient = null,
IWorkScheduler scheduler = null, IMiniLogger logger = null, IDiskCache diskCache = null,
IDownloadCache downloadCache = null, bool? loadWithTransparencyChannel = null, bool? fadeAnimationEnabled = null,
int httpHeadersTimeout = HttpHeadersTimeout, int httpReadTimeout = HttpReadTimeout)
If you don't want to use the Retry() functionality but have your custom error handling/retry logic (for example: because you use Polly). Then you can use IntoAsync() instead of Into()
try {
// IntoAsync does not swallow exceptions so you should surround it with a try/catch
await ImageService.LoadUrl(urlToImage).IntoAsync(_imageView);
} catch (Exception ex) {
// do whatever you want...
}
If you want to stop pending loading requests. For example when your activity gets paused/resumed:
protected override void OnPause()
{
base.OnPause();
ImageService.SetExitTasksEarly(true);
}
protected override void OnResume()
{
base.OnResume();
ImageService.SetExitTasksEarly(false);
}
If you want to load many images in a scrollable list view or horizontal list view and you have performance issues while you fling. In our app with more than 1000 items in an horizontal list view it was the case. To solve it we used:
_myListView.ScrollStateChanged += (object sender, ScrollStateChangedEventArgs scrollArgs) => {
switch (scrollArgs.ScrollState)
{
case ScrollState.Fling:
ImageService.SetPauseWork(true); // all image loading requests will be silently canceled
break;
case ScrollState.Idle:
ImageService.SetPauseWork(false); // loading requests are allowed again
// Here you should have your custom method that forces redrawing visible list items
_myListView.ForcePdfThumbnailsRedraw();
break;
}
};
Customizing the loading logic is very easy: inherit from ImageLoaderTask, put your own logic, and then pass the instance to ImageService: ImageService.LoadImage(customImageTask)
.