Skip to content

Commit

Permalink
Merge pull request MvvmCross#46 from MvvmCross/viewlookup
Browse files Browse the repository at this point in the history
Fixes for MvvmCross#45
  • Loading branch information
martijn00 committed Feb 23, 2016
2 parents 5c3b520 + 5113252 commit 4f4d653
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
21 changes: 11 additions & 10 deletions MvvmCross.Forms.Presenter.Core/MvxFormsPageLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
using System.Linq;
using System.Reflection;
using Xamarin.Forms;
using MvvmCross.Core.Views;

namespace MvvmCross.Forms.Presenter.Core
{
public class MvxFormsPageLoader : IMvxFormsPageLoader
{
private MvxViewModelRequest _request;
private IMvxViewsContainer _viewFinder;

public Page LoadPage(MvxViewModelRequest request)
{
_request = request;

var pageName = GetPageName();
var pageType = GetPageType(pageName);
var pageName = GetPageName(request);
var pageType = GetPageType(request);

if (pageType == null)
{
Expand All @@ -33,16 +32,18 @@ public Page LoadPage(MvxViewModelRequest request)
return page;
}

protected virtual string GetPageName()
protected virtual string GetPageName(MvxViewModelRequest request)
{
var viewModelName = _request.ViewModelType.Name;
var viewModelName = request.ViewModelType.Name;
return viewModelName.Replace("ViewModel", "Page");
}

protected virtual Type GetPageType(string pageName)
protected virtual Type GetPageType(MvxViewModelRequest request)
{
return _request.ViewModelType.GetTypeInfo().Assembly.CreatableTypes()
.FirstOrDefault(t => t.Name == pageName);
if (_viewFinder == null)
_viewFinder = Mvx.Resolve<IMvxViewsContainer> ();

return _viewFinder.GetViewType (request.ViewModelType);
}
}
}
11 changes: 4 additions & 7 deletions MvvmCross.Forms.Presenter.Core/MvxFormsPagePresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,11 @@ public override async void ChangePresentation(MvxPresentationHint hint)
}
}

public void AddPresentationHintHandler<THint>(Func<THint, bool> action)
where THint : MvxPresentationHint
public override void Show(MvxViewModelRequest request)
{
}

public override async void Show(MvxViewModelRequest request)
{
if (await TryShowPage(request))
// async void is a nono, calling this sync because weirdness on startup as
// Show method is not awaited itself hence code continues without blocking.
if (TryShowPage(request).GetAwaiter().GetResult())
return;

Mvx.Error("Skipping request for {0}", request.ViewModelType.Name);
Expand Down

0 comments on commit 4f4d653

Please sign in to comment.