Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
Fixes #14, better caching on UWP
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno committed Jan 16, 2019
1 parent efe683b commit 6bfe70a
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions src/ImageCircle/Renderer.uwp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ namespace ImageCircle.Forms.Plugin.UWP
/// </summary>
public class ImageCircleRenderer : ViewRenderer<Image, Ellipse>
{

ImageBrush imageBrush = null;

/// <summary>
/// Used for registration with dependency service
/// </summary>
Expand Down Expand Up @@ -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 ||
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 6bfe70a

Please sign in to comment.