async static Task StartStopAnimation( IVisualElementRenderer renderer, IImageController imageController, IImageElement imageElement) { IImageRendererController imageRendererController = renderer as IImageRendererController; var view = renderer.View as ImageView; if (imageRendererController.IsDisposed || imageElement == null || view == null || view.IsDisposed()) { return; } if (imageElement.IsLoading) { return; } if (!(view.Drawable is FormsAnimationDrawable) && imageElement.IsAnimationPlaying) { await TryUpdateBitmap(imageRendererController, view, imageElement); } if (view.Drawable is FormsAnimationDrawable animation) { if (imageElement.IsAnimationPlaying && !animation.IsRunning) { animation.Start(); } else if (!imageElement.IsAnimationPlaying && animation.IsRunning) { animation.Stop(); } } }
async static Task TryUpdateBitmap(IImageRendererController rendererController, ImageView Control, IImageElement newImage, IImageElement previous = null) { if (newImage == null || rendererController.IsDisposed) { return; } await Control.UpdateBitmap(newImage, previous).ConfigureAwait(false); }
static void UpdateAspect(IImageRendererController rendererController, ImageView Control, IImageElement newImage, IImageElement previous = null) { if (newImage == null || rendererController.IsDisposed) { return; } ImageView.ScaleType type = newImage.Aspect.ToScaleType(); Control.SetScaleType(type); }
async static Task TryUpdateBitmap(IImageRendererController rendererController, ImageView Control, IImageElement newImage, IImageElement previous = null) { if (newImage == null || rendererController.IsDisposed) { return; } if (Control.Drawable is FormsAnimationDrawable currentAnimation) { rendererController.SetFormsAnimationDrawable(currentAnimation); currentAnimation.Stop(); } else { rendererController.SetFormsAnimationDrawable(null); } try { await Control.UpdateBitmap(newImage, previous).ConfigureAwait(false); } catch (Exception ex) { Log.Warning(nameof(ImageElementManager), "Error loading image: {0}", ex); } finally { if (newImage is IImageController imageController) { imageController.SetIsLoading(false); } } if (rendererController.IsDisposed) { return; } if (Control.Drawable is FormsAnimationDrawable updatedAnimation) { rendererController.SetFormsAnimationDrawable(updatedAnimation); if (newImage.IsAnimationPlaying) { updatedAnimation.Start(); } } }
async static Task TryUpdateBitmap(IImageRendererController rendererController, ImageView Control, IImageElement newImage, IImageElement previous = null) { if (newImage == null || rendererController.IsDisposed) { return; } if (Control.Drawable is FormsAnimationDrawable currentAnimation) { rendererController.SetFormsAnimationDrawable(currentAnimation); currentAnimation.Stop(); } else { rendererController.SetFormsAnimationDrawable(null); } try { await Control.UpdateBitmap(newImage, previous).ConfigureAwait(false); } catch (Exception ex) { Application.Current?.FindMauiContext()?.CreateLogger <IImageRendererController>()?.LogWarning(ex, "Error loading image"); } finally { if (newImage is IImageController imageController) { imageController.SetIsLoading(false); } } if (rendererController.IsDisposed) { return; } if (Control.Drawable is FormsAnimationDrawable updatedAnimation) { rendererController.SetFormsAnimationDrawable(updatedAnimation); if (newImage.IsAnimationPlaying) { updatedAnimation.Start(); } } }
async static Task TryUpdateBitmap(IImageRendererController rendererController, ImageView Control, IImageElement newImage, IImageElement previous = null) { if (newImage == null || rendererController.IsDisposed) { return; } try { await Control.UpdateBitmap(newImage, previous).ConfigureAwait(false); } catch (Exception ex) { Log.Warning(nameof(ImageElementManager), "Error loading image: {0}", ex); } finally { if (newImage is IImageController imageController) { imageController.SetIsLoading(false); } } }