From 6bfe70ab38b9762d5435f9a5d1bcb44e155b7031 Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Wed, 16 Jan 2019 15:22:19 -0800 Subject: [PATCH] Fixes #14, better caching on UWP --- src/ImageCircle/Renderer.uwp.cs | 51 ++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/ImageCircle/Renderer.uwp.cs b/src/ImageCircle/Renderer.uwp.cs index 580de68..71fcd1e 100644 --- a/src/ImageCircle/Renderer.uwp.cs +++ b/src/ImageCircle/Renderer.uwp.cs @@ -19,6 +19,9 @@ namespace ImageCircle.Forms.Plugin.UWP /// public class ImageCircleRenderer : ViewRenderer { + + ImageBrush imageBrush = null; + /// /// Used for registration with dependency service /// @@ -68,22 +71,7 @@ protected async override void OnElementPropertyChanged(object sender, System.Com Control.Width = min; Control.Height = min; - // Fill background color - var color = ((CircleImage)Element).FillColor; - Control.Fill = new SolidColorBrush(Windows.UI.Color.FromArgb( - (byte)(color.A * 255), - (byte)(color.R * 255), - (byte)(color.G * 255), - (byte)(color.B * 255))); - - // Fill stroke - color = ((CircleImage)Element).BorderColor; - Control.StrokeThickness = ((CircleImage)Element).BorderThickness; - Control.Stroke = new SolidColorBrush(Windows.UI.Color.FromArgb( - (byte)(color.A * 255), - (byte)(color.R * 255), - (byte)(color.G * 255), - (byte)(color.B * 255))); + var force = e.PropertyName == VisualElement.XProperty.PropertyName || e.PropertyName == VisualElement.YProperty.PropertyName || @@ -106,9 +94,32 @@ protected async override void OnElementPropertyChanged(object sender, System.Com if (file == Element.Source && !force) return; - file = Element.Source; + // Fill background color + var color = ((CircleImage)Element).FillColor; + Control.Fill = new SolidColorBrush(Windows.UI.Color.FromArgb( + (byte)(color.A * 255), + (byte)(color.R * 255), + (byte)(color.G * 255), + (byte)(color.B * 255))); + + // Fill stroke + color = ((CircleImage)Element).BorderColor; + Control.StrokeThickness = ((CircleImage)Element).BorderThickness; + Control.Stroke = new SolidColorBrush(Windows.UI.Color.FromArgb( + (byte)(color.A * 255), + (byte)(color.R * 255), + (byte)(color.G * 255), + (byte)(color.B * 255))); + + if (file == Element.Source && imageBrush != null) + { + Control.Fill = imageBrush; + return; + } + + BitmapImage bitmapImage = null; - BitmapImage bitmapImage = null; + file = Element.Source; // Handle file images if (file is FileImageSource) @@ -142,7 +153,7 @@ protected async override void OnElementPropertyChanged(object sender, System.Com if (imageSource != null) { - Control.Fill = new ImageBrush + Control.Fill = imageBrush = new ImageBrush { ImageSource = imageSource, Stretch = Stretch.UniformToFill, @@ -153,7 +164,7 @@ protected async override void OnElementPropertyChanged(object sender, System.Com if (bitmapImage != null) { - Control.Fill = new ImageBrush + Control.Fill = imageBrush = new ImageBrush { ImageSource = bitmapImage, Stretch = Stretch.UniformToFill,