Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
[iOS] Handle user popping pages out of order (#934)
Browse files Browse the repository at this point in the history
* [iOS] Handle when user can call pop a page that was already disposed/removed

* [Controls] Fix bug number
  • Loading branch information
rmarinho authored and Jason Smith committed May 24, 2017
1 parent cd61a94 commit 8f7b1f7
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 1 deletion.
29 changes: 29 additions & 0 deletions Xamarin.Forms.ControlGallery.iOS/CustomRendererBugzila38731.cs
@@ -0,0 +1,29 @@
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.ControlGallery.iOS;
using Xamarin.Forms.Controls.Issues;

[assembly: ExportRenderer(typeof(Bugzilla38731), typeof(CustomRendererBugzila38731))]
[assembly: ExportRenderer(typeof(Bugzilla38731.PageTwo), typeof(CustomRendererBugzila38731))]
[assembly: ExportRenderer(typeof(Bugzilla38731.PageThree), typeof(CustomRendererBugzila38731))]
[assembly: ExportRenderer(typeof(Bugzilla38731.PageFour), typeof(CustomRendererBugzila38731))]

namespace Xamarin.Forms.ControlGallery.iOS
{
public class CustomRendererBugzila38731 : Platform.iOS.PageRenderer
{
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);

if (NavigationController.ViewControllers.Length > 1)
{
NavigationController.TopViewController.NavigationItem.SetLeftBarButtonItem(new UIBarButtonItem(
UIImage.FromFile("bank.png"), UIBarButtonItemStyle.Plain, (sender, args) =>
{
NavigationController.PopViewController(true);
}), true);
}
}
}
}
Expand Up @@ -169,6 +169,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<None Include="packages.config" />
<Compile Include="CustomRenderers.cs" />
<Compile Include="CustomRendererBugzila38731.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Xamarin.Forms.Controls\Xamarin.Forms.Controls.csproj">
Expand Down
@@ -0,0 +1,129 @@
using System;
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.Bugzilla, 38731, "Xamarin.Forms.Platform.iOS.NavigationRenderer.GetAppearedOrDisappearedTask NullReferenceExceptionObject", PlatformAffected.Default)]
public class Bugzilla38731 : TestContentPage // or TestMasterDetailPage, etc ...
{
protected override void Init()
{
var label = new Label();
label.Text = "Page one...";
label.HorizontalTextAlignment = TextAlignment.Center;

var button = new Button();
button.AutomationId = "btn1";
button.Text = "Navigate to page two";
button.Clicked += Button_Clicked;

var content = new StackLayout();
content.Children.Add(label);
content.Children.Add(button);

Title = "Page one";
Content = content;
}

void Button_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new PageTwo());
}

public class PageTwo : ContentPage
{
public PageTwo()
{
var label = new Label();
label.Text = "Page two...";
label.HorizontalTextAlignment = TextAlignment.Center;

var button = new Button();
button.AutomationId = "btn2";
button.Text = "Navigate to page three";
button.Clicked += Button_Clicked;

var content = new StackLayout();
content.Children.Add(label);
content.Children.Add(button);

Title = "Page two";
Content = content;
}

void Button_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new PageThree());
}
}

public class PageThree : ContentPage
{
public PageThree()
{
var label = new Label();
label.Text = "Page three...";
label.HorizontalTextAlignment = TextAlignment.Center;

var button = new Button();
button.AutomationId = "btn3";
button.Text = "Navigate to page four";
button.Clicked += Button_Clicked;

var content = new StackLayout();
content.Children.Add(label);
content.Children.Add(button);

Title = "Page three";
Content = content;
}

void Button_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new PageFour());
}
}

public class PageFour : ContentPage
{
public PageFour()
{
var label = new Label();
label.Text = "Last page... Tap back very quick";
label.HorizontalTextAlignment = TextAlignment.Center;

var content = new StackLayout();
content.Children.Add(label);

Title = "Page four";
Content = content;
}
}

#if UITEST
[Test]
public void Bugzilla38731Test ()
{
RunningApp.Tap(q => q.Marked("btn1"));
RunningApp.Tap(q => q.Marked("btn2"));
RunningApp.Tap(q => q.Marked("btn3"));
RunningApp.Back();
RunningApp.Back();
RunningApp.Back();
}
#endif
}
}
Expand Up @@ -550,6 +550,7 @@
<DependentUpon>Bugzilla54977.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42956.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla38731.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs
Expand Up @@ -525,7 +525,7 @@ void RemovePage(Page page)
void RemoveViewControllers(bool animated)
{
var controller = TopViewController as ParentingViewController;
if (controller == null || controller.Child == null)
if (controller == null || controller.Child == null || Platform.GetRenderer(controller.Child) == null)
return;

// Gesture in progress, lets not be proactive and just wait for it to finish
Expand Down

0 comments on commit 8f7b1f7

Please sign in to comment.