Skip to content

Instantly share code, notes, and snippets.

@follesoe
Created July 24, 2018 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save follesoe/224885253d1aa91de0a0f3b867e27cf5 to your computer and use it in GitHub Desktop.
Save follesoe/224885253d1aa91de0a0f3b867e27cf5 to your computer and use it in GitHub Desktop.
public override void Show(MvxViewModelRequest request)
{
if (request.ViewModelType == typeof(SettingsViewModel))
{
var page = CreatePage(request);
var viewModel = LoadViewModel(request);
page.DataContext = viewModel;
var vc = page.CreateViewController();
var attr = new MvxTabPresentationAttribute
{
TabName = "Settings",
TabIconName = "SettingsTabIcon"
};
vc.Title = attr.TabName;
this.ShowTabViewController(vc, attr, request);
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
{
vc.NavigationController.NavigationBar.PrefersLargeTitles = true;
}
}
else if (request.ViewModelType == typeof(SettingsDroneDetailsViewModel))
{
var page = CreatePage(request);
var viewModel = LoadViewModel(request);
page.DataContext = viewModel;
var vc = page.CreateViewController();
var attr = new MvxChildPresentationAttribute();
this.ShowChildViewController(vc, attr, request);
}
else
{
base.Show(request);
}
}
using Android.OS;
using MvvmCross.Forms.Views;
using MvvmCross.ViewModels;
using Xamarin.Forms.Platform.Android;
namespace Blueye.App.Droid.Views
{
public abstract class FormsBaseActivity<TViewModel, TFormsPage> : BaseActivity<TViewModel>
where TViewModel : class, IMvxViewModel
where TFormsPage : MvxContentPage, new()
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.FormsPageFrame);
var page = new TFormsPage
{
DataContext = ViewModel
};
var pageFragment = page.CreateFragment(this);
FragmentManager
.BeginTransaction()
.Replace(Resource.Id.forms_page_frame, pageFragment)
.DisallowAddToBackStack()
.Commit();
}
}
}
using Android.OS;
using MvvmCross.Forms.Views;
using MvvmCross.ViewModels;
using Xamarin.Forms.Platform.Android;
namespace Blueye.App.Droid.Views
{
public abstract class FormsBaseFragment<TViewModel, TFormsPage> : BaseFragment<TViewModel>
where TViewModel : class, IMvxViewModel
where TFormsPage : MvxContentPage, new ()
{
protected override int FragmentLayoutId => Resource.Layout.FormsPageFrame;
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
var page = new TFormsPage
{
DataContext = ViewModel
};
var pageFragment = page.CreateSupportFragment(Activity);
ChildFragmentManager
.BeginTransaction()
.Replace(Resource.Id.forms_page_frame, pageFragment)
.DisallowAddToBackStack()
.Commit();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/forms_page_frame" />
using Android.App;
using Blueye.App.Views;
using Blueye.App.ViewModels;
using MvvmCross.Platforms.Android.Presenters.Attributes;
namespace Blueye.App.Droid.Views
{
[MvxActivityPresentation]
[Activity(Theme = "@style/AppTheme")]
public class SettingsDroneDetailsView : FormsBaseActivity<SettingsDroneDetailsViewModel, SettingsDroneDetailsPage>
{
}
}
using Blueye.App.Views;
using Blueye.App.ViewModels;
using MvvmCross.Platforms.Android.Presenters.Attributes;
namespace Blueye.App.Droid.Views
{
[MvxFragmentPresentation(typeof(MiniHomeViewModel), Resource.Id.container)]
public class SettingsView : FormsBaseFragment<SettingsViewModel, SettingsPage>
{
}
}
// On Droid:
protected override MvxBindingBuilder CreateBindingBuilder() => new MvxFormsAndroidBindingBuilder();
// On iOS:
protected override MvxBindingBuilder CreateBindingBuilder() => new MvxFormsIosBindingBuilder();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment