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

Updated Base PageModel to have an InitAsync method #320

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -54,7 +54,7 @@
<PackageReference Include="Xamarin.AndroidX.CardView" Version="1.0.0" />
<PackageReference Include="Xamarin.AndroidX.MediaRouter" Version="1.1.0" />
<PackageReference Include="Xamarin.AndroidX.Migration" Version="1.0.6" /> <PackageReference Include="Xamarin.Forms">
<Version>4.6.0.772</Version>
<Version>4.6.0.1180</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.6.0.772" />
<PackageReference Include="Xamarin.Forms" Version="4.6.0.1180" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<ItemGroup>
Expand Down
15 changes: 8 additions & 7 deletions samples/FreshMvvmApp/FreshMvvmApp/FreshMvvmApp/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Xamarin.Forms;
using System.Collections.Generic;
using System.Threading.Tasks;
using FreshMvvm;

namespace FreshMvvmApp
Expand All @@ -14,9 +15,9 @@ public App()
MainPage = new NavigationPage(new LaunchPage(this));
}

public void LoadBasicNav()
public async Task LoadBasicNav()
{
var page = FreshPageModelResolver.ResolvePageModel<MainMenuPageModel>();
var page = await FreshPageModelResolver.ResolvePageModel<MainMenuPageModel>();
var basicNavContainer = new FreshNavigationContainer(page);
MainPage = basicNavContainer;
}
Expand Down Expand Up @@ -46,17 +47,17 @@ public void LoadFOTabbedNav()
MainPage = tabbedNavigation;
}

public void LoadCustomNav()
public async Task LoadCustomNav()
{
MainPage = new CustomImplementedNav();
MainPage = await CustomImplementedNav.Create();
}

