Skip to content
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
@@ -0,0 +1,76 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;xamarin.ios10;monoandroid81;uap10.0.16299</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\netstandard2.0\MADE.App.Views.Navigation.MvvmLight.xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard2.0\MADE.App.Views.Navigation.MvvmLight.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<Compile Remove="api\**" />
<Compile Remove="articles\**" />
<Compile Remove="_site\**" />
<EmbeddedResource Remove="api\**" />
<EmbeddedResource Remove="articles\**" />
<EmbeddedResource Remove="_site\**" />
<None Remove="api\**" />
<None Remove="articles\**" />
<None Remove="_site\**" />
</ItemGroup>

<PropertyGroup>
<LogFile>Docfx-$(TargetFramework).log</LogFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>1.0.0.0</Version>
<Authors>MADE Apps</Authors>
<Company>MADE Apps</Company>
<Product>MADE App View Navigation MvvmLight Library</Product>
<Description>Making App Development Easier with a collection of easy to use components for building MVVM friendly page to page navigation for .NET projects using MvvmLight across Windows, Android, and iOS.</Description>
<Copyright>Copyright (C) MADE Apps. All rights reserved.</Copyright>
<PackageLicenseUrl>https://github.com/MADE-Apps/MADE-App-Components/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/MADE-Apps/MADE-App-Components</PackageProjectUrl>
<RepositoryUrl>https://github.com/MADE-Apps/MADE-App-Components</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageIconUrl>https://pbs.twimg.com/profile_images/927154020422160385/6HSRU36P_400x400.jpg</PackageIconUrl>
<PackageTags>MADE App Development MvvmLight Mvvm View Navigation Service Frame Windows Android iOS Xamarin</PackageTags>
<RootNamespace>MADE.App.Views.Navigation</RootNamespace>
</PropertyGroup>

<ItemGroup>
<None Remove=".gitignore" />
<None Remove="docfx.json" />
<None Remove="index.md" />
<None Remove="log.txt" />
<None Remove="toc.yml" />
<None Remove="Docfx-*.log" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommonServiceLocator" Version="2.0.3" />
<PackageReference Include="docfx.console" Version="2.36.0" PrivateAssets="All" />
<PackageReference Include="MSBuild.Sdk.Extras" Version="1.5.4" PrivateAssets="All" />
<PackageReference Include="MvvmLightLibs" Version="5.4.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'monoandroid81' ">
<PackageReference Include="Xamarin.Android.Support.Fragment" Version="27.0.2" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="27.0.2" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'uap10.0.16299' ">
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.1.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MADE.App.Views.Navigation\MADE.App.Views.Navigation.csproj" />
</ItemGroup>

<Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />
</Project>
73 changes: 73 additions & 0 deletions MADE.App.Views.Navigation.MvvmLight/Pages/MvvmPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#if WINDOWS_UWP || __ANDROID__
namespace MADE.App.Views.Navigation.Pages
{
using MADE.App.Views.Navigation.ViewModels;

/// <summary>
/// Defines an MVVM friendly page that is compatible with MvvmLight and the application NavigationFrame.
/// </summary>
public class MvvmPage : Page
{
/// <summary>
/// Called when the page has loaded.
/// </summary>
public override void OnPageLoaded()
{
base.OnPageLoaded();

if (this.DataContext is PageViewModel vm)
{
vm.OnPageLoaded();
}
}

/// <summary>
/// Called when the page has been navigated from.
/// </summary>
/// <param name="e">
/// The navigation event argument for the navigation.
/// </param>
public override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);

if (this.DataContext is PageViewModel vm)
{
vm.OnNavigatedFrom(e);
}
}

/// <summary>
/// Called when the page has been navigated to.
/// </summary>
/// <param name="e">
/// The navigation event argument for the navigation.
/// </param>
public override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);

if (this.DataContext is PageViewModel vm)
{
vm.OnNavigatedTo(e);
}
}

/// <summary>
/// Called when the page is being navigated from.
/// </summary>
/// <param name="e">
/// The navigation event argument for the navigation supporting the cancellation of the navigation.
/// </param>
public override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);

if (this.DataContext is PageViewModel vm)
{
vm.OnNavigatingFrom(e);
}
}
}
}
#endif
81 changes: 81 additions & 0 deletions MADE.App.Views.Navigation.MvvmLight/ViewModels/PageViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PageViewModel.cs" company="MADE Apps">
// Copyright (c) MADE Apps.
// </copyright>
// <summary>
// Defines a view-model for a MADE page.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace MADE.App.Views.Navigation.ViewModels
{
using CommonServiceLocator;

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using GalaSoft.MvvmLight.Messaging;

/// <summary>
/// Defines a view-model for a MADE page.
/// </summary>
public class PageViewModel : ViewModelBase
{
/// <summary>
/// Initializes a new instance of the <see cref="PageViewModel"/> class.
/// </summary>
public PageViewModel()
: this(ServiceLocator.Current.GetInstance<IMessenger>())
{

}

/// <summary>
/// Initializes a new instance of the <see cref="PageViewModel"/> class.
/// </summary>
/// <param name="messenger">
/// The MVVM message aggregator.
/// </param>
[PreferredConstructor]
public PageViewModel(IMessenger messenger)
{
this.MessengerInstance = messenger;
}

/// <summary>
/// Called when the page has loaded.
/// </summary>
public virtual void OnPageLoaded()
{
}

/// <summary>
/// Called when the page has been navigated from.
/// </summary>
/// <param name="e">
/// The navigation event argument for the navigation.
/// </param>
public virtual void OnNavigatedFrom(NavigationEventArgs e)
{
}

/// <summary>
/// Called when the page has been navigated to.
/// </summary>
/// <param name="e">
/// The navigation event argument for the navigation.
/// </param>
public virtual void OnNavigatedTo(NavigationEventArgs e)
{
}

/// <summary>
/// Called when the page is being navigated from.
/// </summary>
/// <param name="e">
/// The navigation event argument for the navigation supporting the cancellation of the navigation.
/// </param>
public virtual void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
}
}
}
53 changes: 22 additions & 31 deletions MADE.App.Views.Navigation/NavigationFrame.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace MADE.App.Views.Navigation
using Android.Support.V4.App;
using Android.Support.V7.App;

