Skip to content

Commit

Permalink
#342 Use NavigationPageAdapter events
Browse files Browse the repository at this point in the history
  • Loading branch information
nigel-sampson committed Nov 2, 2016
1 parent 5f477fc commit 4a4b27b
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/Caliburn.Micro.Platform/xforms/NavigationPageAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,43 @@ namespace Caliburn.Micro.Xamarin.Forms {
/// </summary>
public class NavigationPageAdapter : INavigationService {
private readonly NavigationPage navigationPage;
private Page currentPage;

/// <summary>
/// Instantiates new instance of NavigationPageAdapter
/// </summary>
/// <param name="navigationPage">The navigation page to adapat</param>
public NavigationPageAdapter(NavigationPage navigationPage) {
this.navigationPage = navigationPage;

navigationPage.Pushed += OnPushed;
navigationPage.Popped += OnPopped;
navigationPage.PoppedToRoot += OnPoppedToRoot;
}

private void OnPoppedToRoot(object sender, NavigationEventArgs e)
{
DeactivateView(currentPage);
ActivateView(navigationPage.CurrentPage);

currentPage = navigationPage.CurrentPage;
}

private void OnPopped(object sender, NavigationEventArgs e)
{
DeactivateView(currentPage);
ActivateView(navigationPage.CurrentPage);

currentPage = navigationPage.CurrentPage;
}

private void OnPushed(object sender, NavigationEventArgs e)
{
DeactivateView(currentPage);
ActivateView(navigationPage.CurrentPage);

currentPage = navigationPage.CurrentPage;
}

/// <summary>
/// Allow Xamarin to navigate to a ViewModel backed by a view which is of type <see cref="T:Xamarin.Forms.ContentView"/> by adapting the result
Expand Down Expand Up @@ -168,9 +196,6 @@ private Task PushAsync(Element view, object parameter, bool animated)
page = CreateContentPage(contentView, viewModel);
}

page.Appearing += (s, e) => ActivateView(page);
page.Disappearing += (s, e) => DeactivateView(page);

return navigationPage.PushAsync(page, animated);
}

Expand Down

0 comments on commit 4a4b27b

Please sign in to comment.