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

Fix samples and duplicate ViewModels on Xamarin.Forms #2044

Merged
merged 2 commits into from Jul 17, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -64,6 +64,9 @@ protected override void OnCreate(Bundle bundle)
setupSingleton.EnsureInitialized();

LifetimeListener.OnCreate(this);

global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(FormsApplication);
}

public void MvxInternalStartActivityForResult(Intent intent, int requestCode)
Expand Down
Expand Up @@ -64,6 +64,9 @@ protected override void OnCreate(Bundle bundle)
setupSingleton.EnsureInitialized();

LifetimeListener.OnCreate(this);

global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(FormsApplication);
}

public void MvxInternalStartActivityForResult(Intent intent, int requestCode)
Expand Down
Expand Up @@ -18,6 +18,9 @@ public static class MvxPresenterHelpers
{
public static IMvxViewModel LoadViewModel(MvxViewModelRequest request)
{
if(request is MvxViewModelInstanceRequest instanceRequest)
return instanceRequest.ViewModelInstance;

var viewModelLoader = Mvx.Resolve<IMvxViewModelLoader>();
var viewModel = viewModelLoader.LoadViewModel(request, null);
return viewModel;
Expand Down
Expand Up @@ -15,19 +15,7 @@ namespace Example.Droid
[Activity(Label = "ExampleApplicationActivity", ScreenOrientation=ScreenOrientation.Portrait)]
public class ExampleApplicationActivity : MvxFormsApplicationActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

Forms.Init(this, bundle);
var mvxFormsApp = new MvxFormsApplication();
LoadApplication(mvxFormsApp);

var presenter = Mvx.Resolve<IMvxViewPresenter>() as MvxFormsDroidPagePresenter;
presenter.FormsApplication = mvxFormsApp;

Mvx.Resolve<IMvxAppStart>().Start();
}

}
}

11 changes: 2 additions & 9 deletions TestProjects/Forms/Example001CSharp/Example.Android/Setup.cs
Expand Up @@ -3,13 +3,14 @@
using MvvmCross.Core.Views;
using MvvmCross.Droid.Platform;
using MvvmCross.Droid.Views;
using MvvmCross.Forms.Droid;
using MvvmCross.Forms.Droid.Presenters;
using MvvmCross.Platform;
using MvvmCross.Platform.Platform;

namespace Example.Droid
{
public class Setup : MvxAndroidSetup
public class Setup : MvxFormsAndroidSetup
{
public Setup(Context applicationContext)
: base(applicationContext)
Expand All @@ -25,13 +26,5 @@ protected override IMvxTrace CreateDebugTrace()
{
return new DebugTrace();
}

protected override IMvxAndroidViewPresenter CreateViewPresenter()
{
var presenter = new MvxFormsDroidPagePresenter();
Mvx.RegisterSingleton<IMvxViewPresenter>(presenter);

return presenter;
}
}
}
13 changes: 8 additions & 5 deletions TestProjects/Forms/Example001CSharp/Example.iOS/AppDelegate.cs
@@ -1,5 +1,6 @@
using Foundation;
using MvvmCross.Core.ViewModels;
using MvvmCross.Forms.iOS;
using MvvmCross.iOS.Platform;
using MvvmCross.Platform;
using UIKit;
Expand All @@ -10,21 +11,23 @@ namespace Example.iOS
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : MvxApplicationDelegate
public partial class AppDelegate : MvxFormsApplicationDelegate
{
private UIWindow _window;
public override UIWindow Window { get; set; }

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
_window = new UIWindow(UIScreen.MainScreen.Bounds);
Window = new UIWindow(UIScreen.MainScreen.Bounds);

var setup = new Setup(this, _window);
var setup = new Setup(this, Window);
setup.Initialize();

var startup = Mvx.Resolve<IMvxAppStart>();
startup.Start();

_window.MakeKeyAndVisible();
LoadApplication(setup.FormsApplication);

Window.MakeKeyAndVisible();

return true;
}
Expand Down
12 changes: 2 additions & 10 deletions TestProjects/Forms/Example001CSharp/Example.iOS/Setup.cs
@@ -1,5 +1,6 @@
using MvvmCross.Core.ViewModels;
using MvvmCross.Forms.Core;
using MvvmCross.Forms.iOS;
using MvvmCross.Forms.iOS.Presenters;
using MvvmCross.iOS.Platform;
using MvvmCross.iOS.Views.Presenters;
Expand All @@ -9,7 +10,7 @@

