Skip to content

Commit

Permalink
Cleanup fluent navigators (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
wcoder authored Feb 22, 2022
1 parent 49bace6 commit 1178cbd
Show file tree
Hide file tree
Showing 24 changed files with 195 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Softeq.XToolkit.WhiteLabel.Extensions;
using Softeq.XToolkit.WhiteLabel.Model;
using Softeq.XToolkit.WhiteLabel.Navigation;
using Softeq.XToolkit.WhiteLabel.Navigation.FluentNavigators;

namespace Softeq.XToolkit.WhiteLabel.Droid.Dialogs
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Softeq.XToolkit.WhiteLabel.Droid.Internal;
using Softeq.XToolkit.WhiteLabel.Mvvm;
using Softeq.XToolkit.WhiteLabel.Navigation;
using Softeq.XToolkit.WhiteLabel.Navigation.FluentNavigators;

namespace Softeq.XToolkit.WhiteLabel.Droid.Navigation
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Softeq.XToolkit.WhiteLabel.Droid.Providers;
using Softeq.XToolkit.WhiteLabel.Mvvm;
using Softeq.XToolkit.WhiteLabel.Navigation;
using Softeq.XToolkit.WhiteLabel.Navigation.FluentNavigators;

namespace Softeq.XToolkit.WhiteLabel.Droid.Navigation
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Softeq.XToolkit.WhiteLabel.Dialogs;
using Softeq.XToolkit.WhiteLabel.Model;
using Softeq.XToolkit.WhiteLabel.Navigation;
using Softeq.XToolkit.WhiteLabel.Navigation.FluentNavigators;
using Xamarin.Forms;

namespace Softeq.XToolkit.WhiteLabel.Forms.Navigation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Developed by Softeq Development Corporation
// http://www.softeq.com

using System;
using Softeq.XToolkit.WhiteLabel.Mvvm;
using Softeq.XToolkit.WhiteLabel.Navigation;
using Softeq.XToolkit.WhiteLabel.Navigation.FluentNavigators;

namespace Softeq.XToolkit.WhiteLabel.Forms.Navigation
{
public static class FormsFluentNavigatorExtensions
{
[Obsolete("Use `_frameNavigation.From(this)` before using navigator instead of this.")]
public static FrameFluentNavigator<TViewModel> From<TViewModel>(
this FrameFluentNavigator<TViewModel> navigator,
object source)
where TViewModel : IViewModelBase
{
navigator.Initialize(source);
return navigator;
}

// TODO YP: Frame navigation needs to be redesigned for the future (forms/maui).
public static IFrameNavigationService From<TViewModel>(
this IFrameNavigationService navigationService,
TViewModel source)
where TViewModel : IViewModelBase
{
navigationService.Initialize(source);
return navigationService;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Softeq.XToolkit.Common.Threading;
using Softeq.XToolkit.WhiteLabel.Mvvm;
using Softeq.XToolkit.WhiteLabel.Navigation;
using Softeq.XToolkit.WhiteLabel.Navigation.FluentNavigators;
using Xamarin.Forms;

namespace Softeq.XToolkit.WhiteLabel.Forms.Navigation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Softeq.XToolkit.WhiteLabel.Bootstrapper.Abstract;
using Softeq.XToolkit.WhiteLabel.Mvvm;
using Softeq.XToolkit.WhiteLabel.Navigation;
using Softeq.XToolkit.WhiteLabel.Navigation.FluentNavigators;

namespace Softeq.XToolkit.WhiteLabel.Forms.Navigation
{
Expand Down Expand Up @@ -34,11 +33,6 @@ public void GoBack()
_platformNavigationService.GoBack();
}

public PageFluentNavigator<T> For<T>() where T : IViewModelBase
{
return new PageFluentNavigator<T>(this);
}

public void NavigateToViewModel<T>(
bool clearBackStack,
IReadOnlyList<NavigationParameterModel>? parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using Softeq.XToolkit.WhiteLabel.Mvvm;
using Softeq.XToolkit.WhiteLabel.Navigation;
using Softeq.XToolkit.WhiteLabel.Navigation.FluentNavigators;
using Softeq.XToolkit.WhiteLabel.Tests.Stubs;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Softeq.XToolkit.Common.Weak;
using Softeq.XToolkit.WhiteLabel.Mvvm;
using Softeq.XToolkit.WhiteLabel.Navigation;
using Softeq.XToolkit.WhiteLabel.Navigation.FluentNavigators;
using UIKit;

namespace Softeq.XToolkit.WhiteLabel.iOS.Navigation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using Softeq.XToolkit.WhiteLabel.iOS.Navigation;
using Softeq.XToolkit.WhiteLabel.Model;
using Softeq.XToolkit.WhiteLabel.Navigation;
using Softeq.XToolkit.WhiteLabel.Navigation.FluentNavigators;
using UIKit;

namespace Softeq.XToolkit.WhiteLabel.iOS.Services
Expand Down
35 changes: 0 additions & 35 deletions Softeq.XToolkit.WhiteLabel/Navigation/DialogsServiceExtensions.cs

This file was deleted.

84 changes: 84 additions & 0 deletions Softeq.XToolkit.WhiteLabel/Navigation/FluentNavigatorExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Developed by Softeq Development Corporation
// http://www.softeq.com

using System;
using Softeq.XToolkit.WhiteLabel.Mvvm;
using Softeq.XToolkit.WhiteLabel.Navigation.FluentNavigators;

namespace Softeq.XToolkit.WhiteLabel.Navigation
{
public static class FluentNavigatorExtensions
{
/// <summary>
/// Creates a <see cref="DialogFluentNavigator{TViewModel}"/>
/// from the specified <see cref="IDialogsService"/>.
/// </summary>
/// <typeparam name="TViewModel">Type of ViewModel.</typeparam>
/// <param name="dialogsService">Instance of <see cref="IDialogsService"/>.</param>
/// <returns>
/// Instance of <see cref="DialogFluentNavigator{TViewModel}"/>
/// created from the specified <see cref="IDialogsService"/>.
/// </returns>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="dialogsService"/> cannot be <see langword="null"/>.
/// </exception>
public static DialogFluentNavigator<TViewModel> For<TViewModel>(this IDialogsService dialogsService)
where TViewModel : class, IDialogViewModel
{
if (dialogsService == null)
{
throw new ArgumentNullException(nameof(dialogsService));
}

return new DialogFluentNavigator<TViewModel>(dialogsService);
}

/// <summary>
/// Creates a <see cref="FrameFluentNavigator{TViewModel}"/>
/// from the specified <see cref="IFrameNavigationService"/>.
/// </summary>
/// <typeparam name="TViewModel">Type of ViewModel.</typeparam>
/// <param name="frameNavigationService">Instance of <see cref="IFrameNavigationService"/>.</param>
/// <returns>
/// Instance of <see cref="FrameFluentNavigator{TViewModel}"/>
/// created from the specified <see cref="IFrameNavigationService"/>.
/// </returns>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="frameNavigationService"/> cannot be <see langword="null"/>.
/// </exception>
public static FrameFluentNavigator<TViewModel> For<TViewModel>(this IFrameNavigationService frameNavigationService)
where TViewModel : IViewModelBase
{
if (frameNavigationService == null)
{
throw new ArgumentNullException(nameof(frameNavigationService));
}

return new FrameFluentNavigator<TViewModel>(frameNavigationService);
}

/// <summary>
/// Creates a <see cref="PageFluentNavigator{TViewModel}"/>
/// from the specified <see cref="IPageNavigationService"/>.
/// </summary>
/// <typeparam name="TViewModel">Type of ViewModel.</typeparam>
/// <param name="pageNavigationService">Instance of <see cref="IPageNavigationService"/>.</param>
/// <returns>
/// Instance of <see cref="PageFluentNavigator{TViewModel}"/>
/// created from the specified <see cref="IFrameNavigationService"/>.
/// </returns>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="pageNavigationService"/> cannot be <see langword="null"/>.
/// </exception>
public static PageFluentNavigator<TViewModel> For<TViewModel>(this IPageNavigationService pageNavigationService)
where TViewModel : IViewModelBase
{
if (pageNavigationService == null)
{
throw new ArgumentNullException(nameof(pageNavigationService));
}

return new PageFluentNavigator<TViewModel>(pageNavigationService);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ namespace Softeq.XToolkit.WhiteLabel.Navigation.FluentNavigators
/// <typeparam name="TViewModel">Type of ViewModel to perform navigation to.</typeparam>
public abstract class FluentNavigatorBase<TViewModel> where TViewModel : IViewModelBase
{
/// <summary>
/// List of navigation parameters for the current navigator instance.
/// </summary>
protected readonly List<NavigationParameterModel> _parameters = new List<NavigationParameterModel>();

/// <summary>
/// Gets the list of navigation parameters for the current navigator instance.
/// </summary>
public List<NavigationParameterModel> Parameters { get; } = new List<NavigationParameterModel>();
public IReadOnlyList<NavigationParameterModel> Parameters => _parameters;

/// <summary>
/// Creates and adds navigation parameter for the specified property using reflection.
Expand All @@ -35,9 +40,9 @@ protected FluentNavigatorBase<TViewModel> ApplyParameter<TValue>(
var propertyInfo = (PropertyInfo) propertyExpression.GetMemberInfo();
var parameter = new NavigationParameterModel(value, new PropertyInfoModel(propertyInfo));

Parameters.Add(parameter);
_parameters.Add(parameter);

return this;
}
}
}
}
Loading

0 comments on commit 1178cbd

Please sign in to comment.