diff --git a/source/FFImageLoading.Forms.Droid/CachedImageRenderer.cs b/source/FFImageLoading.Forms.Droid/CachedImageRenderer.cs index 0910bfb20..49ad56b7a 100644 --- a/source/FFImageLoading.Forms.Droid/CachedImageRenderer.cs +++ b/source/FFImageLoading.Forms.Droid/CachedImageRenderer.cs @@ -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; diff --git a/source/FFImageLoading.Forms.Droid/ImageSourceBinding.cs b/source/FFImageLoading.Forms.Droid/ImageSourceBinding.cs index 6985c8921..dcbed741c 100644 --- a/source/FFImageLoading.Forms.Droid/ImageSourceBinding.cs +++ b/source/FFImageLoading.Forms.Droid/ImageSourceBinding.cs @@ -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)) { diff --git a/source/FFImageLoading.Forms.Tizen/ImageSourceBinding.cs b/source/FFImageLoading.Forms.Tizen/ImageSourceBinding.cs index de4cd323b..2def973e4 100644 --- a/source/FFImageLoading.Forms.Tizen/ImageSourceBinding.cs +++ b/source/FFImageLoading.Forms.Tizen/ImageSourceBinding.cs @@ -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)) { diff --git a/source/FFImageLoading.Forms.Touch/CachedImageRenderer.cs b/source/FFImageLoading.Forms.Touch/CachedImageRenderer.cs index aad75e088..49ef1d85c 100644 --- a/source/FFImageLoading.Forms.Touch/CachedImageRenderer.cs +++ b/source/FFImageLoading.Forms.Touch/CachedImageRenderer.cs @@ -11,6 +11,7 @@ using FFImageLoading.Helpers; using FFImageLoading.Forms.Args; using FFImageLoading.Forms.Platform; +using System.Reflection; #if __IOS__ using UIKit; @@ -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) diff --git a/source/FFImageLoading.Forms.Touch/ImageSourceBinding.cs b/source/FFImageLoading.Forms.Touch/ImageSourceBinding.cs index f4295b8c2..e6968d2d1 100644 --- a/source/FFImageLoading.Forms.Touch/ImageSourceBinding.cs +++ b/source/FFImageLoading.Forms.Touch/ImageSourceBinding.cs @@ -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)) { diff --git a/source/FFImageLoading.Forms.WinUWP/ImageSourceBinding.cs b/source/FFImageLoading.Forms.WinUWP/ImageSourceBinding.cs index d6eadfbeb..2fb09fc2c 100644 --- a/source/FFImageLoading.Forms.WinUWP/ImageSourceBinding.cs +++ b/source/FFImageLoading.Forms.WinUWP/ImageSourceBinding.cs @@ -99,9 +99,9 @@ internal static async Task 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)) { diff --git a/source/FFImageLoading.Forms/Handlers/HandlerBase.cs b/source/FFImageLoading.Forms/Handlers/HandlerBase.cs index fd6290fb7..e40eb67d3 100644 --- a/source/FFImageLoading.Forms/Handlers/HandlerBase.cs +++ b/source/FFImageLoading.Forms/Handlers/HandlerBase.cs @@ -13,7 +13,7 @@ protected virtual Task 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) @@ -44,6 +44,12 @@ protected virtual Task LoadImageAsync(IImageSourceBinding bind if (parameters != default) { + // Enable vector image source + if (imageSource is IVectorImageSource vect) + { + parameters.WithCustomDataResolver(vect.GetVectorDataResolver()); + } + var tcs = new TaskCompletionSource(); parameters diff --git a/source/FFImageLoading.Svg.Shared/SvgDataResolver.cs b/source/FFImageLoading.Svg.Shared/SvgDataResolver.cs index 9665a9b31..20dd59198 100644 --- a/source/FFImageLoading.Svg.Shared/SvgDataResolver.cs +++ b/source/FFImageLoading.Svg.Shared/SvgDataResolver.cs @@ -274,12 +274,12 @@ public async Task 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) {