namespace Example.iOS
{
public class Setup : MvxIosSetup
public class Setup : MvxFormsIosSetup
{
public Setup(IMvxApplicationDelegate applicationDelegate, UIWindow window)
: base(applicationDelegate, window)
Expand All @@ -25,14 +26,5 @@ protected override IMvxTrace CreateDebugTrace()
{
return new DebugTrace();
}

protected override IMvxIosViewPresenter CreatePresenter()
{
Forms.Init();

var xamarinFormsApp = new MvxFormsApplication();

return new MvxFormsIosPagePresenter(Window, xamarinFormsApp);
}
}
}
Expand Up @@ -15,19 +15,6 @@ namespace Example.Droid
[Activity(Label = "ExampleApplicationActivity", ScreenOrientation=ScreenOrientation.Portrait)]
public class ExampleApplicationActivity : MvxFormsApplicationActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

Forms.Init(this, bundle);
var mvxFormsApp = new MvxFormsApplication();
LoadApplication(mvxFormsApp);

var presenter = Mvx.Resolve<IMvxViewPresenter>() as MvxFormsDroidPagePresenter;
presenter.FormsApplication = mvxFormsApp;

Mvx.Resolve<IMvxAppStart>().Start();
}
}
}

11 changes: 2 additions & 9 deletions TestProjects/Forms/Example001XAML/Example.Android/Setup.cs
Expand Up @@ -3,13 +3,14 @@
using MvvmCross.Core.Views;
using MvvmCross.Droid.Platform;
using MvvmCross.Droid.Views;
using MvvmCross.Forms.Droid;
using MvvmCross.Forms.Droid.Presenters;
using MvvmCross.Platform;
using MvvmCross.Platform.Platform;

namespace Example.Droid
{
public class Setup : MvxAndroidSetup
public class Setup : MvxFormsAndroidSetup
{
public Setup(Context applicationContext)
: base(applicationContext)
Expand All @@ -25,13 +26,5 @@ protected override IMvxTrace CreateDebugTrace()
{
return new DebugTrace();
}

protected override IMvxAndroidViewPresenter CreateViewPresenter()
{
var presenter = new MvxFormsDroidPagePresenter();
Mvx.RegisterSingleton<IMvxViewPresenter>(presenter);

return presenter;
}
}
}
13 changes: 8 additions & 5 deletions TestProjects/Forms/Example001XAML/Example.iOS/AppDelegate.cs
@@ -1,5 +1,6 @@
using Foundation;
using MvvmCross.Core.ViewModels;
using MvvmCross.Forms.iOS;
using MvvmCross.iOS.Platform;
using MvvmCross.Platform;
using UIKit;
Expand All @@ -10,21 +11,23 @@ namespace Example.iOS
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : MvxApplicationDelegate
public partial class AppDelegate : MvxFormsApplicationDelegate
{
private UIWindow _window;
public override UIWindow Window { get; set; }

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
_window = new UIWindow(UIScreen.MainScreen.Bounds);
Window = new UIWindow(UIScreen.MainScreen.Bounds);

var setup = new Setup(this, _window);
var setup = new Setup(this, Window);
setup.Initialize();

var startup = Mvx.Resolve<IMvxAppStart>();
startup.Start();

_window.MakeKeyAndVisible();
LoadApplication(setup.FormsApplication);

Window.MakeKeyAndVisible();

return true;
}
Expand Down
12 changes: 2 additions & 10 deletions TestProjects/Forms/Example001XAML/Example.iOS/Setup.cs
@@ -1,5 +1,6 @@
using MvvmCross.Core.ViewModels;
using MvvmCross.Forms.Core;
using MvvmCross.Forms.iOS;
using MvvmCross.Forms.iOS.Presenters;
using MvvmCross.iOS.Platform;
using MvvmCross.iOS.Views.Presenters;
Expand All @@ -9,7 +10,7 @@