public void LoadMultipleNavigation()
public async Task LoadMultipleNavigation()
{
var masterDetailsMultiple = new MasterDetailPage(); //generic master detail page

//we setup the first navigation container with ContactList
var contactListPage = FreshPageModelResolver.ResolvePageModel<ContactListPageModel>();
var contactListPage = await FreshPageModelResolver.ResolvePageModel<ContactListPageModel>();
contactListPage.Title = "Contact List";
//we setup the first navigation container with name MasterPageArea
var masterPageArea = new FreshNavigationContainer(contactListPage, "MasterPageArea");
Expand All @@ -65,7 +66,7 @@ public void LoadMultipleNavigation()
masterDetailsMultiple.Master = masterPageArea; //set the first navigation container to the Master

//we setup the second navigation container with the QuoteList
var quoteListPage = FreshPageModelResolver.ResolvePageModel<QuoteListPageModel>();
var quoteListPage = await FreshPageModelResolver.ResolvePageModel<QuoteListPageModel>();
quoteListPage.Title = "Quote List";
//we setup the second navigation container with name DetailPageArea
var detailPageArea = new FreshNavigationContainer(quoteListPage, "DetailPageArea");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="PropertyChanged.Fody" Version="3.2.8" />
<PackageReference Include="Xamarin.Forms" Version="4.6.0.772" />
<PackageReference Include="Xamarin.Forms" Version="4.6.0.1180" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions samples/FreshMvvmApp/FreshMvvmApp/FreshMvvmApp/LaunchPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ public LaunchPage (App app)
"Tabbed (FO) Navigation",
"Multiple Navigation"
};
list.ItemTapped += (object sender, ItemTappedEventArgs e) => {
list.ItemTapped += async (object sender, ItemTappedEventArgs e) => {
if ((string)e.Item == "Basic Navigation")
app.LoadBasicNav ();
await app.LoadBasicNav ();
else if ((string)e.Item == "Master Detail")
app.LoadMasterDetail ();
else if ((string)e.Item == "Tabbed Navigation")
app.LoadTabbedNav ();
else if ((string)e.Item == "Tabbed (FO) Navigation")
app.LoadFOTabbedNav ();
else if ((string)e.Item == "Custom Navigation")
app.LoadCustomNav ();
await app.LoadCustomNav ();
else if ((string)e.Item == "Multiple Navigation")
app.LoadMultipleNavigation ();
await app.LoadMultipleNavigation ();
};
this.Content = list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using FreshMvvm;
using Xamarin.Forms;
using System.Collections.Generic;
using System.Dynamic;
using System.Threading.Tasks;

namespace FreshMvvmApp
Expand All @@ -14,19 +15,31 @@ public class CustomImplementedNav : Xamarin.Forms.MasterDetailPage, IFreshNaviga
FreshTabbedNavigationContainer _tabbedNavigationPage;
Page _contactsPage, _quotesPage;

public CustomImplementedNav ()
private CustomImplementedNav ()
{
NavigationServiceName = "CustomImplementedNav";
SetupTabbedPage ();
}

public static async Task<CustomImplementedNav> Create()
{
var newInstance = new CustomImplementedNav();
return await newInstance.InitialiseAsync();
}

private async Task<CustomImplementedNav> InitialiseAsync()
{
NavigationServiceName = "CustomImplementedNav";
await SetupTabbedPage ();
CreateMenuPage ("Menu");
RegisterNavigation ();
return this;
}

void SetupTabbedPage()
async Task SetupTabbedPage()
{
_tabbedNavigationPage = new FreshTabbedNavigationContainer ();
_contactsPage = _tabbedNavigationPage.AddTab<ContactListPageModel> ("Contacts", "contacts.png");
_quotesPage = _tabbedNavigationPage.AddTab<QuoteListPageModel> ("Quotes", "document.png");
_contactsPage = await _tabbedNavigationPage.AddTab<ContactListPageModel> ("Contacts", "contacts.png");
_quotesPage = await _tabbedNavigationPage.AddTab<QuoteListPageModel> ("Quotes", "document.png");
this.Detail = _tabbedNavigationPage;
}

Expand Down Expand Up @@ -54,7 +67,7 @@ protected void CreateMenuPage(string menuPageTitle)
_tabbedNavigationPage.CurrentPage = _quotesPage;
break;
case "Modal Demo":
var modalPage = FreshPageModelResolver.ResolvePageModel<ModalPageModel>();
var modalPage = await FreshPageModelResolver.ResolvePageModel<ModalPageModel>();
await PushPage(modalPage, null, true);
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using PropertyChanged;
using FreshMvvm;
using System;
using System.Threading.Tasks;

namespace FreshMvvmApp
{
Expand All @@ -24,13 +25,15 @@ void HandleContactChanged(string propertyName)

public Contact Contact { get; set; }

public override void Init (object initData)
public override Task InitAsync(object initData)
{
if (initData != null) {
Contact = (Contact)initData;
} else {
Contact = new Contact ();
}

return base.InitAsync(initData);
}

public Command SaveCommand {
Expand All @@ -55,7 +58,7 @@ public Command TestModalNavigationBasic {
get {
return new Command (async () => {

var page = FreshPageModelResolver.ResolvePageModel<MainMenuPageModel> ();
var page = await FreshPageModelResolver.ResolvePageModel<MainMenuPageModel> ();
var basicNavContainer = new FreshNavigationContainer (page, Guid.NewGuid ().ToString ());
await CoreMethods.PushNewNavigationServiceModal(basicNavContainer, new FreshBasePageModel[] { page.GetModel() });
});
Expand Down
13 changes: 7 additions & 6 deletions src/FreshMvvm.Tests/Fixtures/FreshPageModelResolverFixture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using FreshMvvm.Tests.Mocks;
using NUnit.Framework;

Expand All @@ -10,16 +11,16 @@ public class FreshPageModelResolverFixture
[TestCase]
public void Test_ResolvePageModel_Not_Found()
{
Assert.Throws<Exception>(() =>
Assert.ThrowsAsync<Exception>(async () =>
{
FreshPageModelResolver.ResolvePageModel<MockFreshBasePageModel>();
await FreshPageModelResolver.ResolvePageModel<MockFreshBasePageModel>();
});
}

[TestCase]
public void Test_ResolvePageModel()
public async Task Test_ResolvePageModel()
{
var page = FreshPageModelResolver.ResolvePageModel<MockContentPageModel>();
var page = await FreshPageModelResolver.ResolvePageModel<MockContentPageModel>();
var context = page.BindingContext as MockContentPageModel;

Assert.IsNotNull(context);
Expand All @@ -28,9 +29,9 @@ public void Test_ResolvePageModel()
}

[TestCase("test data")]
public void Test_ResolvePageModel_With_Init(object data)
public async Task Test_ResolvePageModel_With_Init(object data)
{
var page = FreshPageModelResolver.ResolvePageModel<MockContentPageModel>(data);
var page = await FreshPageModelResolver.ResolvePageModel<MockContentPageModel>(data);
var context = page.BindingContext as MockContentPageModel;

Assert.IsNotNull(context);
Expand Down
Loading