Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix destory older pages when navigation from NavigationPage #1067

Merged
merged 6 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ public bool CanNavigate(NavigationParameters parameters)
return true;
}
}

public class SecondContentPageMockViewModel : ViewModelBase
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ public class NavigationPageMockViewModel : ViewModelBase
{

}

public class NavigationPageEmptyMockViewModel : ViewModelBase
{

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Prism.Forms.Tests.Mocks.ViewModels
{
public class PageMockViewModel
public class PageMockViewModel : ViewModelBase
{

}
Expand Down
11 changes: 11 additions & 0 deletions Source/Xamarin/Prism.Forms.Tests/Mocks/Views/ContentPageMock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,15 @@ public void Destroy()
PageNavigationEventRecorder?.Record(this, PageNavigationEvent.Destroy);
}
}

public class SecondContentPageMock : ContentPageMock
{
public SecondContentPageMock()
{
}

public SecondContentPageMock(PageNavigationEventRecorder recorder) : base(recorder)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public MasterDetailPageMock() : this(null)

public MasterDetailPageMock(PageNavigationEventRecorder recorder)
{
Master = new ContentPageMock(recorder) { Title = "Master" };
Detail = new ContentPageMock(recorder);

ViewModelLocator.SetAutowireViewModel(this, true);
Expand Down
71 changes: 66 additions & 5 deletions Source/Xamarin/Prism.Forms.Tests/Mocks/Views/NavigationPageMock.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Prism.Mvvm;
using System.Threading.Tasks;
using Prism.Mvvm;
using Prism.Navigation;
using Xamarin.Forms;

namespace Prism.Forms.Tests.Mocks.Views
{
public class NavigationPageMock : NavigationPage, IDestructible, IPageNavigationEventRecordable
public class NavigationPageMock : NavigationPage, IDestructible, IPageNavigationEventRecordable, INavigationPageOptions, INavigationAware
{
public bool DestroyCalled { get; private set; } = false;
public PageNavigationEventRecorder PageNavigationEventRecorder { get; set; }
Expand All @@ -13,7 +14,11 @@ public NavigationPageMock() : this(null)
{
}

public NavigationPageMock(PageNavigationEventRecorder recorder) : base(new ContentPageMock(recorder))
public NavigationPageMock(PageNavigationEventRecorder recorder) : this(recorder, new ContentPageMock(recorder))
{
}

public NavigationPageMock(PageNavigationEventRecorder recorder, Page page) : base(page)
{
ViewModelLocator.SetAutowireViewModel(this, true);

Expand All @@ -26,13 +31,69 @@ public void Destroy()
DestroyCalled = true;
PageNavigationEventRecorder.Record(this, PageNavigationEvent.Destroy);
}

public bool ClearNavigationStackOnNavigation { get; set; } = true;
public void OnNavigatedFrom(NavigationParameters parameters)
{
PageNavigationEventRecorder?.Record(this, PageNavigationEvent.OnNavigatedFrom);
}

public void OnNavigatedTo(NavigationParameters parameters)
{
PageNavigationEventRecorder?.Record(this, PageNavigationEvent.OnNavigatedTo);
}

public void OnNavigatingTo(NavigationParameters parameters)
{
PageNavigationEventRecorder?.Record(this, PageNavigationEvent.OnNavigatingTo);
}
}

public class NavigationPageEmptyMock : NavigationPage
public class NavigationPageEmptyMock : NavigationPage, INavigationAware, IConfirmNavigationAsync, IDestructible, IPageNavigationEventRecordable
{
public PageNavigationEventRecorder PageNavigationEventRecorder { get; set; }
public NavigationPageEmptyMock() : base()
{


}

public NavigationPageEmptyMock(PageNavigationEventRecorder recorder)
{
ViewModelLocator.SetAutowireViewModel(this, true);

PageNavigationEventRecorder = recorder;
((IPageNavigationEventRecordable)BindingContext).PageNavigationEventRecorder = recorder;
}

public void OnNavigatedFrom(NavigationParameters parameters)
{
PageNavigationEventRecorder?.Record(this, PageNavigationEvent.OnNavigatedFrom);
}

public void OnNavigatedTo(NavigationParameters parameters)
{
PageNavigationEventRecorder?.Record(this, PageNavigationEvent.OnNavigatedTo);
}

public void OnNavigatingTo(NavigationParameters parameters)
{
PageNavigationEventRecorder?.Record(this, PageNavigationEvent.OnNavigatingTo);
}

public Task<bool> CanNavigateAsync(NavigationParameters parameters)
{
return Task.Run(() =>
{
if (parameters.ContainsKey("canNavigate"))
return (bool)parameters["canNavigate"];

return true;
});
}

public void Destroy()
{
PageNavigationEventRecorder?.Record(this, PageNavigationEvent.Destroy);
}
}

Expand Down
48 changes: 46 additions & 2 deletions Source/Xamarin/Prism.Forms.Tests/Mocks/Views/PageMock.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,53 @@
using Prism.Navigation;
using System.Threading.Tasks;
using Prism.Mvvm;
using Prism.Navigation;
using Xamarin.Forms;

namespace Prism.Forms.Tests.Mocks.Views
{
public class PageMock : Page
public class PageMock : Page, INavigationAware, IConfirmNavigationAsync, IDestructible, IPageNavigationEventRecordable
{
public PageNavigationEventRecorder PageNavigationEventRecorder { get; set; }

public PageMock() : this(null)
{

}

public PageMock(PageNavigationEventRecorder recorder)
{
PageNavigationEventRecorder = recorder;
}

public void OnNavigatedFrom(NavigationParameters parameters)
{
PageNavigationEventRecorder?.Record(this, PageNavigationEvent.OnNavigatedFrom);
}

public void OnNavigatedTo(NavigationParameters parameters)
{
PageNavigationEventRecorder?.Record(this, PageNavigationEvent.OnNavigatedTo);
}

public void OnNavigatingTo(NavigationParameters parameters)
{
PageNavigationEventRecorder?.Record(this, PageNavigationEvent.OnNavigatingTo);
}

public Task<bool> CanNavigateAsync(NavigationParameters parameters)
{
return Task.Run(() =>
{
if (parameters.ContainsKey("canNavigate"))
return (bool)parameters["canNavigate"];

return true;
});
}

public void Destroy()
{
PageNavigationEventRecorder?.Record(this, PageNavigationEvent.Destroy);
}
}
}
Loading