Xamarin and MvvmCross = cross-platform coolness

16

Click here to load reader

description

Xamarin cross-platform development framework bundled together with MvvmCross provides a good toolset for creating mobile applications for iOS, Android and Windows Phone with C#

Transcript of Xamarin and MvvmCross = cross-platform coolness

Page 1: Xamarin and MvvmCross = cross-platform coolness

Juha Ristolainen (@Riussi) / Futurice Ltd (@futurice)

Xamarin + MvvmCross = cross-platform coolness8/14/2014

Page 2: Xamarin and MvvmCross = cross-platform coolness

Xamarin

Page 3: Xamarin and MvvmCross = cross-platform coolness

Mobile app development

*Image borrowed from Miguel de Icaza’s BUILD 2014 presentation

Traditional approach• Native apps developed in silos• No code re-use

8/14/2014

Page 4: Xamarin and MvvmCross = cross-platform coolness

Mobile app development

*Image borrowed from Miguel de Icaza’s BUILD 2014 presentation

Xamarin approach• Share common code between

apps• Write native apps with C#

• Amount of platform specific code from a few case studies from Xamarin:

• iOS: 20-30%• Android: 15-20%• Windows Phone: 10-15%

8/14/2014

Presenter
Presentation Notes
C# run on 2.6 billion devices
Page 5: Xamarin and MvvmCross = cross-platform coolness

What Xamarin offers

» C# + Full .NET Runtime (also F# compiler)

» Native UI (iOS + Android)

› Same native UI components

» Native performance

› Compiles from MSIL/CIL into native ARM-code

*Image borrowed from Miguel de Icaza’s BUILD 2014 presentation

Presenter
Presentation Notes
In iOS we can’t JIT compile. Static compiler, C# -> MSIL/CIL -> native ARM code. (MonoCode or Apple LLVM) Also F# compiler Android has JIT
Page 6: Xamarin and MvvmCross = cross-platform coolness

Xamarin approach

• Write native apps with C#

• App per platform, use normal platform idioms

• Native APIs wrapped in strongly typed C#

• Share common code between them

• Models, ViewModels, etc.

• Anything you can do on iOS and Android with Obj-C and Java you can do with Xamarin C#

68/14/2014 Futurice

Presenter
Presentation Notes
Xamarin showed stats at BUILD 2014 Amount of platform specific code: iOS: ~20-30% Android: ~15-20% Windows Phone: ~10-15%
Page 7: Xamarin and MvvmCross = cross-platform coolness

Sharing code

» Shared project

» New Universal App shared

» PCL (Portable Class Library)

» PCL + nuget

› Stick to public API contract that a PCL profile can compile

› Reference assembly that projects use

› Actual implementations can be platform specific and use which ever packages they want

Presenter
Presentation Notes
Shared project Universal app PCL Limited to just using the basic set of APIs PCL + nuget Use anything that’s compatible from nuget Stick to Public API contract that can be compiled for a PCL profile Create reference assembly, project references that Actual implementation per platform SQLite from MS based on this Xamarin moving completely to PCL (profile 78)
Page 8: Xamarin and MvvmCross = cross-platform coolness

MvvmCross

Page 9: Xamarin and MvvmCross = cross-platform coolness

MvvmCross Manifesto

» Portability

» Interface Driven Development

» Code for Test

» MVVM

» Native Uis

» Your opinion matters

» The app is King

https://github.com/MvvmCross/MvvmCross/wiki/The-MvvmCross-Manifesto

Presenter
Presentation Notes
MvvmCross is opinionated. It cares about how you write your code. Its opinions are: Portability – you should use Portable Class Libraries for as much of your code as you possibly can - viewmodel, model, service and even view. Friends don’t let friends copy and paste. # is for twitter, not for code. Interface Driven Development – you should use Dependency Injection, Inversion of Control and Plugins to get your applications richly and robustly to market on all of your target platforms. Code for Test – you should use interfaces; you should develop small, cohesive, loosely coupled components; and you should add unit tests to allow your code to be used, reshaped and reused again and again. Mvvm – you should use architectural patterns - especially Model-View-ViewModel with Data-Binding - in order to provide a structure within your app, and in order to deliver both a delightful application and a sustainable, flexible ongoing development process. Native UIs – users love Native, and you should give them Native UIs that delight, that provide rich functionality and that are styled to fit naturally in the context of your users’ devices. Your opinions matter – you should be able to override any part of MvvmCross, including its opinions. The app is King – more than anything else, what matters is that you ship. Delivering is everything. The app is King.
Page 10: Xamarin and MvvmCross = cross-platform coolness

First things

first

› Source code on GitHubhttps://github.com/MvvmCross/MvvmCross

› Get Ninja Coder extension to Visual Studiohttp://bit.ly/ninjacoder-mvvmcross

› I still prefer Visual Studio over Xamarin Studio

Page 11: Xamarin and MvvmCross = cross-platform coolness

App Architecture

› Common Core which contains

› Models

› ViewModels

› Connections to web APIs, etc

› App logic (navigation, etc)

› UI-project per platform

› Platform views

› Android, iOS, Windows Phone, Windows

Page 12: Xamarin and MvvmCross = cross-platform coolness

Service Location

and Inversion of

Control

› MvvmCross uses Service Locator pattern and Inversion of Control heavily

› For more Service Locator basics, see http://msdn.microsoft.com/en-us/library/ff648968.aspx

› For more IoC basics see http://joelabrahamsson.com/inversion-of-control-an-introduction-with-examples-in-net/

› Code against interfaces

› Register implementations with framework

› Mvx.Register methods

› Singletons, lazy initialization, etc.

› Framework handles ctor injection

› Mvx.Resolve methods

Page 13: Xamarin and MvvmCross = cross-platform coolness

Convention over

configuration

› MvvmCross uses Convention over Configuration

› FooViewModel maps to FooView

Page 14: Xamarin and MvvmCross = cross-platform coolness

Navigation

› MvvmCross was born for page-based applications

› Navigation logic in Core

› Icommand

› Capsulate actions to ICommands

› Navigate from ViewModel to ViewModel

› Framework does the page transitions

Page 15: Xamarin and MvvmCross = cross-platform coolness

Plugins

› A lot of functionality available via plugins

› Not everything in a monolithic core lib

› Example: location

› Full list at https://github.com/MvvmCross/MvvmCross/wiki/MvvmCross-plugins

Page 16: Xamarin and MvvmCross = cross-platform coolness

Demo › Creating an app skeleton with MvvmCross

Presenter
Presentation Notes
Create .Core .Android Add Refence