[iOS] Prevent NRE when page is switched on Appearing (#840)
authorSamantha Houts <samhouts@users.noreply.github.com>
Mon, 27 Mar 2017 10:31:04 +0000 (03:31 -0700)
committerRui Marinho <me@ruimarinho.net>
Mon, 27 Mar 2017 10:31:04 +0000 (11:31 +0100)
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Unreported1.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs

diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Unreported1.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Unreported1.cs
new file mode 100644 (file)
index 0000000..2ed07cd
--- /dev/null
@@ -0,0 +1,55 @@
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+// Apply the default category of "Issues" to all of the tests in this assembly
+// We use this as a catch-all for tests which haven't been individually categorized
+#if UITEST
+[assembly: NUnit.Framework.Category("Issues")]
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+       [Preserve(AllMembers = true)]
+       [Issue(IssueTracker.None, 0, "NRE when switching page on Appearing", PlatformAffected.iOS)]
+       public class Unreported1 : TestMasterDetailPage
+       {
+               static Unreported1 MDP;
+
+               class SplashPage : ContentPage
+               {
+                       protected override void OnAppearing()
+                       {
+                               base.OnAppearing();
+
+                               // You really shouldn't do this, but we shouldn't crash when you do it. :)
+                               SwitchDetail();
+                       }
+               }
+
+               protected override void Init()
+               {
+                       MDP = this;
+
+                       Master = new Page { Title = "Master" };
+                       Detail = new SplashPage();
+               }
+
+               public static void SwitchDetail()
+               {
+                       MDP.Detail = new ContentPage { Content = new Label { Text = "If this did not crash, this test has passed." }, Padding = 20 };
+               }
+
+#if UITEST
+               [Test]
+               public void Unreported1Test()
+               {
+                       RunningApp.Screenshot("ensure there is no crash");
+               }
+#endif
+       }
+}
\ No newline at end of file
index 98753ff..8608dc7 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla52533.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla53362.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla45874.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Unreported1.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla53909.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)_Template.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue1028.cs" />
index e5e7d70..f7e3127 100644 (file)
@@ -200,6 +200,9 @@ namespace Xamarin.Forms.Platform.iOS
 
                void UpdateStatusBarPrefersHidden()
                {
+                       if (Element == null)
+                               return;
+
                        var animation = ((Page)Element).OnThisPlatform().PreferredStatusBarUpdateAnimation();
                        if (animation == PageUIStatusBarAnimation.Fade || animation == PageUIStatusBarAnimation.Slide)
                                UIView.Animate(0.25, () => SetNeedsStatusBarAppearanceUpdate());