Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MvvmCross Bootcamp

MvvmCross Bootcamp

Martijn van Dijk

July 27, 2017
Tweet

More Decks by Martijn van Dijk

Other Decks in Technology

Transcript

  1. 1

  2. Agenda 17:00 - 18:00 Walk-in with pizza and drinks 18:00

    - 18:10 Welcome and Intro 18:15 - 19:15 MvvmCross 5.0 presentation and demo by Xamarin MVP and MvvmCross lead developer Martijn van Dijk 19:15 onwards “Hack your first app” – mini hackathon where you can start building your first app with Xamarin, MvvmCross and Azure
  3. 4

  4. 5 MvvmCross Bootcamp! Build polished mobile apps with MvvmCross Github:

    github.com/martijn00 Martijn van Dijk Twitter: @Mhvdijk Email: [email protected]
  5. Why Mvvm? View Binder ViewModel Model Button Text 1. Action

    1. Action 3. Command 5. Notify change 6. Change data 4. Access data 2. Event handling
  6. Cross platform awesomeness! Support for all major platforms Most advanced

    Mvvm library for Xamarin and .NET cross platform
  7. I love MvvmCross I am really impressed with MvvmCross Miguel

    de Icaza Xamarin CTO Scott Hanselman Microsoft Developer Evangelist
  8. 14 ▪ Viewmodels are INotifyPropertyChanged aware public class MyViewModel :

    MvxViewModel<MyObject> { Task Initialize(MyObject parameter); void Appearing(); void Appeared(); void Disappearing(); void Disappeared(); } ▪ ViewModels have lifecycle events ViewModels
  9. IoC (Inversion of Control) 1. Use interfaces 2. Define implementation

    of interfaces at runtime 3. Job done! :) ▪ Singleton: Mvx.RegisterSingleton<T>(); ▪ Lazy: Mvx.ConstructAndRegisterSingleton<T>(); ▪ Dynamic: Mvx.RegisterType<T>(); ▪ Construct: Mvx.IocConstruct<T>(); Mvx.Resolve<T>();
  10. Dependency Injection public class MyViewModel : MvxViewModel { public MyViewModel(IMvxJsonConverter

    jsonConverter, IMvxGeoLocationWatcher locationWatcher) { // Do stuff.... } }
  11. Generics ▪ MvvmCross uses CoC (Convention over Configuration) by default

    LoginView > LoginViewModel ▪ Generics are the preferred way LoginView : MvxActivity<LoginViewModel> MyView : MvxActivity<SomeDifferentNameViewModel> MyViewModel : MvxViewModel<MyObject, bool> MyValueConverter : MvxValueConverter<int, string>
  12. 19 ▪ ViewModel to ViewModel navigation private readonly IMvxNavigationService _navigationService;

    public MyViewModel(IMvxNavigationService navigation) { _navigationService = navigationService; } public async Task SomeMethod() { var result = await _navigationService.Navigate <NextViewModel, MyObject, MyReturnObject>(new MyObject()); //Do something with the result } Navigation
  13. Presenters ▪ Customize view presentation ▪ One platform-specific presenter per

    platform ▪ Still retain ViewModel logic ▪ Presentation hints to customize behavior
  14. View attributes ▪ Used to indicate how a view is

    presented on the screen ▪ Possible to implement interface to resolve at runtime iOS [MvxRootPresentation(WrapInNavigationController = true)] public partial class MyView : MvxViewController<MyViewModel> Android MvxFragment(typeof (MainViewModel), Resource.Id.content_frame, false)] public class MyView : MvxFragment<MyViewModel>
  15. 24 Enables the best Native UI Easy to implement custom

    presenters Most code reuse Recap of MvvmCross presenters
  16. Plugins ▪ Easy to drop into your project ▪ Extends

    functionality on multiple platforms ▪ Lots of MvvmCross plugins available ▪ Also 3th party plugins on Nuget All plugins available on Nuget
  17. Messenger public class LocationViewModel : MvxViewModel { private readonly MvxSubscriptionToken

    _token; public LocationViewModel(IMvxMessenger messenger) { _token = messenger.Subscribe<LocationMessage>(OnLocationMessage); } private void OnLocationMessage(LocationMessage locationMessage) { Lat = locationMessage.Lat; Lng = locationMessage.Lng; } }
  18. Value converters ▪ Convert bindable properties into a different format

    public class MyTimeAgoValueConverter : MvxValueConverter<DateTime, string> { protected override string Convert(DateTime value, Type targetType, object parameter, CultureInfo cultureInfo) { var timeAgo = DateTime.UtcNow - value; if (timeAgo.TotalSeconds < 30) return "just now"; return "previously"; } }
  19. Unit & UI tests using MvvmCross.Test.Core; using Moq; using NUnit.Framework;

    [TestFixture] public class MyTest : MvxIoCSupportingTest { [Test] public void TestViewModel() { base.Setup(); // from MvxIoCSupportingTest // your test code } }
  20. 30 ▪ Everything from MvvmCross available for Xamarin.Forms ▪ Use

    the Mvx base classes for Forms ▪ Support for MvvmCross Bindings in Forms layouts ▪ Mix native code with Forms ▪ Presenters leveraging Xamarin.Forms Xamarin.Forms
  21. 31 Best Mvvm framework for .NET Easy to learn, extend

    and customize Most code reuse Recap of MvvmCross
  22. Introduction ▪ MvvmCross repositories merged into one ▪ Issues closed:

    337 ▪ Pull requests merged: 209 ▪ Over 175 contributors
  23. Major changes ▪ Improved support for Xamarin.Forms ▪ Lifecycle/Event hooks

    ▪ Generic and typed bindings ▪ Removal of Windows (Phone) 8.x ▪ Removal and cleanup of plugins ▪ Improved StarterPack ▪ New documentation structure ▪ CodeStyle cleanup
  24. Presenting the new iOS & MacOS Presenter ▪ Handles all

    default navigation patterns ▪ Presentation Attributes ▪ Override a presentation attribute at runtime ▪ Extensibility
  25. Navigation service ▪ Async await ▪ Type safe ▪ Uri

    navigation with deeplinking ▪ Events on navigation ▪ Testable
  26. New documentation ▪ New website hosted on Github Pages with

    Jekyll ▪ Super easy to add/modify docs! ▪ Make pull requests to suggest changes ▪ Available now on: www.mvvmcross.com
  27. Roadmap ▪ Improved documentation and getting started ▪ Code cleanup

    ▪ New presenters for Android, tvOS and other platforms ▪ Refactoring of Android Fragments, and lifecycle ▪ .NET Standard support ▪ More Async & C#7 ▪ Tizen support
  28. Connect with us Follow us on Twitter All our news,

    events, insights and more @xabluHQ twitter.com/xabluHQ Follow us on Instagram Take a look behind the scenes instagram.com/xabluhq Connect on LinkedIn Link up with employees and get updates on news and events linkedin.com/company/xablu Like us on Facebook Get our news and events in your feed facebook.com/xabluhq
  29. Get help on Slack xamarinchat.herokuapp.com #MvvmCross channel Follow influencers #MvvmCross

    @MvvmCross Support MvvmCross! Opencollective.com/mvvmcross Join the LinkedIn group linkedin.com/groups/8456977 MvvmCross & Xamarin group Contribute on Github Github.com/MvvmCross/MvvmCross 44 Get involved!
  30. Hackathon Let’s build your first connected app with Xamarin and

    MvvmCross! - We’ve prepared an assignment for you on our Github page: http://xab.lu/meetup19