previewer; PageRenderer trap for missing bg image (#5342)
authorkingces95 <kingces95@users.noreply.github.com>
Thu, 28 Feb 2019 02:32:57 +0000 (16:32 -1000)
committerSamantha Houts <samhouts@users.noreply.github.com>
Thu, 28 Feb 2019 02:32:57 +0000 (18:32 -0800)
* previewer; PageRenderer trap for missing bg image

* previewer; PageRenderer trap for missing bg image

* fix macOS; remove ext for macOS

fixes #5300

Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs
Xamarin.Forms.Platform.iOS/Renderers/CarouselPageRenderer.cs
Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs
Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs
Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs

index 6dc9e3b..9238607 100644 (file)
@@ -32,6 +32,17 @@ namespace Xamarin.Forms.Platform.MacOS
 #endif
                }
 
+#if __MOBILE__
+               public static UIColor FromPatternImageFromBundle(string bgImage)
+               {
+                       var image = UIImage.FromBundle(bgImage);
+                       if (image == null)
+                               return UIColor.White;
+
+                       return UIColor.FromPatternImage(image);
+               }
+#endif
+
                public static Color ToColor(this UIColor color)
                {
                        nfloat red;
index e09bb41..7c10aee 100644 (file)
@@ -361,7 +361,7 @@ namespace Xamarin.Forms.Platform.iOS
                        string bgImage = ((Page)Element).BackgroundImage;
                        if (!string.IsNullOrEmpty(bgImage))
                        {
-                               View.BackgroundColor = UIColor.FromPatternImage(UIImage.FromBundle(bgImage));
+                               View.BackgroundColor = ColorExtensions.FromPatternImageFromBundle(bgImage);
                                return;
                        }
                        Color bgColor = Element.BackgroundColor;
index adb90eb..5a1f010 100644 (file)
@@ -322,7 +322,7 @@ namespace Xamarin.Forms.Platform.iOS
                        string bgImage = ((Page)Element).BackgroundImage;
                        if (!string.IsNullOrEmpty(bgImage))
                        {
-                               View.BackgroundColor = UIColor.FromPatternImage(UIImage.FromBundle(bgImage) ?? throw new Exception($"Image: File '{bgImage}' not found in app bundle"));
+                               View.BackgroundColor = ColorExtensions.FromPatternImageFromBundle(bgImage);
                                return;
                        }
                        Color bgColor = Element.BackgroundColor;
index 79a650a..b62aa02 100644 (file)
@@ -302,7 +302,7 @@ namespace Xamarin.Forms.Platform.iOS
                void UpdateBackground()
                {
                        if (!string.IsNullOrEmpty(((Page)Element).BackgroundImage))
-                               View.BackgroundColor = UIColor.FromPatternImage(UIImage.FromBundle(((Page)Element).BackgroundImage));
+                               View.BackgroundColor = ColorExtensions.FromPatternImageFromBundle(((Page)Element).BackgroundImage);
                        else if (Element.BackgroundColor == Color.Default)
                                View.BackgroundColor = UIColor.White;
                        else
index 1f705c2..fafdd93 100644 (file)
@@ -319,7 +319,7 @@ namespace Xamarin.Forms.Platform.iOS
                void UpdateBackground()
                {
                        if (!string.IsNullOrEmpty(((Page)Element).BackgroundImage))
-                               View.BackgroundColor = UIColor.FromPatternImage(UIImage.FromBundle(((Page)Element).BackgroundImage));
+                               View.BackgroundColor = ColorExtensions.FromPatternImageFromBundle(((Page)Element).BackgroundImage);
                        else if (Element.BackgroundColor == Color.Default)
                                View.BackgroundColor = UIColor.White;
                        else