using MADE.App.Views.Navigation.Pages;

/// <summary>
/// Defines a frame for navigating and displaying page content.
/// </summary>
Expand Down Expand Up @@ -82,25 +84,21 @@ public void GoBack()
return;
}

if (!this.CanNavigateAway())
NavigationEventArgs previousPageEvent = this.GetNavigationEvent(this.BackStackDepth - 1);
if (previousPageEvent == null)
{
// ToDo, if there is no page event, we are at the end of the stack. Should exit app.
return;
}

NavigationEventArgs currentPageEvent = this.GetNavigationEvent(this.BackStackDepth);
if (currentPageEvent != null)
{
currentPageEvent.NavigationMode = NavigationMode.Back;
}
previousPageEvent.NavigationMode = NavigationMode.Back;

NavigationEventArgs previousPageEvent = this.GetNavigationEvent(this.BackStackDepth - 1);
if (previousPageEvent != null)
if (!this.CanNavigateAway(previousPageEvent))
{
previousPageEvent.NavigationMode = NavigationMode.Back;
return;
}

this.HandleNavigation(
currentPageEvent,
previousPageEvent,
() =>
{
Expand Down Expand Up @@ -137,11 +135,6 @@ public bool Navigate(Type sourcePageType)
/// </returns>
public bool Navigate(Type sourcePageType, object parameter)
{
if (!this.CanNavigateAway())
{
return false;
}

if (!(Activator.CreateInstance(sourcePageType) is Page page))
{
return false;
Expand All @@ -154,6 +147,11 @@ public bool Navigate(Type sourcePageType, object parameter)
SourcePageType = sourcePageType
};

if (!this.CanNavigateAway(navArgs))
{
return false;
}

this.HandleNavigation(
navArgs,
() =>
Expand Down Expand Up @@ -193,26 +191,18 @@ protected override void OnCreate(Bundle savedInstanceState)
}

private void HandleNavigation(NavigationEventArgs navArgs, Action navigationAction)
{
this.HandleNavigation(navArgs, navArgs, navigationAction);
}

private void HandleNavigation(
NavigationEventArgs previousNavArgs,
NavigationEventArgs newNavArgs,
Action navigationAction)
{
IPage previousPage = this.currentPage;
previousPage?.OnNavigatedFrom(previousNavArgs);
previousPage?.OnNavigatedFrom(navArgs);

navigationAction?.Invoke();

this.currentPage = this.SupportFragmentManager.GetCurrentFragment() as Page;
if (this.currentPage != null)
{
this.currentPage.OnNavigatedTo(newNavArgs);
this.CurrentSourcePageParameter = newNavArgs.Parameter;
this.PageNavigated?.Invoke(this, newNavArgs);
this.currentPage.OnNavigatedTo(navArgs);
this.CurrentSourcePageParameter = navArgs.Parameter;
this.PageNavigated?.Invoke(this, navArgs);
}
}

Expand All @@ -239,7 +229,7 @@ private void RemoveNavigationEvent(int key)
}
}

private bool CanNavigateAway()
private bool CanNavigateAway(NavigationEventArgs args)
{
IPage previousPage = this.currentPage;

Expand All @@ -248,9 +238,10 @@ private bool CanNavigateAway()
NavigatingCancelEventArgs navArgs =
new NavigatingCancelEventArgs(() => shouldCancel = true)
{
SourcePageType = previousPage?.GetType(),
NavigationMode = NavigationMode.Back
};
SourcePageType = args.SourcePageType,
NavigationMode = args.NavigationMode,
Parameter = args.Parameter
};

previousPage?.OnNavigatingFrom(navArgs);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#if __ANDROID__
namespace MADE.App.Views.Navigation
namespace MADE.App.Views.Navigation.Pages
{
using Android.Views;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace MADE.App.Views.Navigation
namespace MADE.App.Views.Navigation.Pages
{
/// <summary>
/// Defines an interface for an application page.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#if __ANDROID__
namespace MADE.App.Views.Navigation
namespace MADE.App.Views.Navigation.Pages
{
using Android.OS;
using Android.Support.V4.App;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#if WINDOWS_UWP
namespace MADE.App.Views.Navigation
namespace MADE.App.Views.Navigation.Pages
{
using Windows.ApplicationModel;

Expand Down
Loading