summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.ControlGallery.iOS
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2017-04-25 12:16:25 -0600
committerRui Marinho <me@ruimarinho.net>2017-04-25 19:16:25 +0100
commitcdc405512844671bc3b2c8bd28f583036e5530a2 (patch)
tree881d68b4a26eecbbc77e76b86b3f322cd41b3e3d /Xamarin.Forms.ControlGallery.iOS
parent9631ec2d8bbac8b837955af238f322c1023af097 (diff)
downloadxamarin-forms-cdc405512844671bc3b2c8bd28f583036e5530a2.tar.gz
xamarin-forms-cdc405512844671bc3b2c8bd28f583036e5530a2.tar.bz2
xamarin-forms-cdc405512844671bc3b2c8bd28f583036e5530a2.zip
Better error handling for image loading errors on iOS/Android (#849)
* First run at removing async void image update methods Consistent error logging and IsLoading on Android,iOS,UWP Move error logging into image handlers for better messages Add demo of custom ImageRenderer error handling Update docs Make the test smaller so the results don't get pushed offscreen Fix namespace error * Update error handling for fast image renderer * Update 37625 test to use image we control * Add java disposed check to avoid ObjectDisposedException in async operations * Add disposed checks to legacy renderer; null check element before SetIsLoading * Check disposed on GetDesiredSize for fast renderer Use local disposed member where possible for disposed check * Check for disposal after async handlers in iOS * Add disposal checks after async methods in Windows * Reset linker settings on project; reduce redundant casts in ImageViewExtensions
Diffstat (limited to 'Xamarin.Forms.ControlGallery.iOS')
-rw-r--r--Xamarin.Forms.ControlGallery.iOS/BrokenImageSourceHandler.cs36
-rw-r--r--Xamarin.Forms.ControlGallery.iOS/Properties/AssemblyInfo.cs6
-rw-r--r--Xamarin.Forms.ControlGallery.iOS/Resources/invalidimage.jpg1
-rw-r--r--Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj2
4 files changed, 45 insertions, 0 deletions
diff --git a/Xamarin.Forms.ControlGallery.iOS/BrokenImageSourceHandler.cs b/Xamarin.Forms.ControlGallery.iOS/BrokenImageSourceHandler.cs
new file mode 100644
index 00000000..5e58764b
--- /dev/null
+++ b/Xamarin.Forms.ControlGallery.iOS/BrokenImageSourceHandler.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using UIKit;
+using Xamarin.Forms;
+using Xamarin.Forms.ControlGallery.iOS;
+using Xamarin.Forms.Controls.Issues;
+using Xamarin.Forms.Platform.iOS;
+
+[assembly: ExportRenderer(typeof(_51173Image), typeof(_51173CustomImageRenderer))]
+namespace Xamarin.Forms.ControlGallery.iOS
+{
+ public sealed class BrokenImageSourceHandler : IImageSourceHandler
+ {
+ public Task<UIImage> LoadImageAsync(ImageSource imagesource, CancellationToken cancelationToken = new CancellationToken(),
+ float scale = 1)
+ {
+ throw new Exception("Fail");
+ }
+ }
+
+ public class _51173CustomImageRenderer : ImageRenderer
+ {
+ protected override async Task TrySetImage(Image previous = null)
+ {
+ try
+ {
+ await SetImage(previous).ConfigureAwait(false);
+ }
+ catch (Exception ex)
+ {
+ await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("Image Error 51173", $"The image failed to load, here's why: {ex.Message}", "OK");
+ }
+ }
+ }
+}
diff --git a/Xamarin.Forms.ControlGallery.iOS/Properties/AssemblyInfo.cs b/Xamarin.Forms.ControlGallery.iOS/Properties/AssemblyInfo.cs
index e7f2b400..d11d7e2f 100644
--- a/Xamarin.Forms.ControlGallery.iOS/Properties/AssemblyInfo.cs
+++ b/Xamarin.Forms.ControlGallery.iOS/Properties/AssemblyInfo.cs
@@ -1,6 +1,9 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+using Xamarin.Forms;
+using Xamarin.Forms.ControlGallery.iOS;
+using Xamarin.Forms.Controls;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
@@ -35,3 +38,6 @@ using System.Runtime.InteropServices;
[assembly: AssemblyVersion ("1.0.0.0")]
[assembly: AssemblyFileVersion ("1.0.0.0")]
[assembly: Xamarin.Forms.ResolutionGroupName("XamControl")]
+
+// Deliberately broken image source and handler so we can test handling of image loading errors
+[assembly: ExportImageSourceHandler(typeof(FailImageSource), typeof(BrokenImageSourceHandler))] \ No newline at end of file
diff --git a/Xamarin.Forms.ControlGallery.iOS/Resources/invalidimage.jpg b/Xamarin.Forms.ControlGallery.iOS/Resources/invalidimage.jpg
new file mode 100644
index 00000000..6c7ebbb3
--- /dev/null
+++ b/Xamarin.Forms.ControlGallery.iOS/Resources/invalidimage.jpg
@@ -0,0 +1 @@
+This is certainly not a real JPEG. \ No newline at end of file
diff --git a/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj b/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj
index d76b5e58..4e2e7706 100644
--- a/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj
+++ b/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj
@@ -159,6 +159,7 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
+ <Compile Include="BrokenImageSourceHandler.cs" />
<Compile Include="BrokenNativeControl.cs" />
<Compile Include="CustomRenderer40251.cs" />
<Compile Include="Main.cs" />
@@ -218,6 +219,7 @@
<Content Include="oasis.jpg" />
<BundleResource Include="oasissmall.jpg" />
<Content Include="coffee%402x.png" />
+ <BundleResource Include="Resources\invalidimage.jpg" />
<Content Include="settings%402x.png" />
<Content Include="menuIcon%402x.png" />
<Content Include="crimsonsmall.jpg" />