Skip to content

Commit

Permalink
refactored NavigateAsync()
Browse files Browse the repository at this point in the history
  • Loading branch information
vividos committed Dec 8, 2018
1 parent ed66966 commit 58941bc
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/App/Core/Services/NavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,26 @@ public static NavigationService Instance
/// <param name="parameter">parameter object to pass; may be null</param>
/// <returns>task to wait on</returns>
public async Task NavigateAsync(string pageKey, bool animated, object parameter = null)
{
Type pageType = GetPageTypeFromPageKey(pageKey, parameter);

if (pageType != null)
{
Device.BeginInvokeOnMainThread(async () => await this.NavigateAsync(pageType, animated, parameter));
}
}

/// <summary>
/// Returns Xamarin.Forms page type from given page key; also checks if needed parameters
/// were passed.
/// </summary>
/// <param name="pageKey">page key</param>
/// <param name="parameter">parameter; mandatory for some pages</param>
/// <returns>page type</returns>
private static Type GetPageTypeFromPageKey(string pageKey, object parameter)
{
Type pageType = null;

switch (pageKey)
{
case Constants.PageKeyMapPage:
Expand Down Expand Up @@ -109,10 +127,7 @@ public async Task NavigateAsync(string pageKey, bool animated, object parameter
break;
}

if (pageType != null)
{
Device.BeginInvokeOnMainThread(async () => await this.NavigateAsync(pageType, animated, parameter));
}
return pageType;
}

/// <summary>
Expand Down

0 comments on commit 58941bc

Please sign in to comment.