namespace Example.iOS
{
public class Setup : MvxIosSetup
public class Setup : MvxFormsIosSetup
{
public Setup(IMvxApplicationDelegate applicationDelegate, UIWindow window)
: base(applicationDelegate, window)
Expand All @@ -25,14 +26,5 @@ protected override IMvxTrace CreateDebugTrace()
{
return new DebugTrace();
}

protected override IMvxIosViewPresenter CreatePresenter()
{
Forms.Init();

var xamarinFormsApp = new MvxFormsApplication();

return new MvxFormsIosPagePresenter(Window, xamarinFormsApp);
}
}
}
Expand Up @@ -13,18 +13,6 @@ namespace MasterDetailExample.Droid
[Activity(Label = "MasterDetailApplicationActivity", Icon = "@android:color/transparent")]
public class MasterDetailApplicationActivity : MvxFormsApplicationActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);

Forms.Init(this, bundle);
var mvxFormsApp = new MvxFormsApplication();
LoadApplication(mvxFormsApp);

var presenter = Mvx.Resolve<IMvxViewPresenter>() as MvxFormsDroidMasterDetailPagePresenter;
presenter.FormsApplication = mvxFormsApp;

Mvx.Resolve<IMvxAppStart>().Start();
}

}
}
Expand Up @@ -4,12 +4,13 @@
using MvvmCross.Core.Views;
using MvvmCross.Droid.Platform;
using MvvmCross.Droid.Views;
using MvvmCross.Forms.Droid;
using MvvmCross.Forms.Droid.Presenters;
using MvvmCross.Platform;

namespace MasterDetailExample.Droid
{
public class Setup : MvxAndroidSetup
public class Setup : MvxFormsAndroidSetup
{
public Setup(Context applicationContext)
: base(applicationContext)
Expand All @@ -24,10 +25,7 @@ protected override IMvxApplication CreateApp()

protected override IMvxAndroidViewPresenter CreateViewPresenter()
{
var presenter = new MvxFormsDroidMasterDetailPagePresenter();
Mvx.RegisterSingleton<IMvxViewPresenter>(presenter);

return presenter;
return new MvxFormsDroidMasterDetailPagePresenter();
}
}
}
@@ -1,5 +1,6 @@
using Foundation;
using MvvmCross.Core.ViewModels;
using MvvmCross.Forms.iOS;
using MvvmCross.iOS.Platform;
using MvvmCross.Platform;
using UIKit;
Expand All @@ -9,15 +10,9 @@ namespace MasterDetailExample.iOS
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to application events from iOS.
[Register("AppDelegate")]
public class AppDelegate : MvxApplicationDelegate
public class AppDelegate : MvxFormsApplicationDelegate
{
// class-level declarations

public override UIWindow Window
{
get;
set;
}
public override UIWindow Window { get; set; }

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
Expand All @@ -29,41 +24,12 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary options)
var startup = Mvx.Resolve<IMvxAppStart>();
startup.Start();

LoadApplication(setup.FormsApplication);

Window.MakeKeyAndVisible();

return true;
}

public override void OnResignActivation(UIApplication application)
{
// Invoked when the application is about to move from active to inactive state.
// This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message)
// or when the user quits the application and it begins the transition to the background state.
// Games should use this method to pause the game.
}

public override void DidEnterBackground(UIApplication application)
{
// Use this method to release shared resources, save user data, invalidate timers and store the application state.
// If your application supports background exection this method is called instead of WillTerminate when the user quits.
}

public override void WillEnterForeground(UIApplication application)
{
// Called as part of the transiton from background to active state.
// Here you can undo many of the changes made on entering the background.
}

public override void OnActivated(UIApplication application)
{
// Restart any tasks that were paused (or not yet started) while the application was inactive.
// If the application was previously in the background, optionally refresh the user interface.
}

public override void WillTerminate(UIApplication application)
{
// Called when the application is about to terminate. Save data, if needed. See also DidEnterBackground.
}
}
}

Expand Down