public static void UpdateIsAnimationPlaying(this WImage imageView, IImageSourcePart image) { if (!IsAnimationSupported) { return; } if (imageView.Source is BitmapImage bitmapImage && bitmapImage.IsAnimatedBitmap) { if (image.IsAnimationPlaying) { if (!bitmapImage.IsPlaying) { bitmapImage.Play(); } } else { if (bitmapImage.IsPlaying) { bitmapImage.Stop(); } } } }
public static Task <IImageSourceServiceResult <Drawable> > GetImageAsync(IImageSourcePart imagePart, IMauiContext mauiContext) { var services = mauiContext.Services; var provider = services.GetRequiredService <IImageSourceServiceProvider>(); var imageSourceService = provider.GetRequiredImageSourceService(imagePart.Source); return(imageSourceService.GetDrawableAsync(imagePart.Source, mauiContext.Context)); }
public static Task <IImageSourceServiceResult <Drawable>?> UpdateSourceAsync( this ImageView imageView, IImageSourcePart image, IImageSourceServiceProvider services, CancellationToken cancellationToken = default) { imageView.Clear(); return(image.UpdateSourceAsync(imageView, services, (d) => imageView.SetImageDrawable(d), cancellationToken)); }
public static Task <IImageSourceServiceResult <UIImage>?> UpdateSourceAsync( this UIImageView imageView, IImageSourcePart image, IImageSourceServiceProvider services, CancellationToken cancellationToken = default) { imageView.Clear(); return(image.UpdateSourceAsync(imageView, services, (uiImage) => { imageView.Image = uiImage; }, cancellationToken)); }
public static void UpdateIsAnimationPlaying(this UIImageView imageView, IImageSourcePart image) { if (image.IsAnimationPlaying) { if (!imageView.IsAnimating) { imageView.StartAnimating(); } } else { if (imageView.IsAnimating) { imageView.StopAnimating(); } } }
public static void UpdateIsAnimationPlaying(this Drawable?drawable, IImageSourcePart image) { if (drawable is IAnimatable animatable) { if (image.IsAnimationPlaying) { if (!animatable.IsRunning) { animatable.Start(); } } else { if (animatable.IsRunning) { animatable.Stop(); } } } }
public static void UpdateSource(this UIImageView imageView, UIImage?uIImage, IImageSourcePart image) { imageView.Image = uIImage; imageView.UpdateIsAnimationPlaying(image); }
public static void UpdateIsAnimationPlaying(this Image platformImage, IImageSourcePart image) { platformImage.IsAnimated = image.IsAnimationPlaying; platformImage.IsAnimationPlaying = image.IsAnimationPlaying; }
public static async Task <IImageSourceServiceResult <WImageSource>?> UpdateSourceAsync( this IImageSourcePart image, FrameworkElement destinationContext, IImageSourceServiceProvider services, Action <WImageSource?> setImage, CancellationToken cancellationToken = default) { image.UpdateIsLoading(false); var imageSource = image.Source; if (imageSource == null) { return(null); } var events = image as IImageSourcePartEvents; events?.LoadingStarted(); image.UpdateIsLoading(true); try { var service = services.GetRequiredImageSourceService(imageSource); var scale = destinationContext.XamlRoot?.RasterizationScale ?? 1; var result = await service.GetImageSourceAsync(imageSource, (float)scale, cancellationToken); var uiImage = result?.Value; var applied = !cancellationToken.IsCancellationRequested && imageSource == image.Source; // only set the image if we are still on the same one if (applied) { setImage(uiImage); if (destinationContext is WImage imageView) { imageView.UpdateIsAnimationPlaying(image); } } events?.LoadingCompleted(applied); return(result); } catch (OperationCanceledException) { // no-op events?.LoadingCompleted(false); } catch (Exception ex) { events?.LoadingFailed(ex); } finally { // only mark as finished if we are still working on the same image if (imageSource == image.Source) { image.UpdateIsLoading(false); } } return(null); }
public static async Task <IImageSourceServiceResult?> UpdateSourceAsync( this IImageSourcePart image, View destinationContext, IImageSourceServiceProvider services, Action <Drawable?> setImage, CancellationToken cancellationToken = default) { image.UpdateIsLoading(false); var context = destinationContext.Context; if (context == null) { return(null); } var destinationImageView = destinationContext as Android.Widget.ImageView; if (destinationImageView is null && setImage is null) { return(null); } var imageSource = image.Source; if (imageSource == null) { return(null); } var events = image as IImageSourcePartEvents; events?.LoadingStarted(); image.UpdateIsLoading(true); try { var service = services.GetRequiredImageSourceService(imageSource); var applied = !cancellationToken.IsCancellationRequested && destinationContext.IsAlive() && imageSource == image.Source; IImageSourceServiceResult?result = null; if (applied) { if (destinationImageView is not null) { result = await service.LoadDrawableAsync(imageSource, destinationImageView, cancellationToken); } else { result = await service.GetDrawableAsync(imageSource, context, cancellationToken); if (setImage is not null && result is IImageSourceServiceResult <Drawable> drawableResult) { setImage.Invoke(drawableResult.Value); } } if (result is null) { throw new InvalidOperationException("Glide failed to load image"); } } events?.LoadingCompleted(applied); return(result); } catch (OperationCanceledException) { // no-op events?.LoadingCompleted(false); } catch (Exception ex) { events?.LoadingFailed(ex); } finally { // only mark as finished if we are still working on the same image if (imageSource == image.Source) { image.UpdateIsLoading(false); } } return(null); }
public static async Task <IImageSourceServiceResult <Drawable>?> UpdateSourceAsync( this IImageSourcePart image, View destinationContext, IImageSourceServiceProvider services, Action <Drawable?> setDrawable, CancellationToken cancellationToken = default) { image.UpdateIsLoading(false); var context = destinationContext.Context; if (context == null) { return(null); } var imageSource = image.Source; if (imageSource == null) { return(null); } var events = image as IImageSourcePartEvents; events?.LoadingStarted(); image.UpdateIsLoading(true); try { var service = services.GetRequiredImageSourceService(imageSource); var result = await service.GetDrawableAsync(imageSource, context, cancellationToken); var drawable = result?.Value; var applied = !cancellationToken.IsCancellationRequested && destinationContext.IsAlive() && imageSource == image.Source; // only set the image if we are still on the same one if (applied) { setDrawable(drawable); drawable.UpdateIsAnimationPlaying(image); } events?.LoadingCompleted(applied); return(result); } catch (OperationCanceledException) { // no-op events?.LoadingCompleted(false); } catch (Exception ex) { events?.LoadingFailed(ex); } finally { // only mark as finished if we are still working on the same image if (imageSource == image.Source) { image.UpdateIsLoading(false); } } return(null); }
public static void LoadImage(IImageSourcePart part, IMauiContext mauiContext, Action <IImageSourceServiceResult <Drawable> > finished = null) { LoadImageResult(GetImageAsync(part.Source, mauiContext), finished) .FireAndForget(e => Internals.Log.Warning(nameof(ImageSourceLoader), $"{e}")); }
public static Task <IImageSourceServiceResult <Drawable> > LoadImageAsync(ImageView imageView, IImageSourcePart part, IMauiContext mauiContext) { var services = mauiContext.Services; var provider = services.GetRequiredService <IImageSourceServiceProvider>(); return(imageView.UpdateSourceAsync(part, provider)); }
public static void UpdateIsAnimationPlaying(this ImageView imageView, IImageSourcePart image) => imageView.Drawable.UpdateIsAnimationPlaying(image);