示例#1
0
        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();
                }
            }
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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();
                }
            }
        }
示例#5
0
        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();
                }
            }
        }
示例#6
0
        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);
                }
            }
        }