Skip to content

Commit

Permalink
Fixed issues causing crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Ieuan Walker authored and Ieuan Walker committed Aug 22, 2019
1 parent a674753 commit d9fdce6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Breadcrumb/Breadcrumb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageId>Xamarin.Forms.Breadcrumb</PackageId>
<Version>1.0.8</Version>
<Version>2.0.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
29 changes: 5 additions & 24 deletions Breadcrumb/Breadcrumb.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,10 @@ public bool IsNavigationEnabled
// TODO: Separator Icon, Image, Text

#endregion Control properties

private readonly INavigation _nav;

public Breadcrumb()
{
InitializeComponent();

_nav = Navigation;

// Event fired the moment ContentView is displayed
Device.BeginInvokeOnMainThread(() =>
{
Expand Down Expand Up @@ -267,45 +262,31 @@ private void AnimatedStack_ChildAdded(object sender, ElementEventArgs e)
/// <param name="selectedPage"></param>
private async Task GoBack(Page selectedPage)
{
System.Console.WriteLine($"{nameof(GoBack)} Clicked");
// Check if selectedPage is still in Navigation Stack
if (!_nav.NavigationStack.Any(x => x.Equals(selectedPage)))
if (!Navigation.NavigationStack.Any(x => x == selectedPage))
{
System.Console.WriteLine("Page not in stack");
// PopToRoot triggered if selectedPage is missing from navigation stack
await _nav.PopToRootAsync();
System.Console.WriteLine("Pop to root");
await Navigation.PopToRootAsync();
return;
}

System.Console.WriteLine("Page in stack");
// Get all pages after and including selectedPage
List<Page> pages = _nav.NavigationStack.SkipWhile(x => x != selectedPage).ToList();
List<Page> pages = Navigation.NavigationStack.SkipWhile(x => x != selectedPage).ToList();

System.Console.WriteLine("List of pages after selected page -");
pages.ForEach(x => System.Console.WriteLine(x.Title));
// Remove selectedPage
pages.Remove(selectedPage);

System.Console.WriteLine("Selected page removed");

// Remove current page (this will be removed with a PopAsync after all other relevant pages are removed)
pages = pages.Take(pages.Count - 1).ToList();

System.Console.WriteLine("Current page removed");

// Remove all pages left in list (i.e. all pages after selectedPage, minus the current page)
foreach (Page page in pages)
{
_nav.RemovePage(page);
Navigation.RemovePage(page);
}

System.Console.WriteLine("Pages inbetween selectedPage and CurrentPage removed");

// Remove current page
await _nav.PopAsync();

System.Console.WriteLine("Popasync");
await Navigation.PopAsync();
}
}
}

0 comments on commit d9fdce6

Please sign in to comment.