Skip to content

Commit

Permalink
Refactor: Removed throwing of SvgImageException and replaced it with …
Browse files Browse the repository at this point in the history
…a EventHandler
  • Loading branch information
bnoffer committed Feb 28, 2023
1 parent 305a40b commit dc30d57
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sample/SVGSample.Android/Resources/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Sample/SVGSample/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ public App()
InitializeComponent();

Xamarin.Forms.Extensions.Svg.SvgImage.RegisterAssembly();

Xamarin.Forms.Extensions.Svg.SvgImage.ExceptionEvent += (sender, e) =>
{
var ex = ((Xamarin.Forms.Extensions.Svg.SvgImageExceptionEventArgs)e).SvgImageException;
System.Diagnostics.Debug.WriteLine(ex.Message);
};
MainPage = new MainPage();
}

Expand Down
8 changes: 7 additions & 1 deletion XamExtensionsSvg/SvgImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public Color TintColor

#endregion

#region Event

public static EventHandler<SvgImageExceptionEventArgs> ExceptionEvent { get; set; }

#endregion

#region Constructor

/// <summary>
Expand Down Expand Up @@ -168,7 +174,7 @@ private void CanvasViewOnPaintSurface(object sender, SKPaintSurfaceEventArgs arg
}
catch (Exception ex)
{
throw new SvgImageException($"Error while trying to load Resource {resourceId}/{Source}.", ex);
ExceptionEvent?.Invoke(this, new SvgImageExceptionEventArgs(new SvgImageException($"Error while trying to load Resource {resourceId}/{Source}.", ex)));
}
}

Expand Down
15 changes: 15 additions & 0 deletions XamExtensionsSvg/SvgImageExceptionEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
namespace Xamarin.Forms.Extensions.Svg
{
public class SvgImageExceptionEventArgs : EventArgs
{
private SvgImageException _svgImageException;
public SvgImageException SvgImageException => _svgImageException;

public SvgImageExceptionEventArgs(SvgImageException ex)
{
_svgImageException = ex;
}
}
}

0 comments on commit dc30d57

Please sign in to comment.