Skip to content

Commit

Permalink
XF: Handlers now support SvgImageSource
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-luberda committed May 6, 2019
1 parent 11d0522 commit 6718025
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 11 deletions.
14 changes: 14 additions & 0 deletions source/FFImageLoading.Forms.Droid/CachedImageRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ public static void InitImageViewHandler()
Helpers.Dependency.Register(typeof(UriImageSource), typeof(FFImageLoadingImageViewHandler));
Helpers.Dependency.Register(typeof(EmbeddedResourceImageSource), typeof(FFImageLoadingImageViewHandler));
Helpers.Dependency.Register(typeof(DataUrlImageSource), typeof(FFImageLoadingImageViewHandler));

try
{
var svgAssembly = Assembly.Load("FFImageLoading.Svg.Forms");
if (svgAssembly != null)
{
var svgImageSourceType = svgAssembly.GetType("FFImageLoading.Svg.Forms.SvgImageSource");
if (svgImageSourceType != null)
{
Helpers.Dependency.Register(svgImageSourceType, typeof(FFImageLoadingImageViewHandler));
}
}
}
catch { }
}

private bool _isDisposed;
Expand Down
4 changes: 2 additions & 2 deletions source/FFImageLoading.Forms.Droid/ImageSourceBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ internal static ImageSourceBinding GetImageSourceBinding(ImageSource source, Cac
}

var vectorSource = source as IVectorImageSource;
if (element != null && vectorSource != null)
if (vectorSource != null)
{
if (vectorSource.VectorHeight == 0 && vectorSource.VectorHeight == 0)
if (element != null && vectorSource.VectorHeight == 0 && vectorSource.VectorHeight == 0)
{
if (element.Height > 0d && !double.IsInfinity(element.Height))
{
Expand Down
4 changes: 2 additions & 2 deletions source/FFImageLoading.Forms.Tizen/ImageSourceBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ internal static ImageSourceBinding GetImageSourceBinding(ImageSource source, Cac
}

var vectorSource = source as IVectorImageSource;
if (element != null && vectorSource != null)
if (vectorSource != null)
{
if (vectorSource.VectorHeight == 0 && vectorSource.VectorHeight == 0)
if (element != null && vectorSource.VectorHeight == 0 && vectorSource.VectorHeight == 0)
{
if (element.Height > 0d && !double.IsInfinity(element.Height))
{
Expand Down
15 changes: 15 additions & 0 deletions source/FFImageLoading.Forms.Touch/CachedImageRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using FFImageLoading.Helpers;
using FFImageLoading.Forms.Args;
using FFImageLoading.Forms.Platform;
using System.Reflection;

#if __IOS__
using UIKit;
Expand Down Expand Up @@ -72,6 +73,20 @@ public static void InitImageSourceHandler()
Helpers.Dependency.Register(typeof(UriImageSource), typeof(FFImageLoadingImageSourceHandler));
Helpers.Dependency.Register(typeof(EmbeddedResourceImageSource), typeof(FFImageLoadingImageSourceHandler));
Helpers.Dependency.Register(typeof(DataUrlImageSource), typeof(FFImageLoadingImageSourceHandler));

try
{
var svgAssembly = Assembly.Load("FFImageLoading.Svg.Forms");
if (svgAssembly != null)
{
var svgImageSourceType = svgAssembly.GetType("FFImageLoading.Svg.Forms.SvgImageSource");
if (svgImageSourceType != null)
{
Helpers.Dependency.Register(svgImageSourceType, typeof(FFImageLoadingImageSourceHandler));
}
}
}
catch { }
}

protected override void Dispose(bool disposing)
Expand Down
4 changes: 2 additions & 2 deletions source/FFImageLoading.Forms.Touch/ImageSourceBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ internal static ImageSourceBinding GetImageSourceBinding(ImageSource source, Cac
}

var vectorSource = source as IVectorImageSource;
if (element != null && vectorSource != null)
if (vectorSource != null)
{
if (vectorSource.VectorHeight == 0 && vectorSource.VectorHeight == 0)
if (element != null && vectorSource.VectorHeight == 0 && vectorSource.VectorHeight == 0)
{
if (element.Height > 0d && !double.IsInfinity(element.Height))
{
Expand Down
4 changes: 2 additions & 2 deletions source/FFImageLoading.Forms.WinUWP/ImageSourceBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ internal static async Task<ImageSourceBinding> GetImageSourceBinding(ImageSource
}

var vectorSource = source as IVectorImageSource;
if (element != null && vectorSource != null)
if (vectorSource != null)
{
if (vectorSource.VectorHeight == 0 && vectorSource.VectorHeight == 0)
if (element != null && vectorSource.VectorHeight == 0 && vectorSource.VectorHeight == 0)
{
if (element.Height > 0d && !double.IsInfinity(element.Height))
{
Expand Down
8 changes: 7 additions & 1 deletion source/FFImageLoading.Forms/Handlers/HandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected virtual Task<IImageLoaderTask> LoadImageAsync(IImageSourceBinding bind

if (binding.ImageSource == ImageSource.Url)
{
var urlSource = (Xamarin.Forms.UriImageSource)imageSource;
var urlSource = (Xamarin.Forms.UriImageSource)((imageSource as IVectorImageSource)?.ImageSource ?? imageSource);
parameters = ImageService.Instance.LoadUrl(binding.Path, urlSource.CacheValidity);

if (!urlSource.CachingEnabled)
Expand Down Expand Up @@ -44,6 +44,12 @@ protected virtual Task<IImageLoaderTask> LoadImageAsync(IImageSourceBinding bind

if (parameters != default)
{
// Enable vector image source
if (imageSource is IVectorImageSource vect)
{
parameters.WithCustomDataResolver(vect.GetVectorDataResolver());
}

var tcs = new TaskCompletionSource<IImageLoaderTask>();

parameters
Expand Down
4 changes: 2 additions & 2 deletions source/FFImageLoading.Svg.Shared/SvgDataResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,12 @@ public async Task<DataResolverResult> Resolve(string identifier, TaskParameter p
if (picture.CullRect.Width > 0)
sizeX = picture.CullRect.Width;
else
sizeX = 300;
sizeX = 400;

if (picture.CullRect.Height > 0)
sizeY = picture.CullRect.Height;
else
sizeY = 300;
sizeY = 400;
}
else if (sizeX > 0 && sizeY <= 0)
{
Expand Down

0 comments on commit 6718025

Please sign in to comment.