Seminar Xamarin.Forms

30
Seminar Xamarin.Forms MARTIN PERNICA | @MARTINDEVELOPER

description

Seminar about Xamarin.Forms technology for students on UTB FAI

Transcript of Seminar Xamarin.Forms

Page 1: Seminar Xamarin.Forms

Seminar Xamarin.FormsMARTIN PERNICA | @MARTINDEVELOPER

Page 2: Seminar Xamarin.Forms

Hello, I’m Martin• Games programmer and creator• Loves rendering and GPGPU programming

• Mobile and website developer monkey

• Crazy games player• Beat me in Titanfall!

• Sometimes CEO• Really, sometimes …

Page 3: Seminar Xamarin.Forms

Classic mobile developmentThere are main 3 mobile platforms:• iOS• Small range of resolutions and devices

• Objective-C, C++, Swift

• Only native ARM code, can not execute code on demand

• Android• Soooo many devices

• Java, C++

• JIT (Dalvik), AOT (ART)

• Windows 8 (Phone, universal, …)• Windows Phone

• Windows Store

• C++, .NET with C#, F# …

Page 4: Seminar Xamarin.Forms

Classic mobile developmentEvery platform use different programming languages and tools

◦ You will need wide variety of skills

And client need to pay 3 platforms and you will spent 3x more time on development◦ Classic client want high quality applications for lower prices

Page 5: Seminar Xamarin.Forms

Classic mobile development

UI code

Platform specific code

Model code

Most programming you will spent at model!

Page 6: Seminar Xamarin.Forms

Classic mobile developmentBut you can use full API, native design and native libraries of target platform

◦ And it will be expensive – time and money

Page 7: Seminar Xamarin.Forms

Classic mobile development

Is there any solution how to write good applications in lesser time?

And no, HTML5 is not solution. Really …

Page 8: Seminar Xamarin.Forms

XamarinXamarin created Mono, MonoTouch (Xamarin.iOS) and Mono for Android (Xamarin.Android)

◦ Mono is open-source implementation of Microsoft .NET (CLI)

◦ MonoTouch and Mono for Android are commercial products which implements/binds native classes to Mono

Mono using Xamarin (.NET BCL) runs on iOS (AOT) and Android (JIT)◦ On Windows Phone it uses the native .NET

Page 9: Seminar Xamarin.Forms

XamarinSo you can use C# (F# if you like) as programming language for every platform

◦ You can call native classes

◦ Use native UI

◦ And also you can use wide range of .NET libraries (not every library is compatible)

Page 10: Seminar Xamarin.Forms

XamarinBut you need write separate code for views and UI for every platform

◦ That’s good because you can tune UI for every platform

But you know – time is money◦ So Xamarin developed the Xamarin.Forms project

Page 11: Seminar Xamarin.Forms

Xamarin.FormsUsing Xamarin.Forms you can write one UI code for every mobile platform!

◦ So you can share model code and UI code, but you can also use native classes

◦ You can write your UI code in C# (F#) or in declarative XAML

Page 12: Seminar Xamarin.Forms

Xamarin.Forms◦ 5 types of pages

◦ 7 types of layouts

◦ Many controls (Views) like Button or DatePicker

◦ And also some ListView/TableView cells

◦ Two-way data binding

◦ Dependency service

◦ Navigation system

◦ Unified animation API

◦ Messaging center

◦ …

Page 13: Seminar Xamarin.Forms

Xamarin.Forms Pages

Page 14: Seminar Xamarin.Forms

Xamarin.Forms Layouts

Page 15: Seminar Xamarin.Forms

Xamarin.Forms Structure

Page

Layout

Childrens

Controls LayoutsPage contains layout (in Content property) and layout have childrens which can be controls like Buttons or some others layouts

Page 16: Seminar Xamarin.Forms

Demo #1Basic project structure

◦ Shared

◦ PCL

◦ Entry point

First page with magic button

Magic button

Page 17: Seminar Xamarin.Forms

Xamarin.Forms MVVM/MVCFor best practice is good to follow some application development patterns like Model-View-ViewModel or Model-View-Controller

Page 18: Seminar Xamarin.Forms

Xamarin.Forms MVVMView

◦ UI

ViewModel◦ Connect data from Model to View

◦ DataBinding (two-way)

◦ Contains event handlers and others

Model◦ Business logic

◦ Entities

◦ Facades

◦ Data (Sqlite, XML …)

Page 19: Seminar Xamarin.Forms

Xamarin.Forms Two-Way DataBindingTwo-Way data binding is pattern where changes of some property (usually of model entity) are reflected from Binding Source to Binding Target and vice versa

Binding Target

Binding Source

Page 20: Seminar Xamarin.Forms

Demo #2Two-way data binding

◦ Set binding on property

◦ Set binding contextLabel

Entry

Dictionary on Android don’t know Swag :/

Page 21: Seminar Xamarin.Forms

Demo #3 – Something usefulSimple TODO list

◦ Created fully with data binding and events

◦ View – TodoPage

◦ ViewModel – TodoViewModel

◦ Model – TodoModel

Label

Entry

ListView

Add Button

Clear Button

Page 22: Seminar Xamarin.Forms

Xamarin.Forms TODO list – last words◦ For best practice – create Task entity

◦ List of strings sucks

◦ Also ListView source can be ObservableCollection and UI will be updated automatically◦ You can skip two-way data binding and reduce code

Page 23: Seminar Xamarin.Forms

Xamarin.Forms AnimationsEvery platform have really different Animations API

For example on iOS is following structure:◦ iOS

◦ Core Animation

◦ Core Graphics

◦ OpenGL ES

◦ GPU hardware

Page 24: Seminar Xamarin.Forms

Xamarin.Forms AnimationsXamarin.Forms provides unified animations API for views

There are many prepared animations like ScaleTo, RotateTo, FadeTo or also you can animate view by yourself

Page 25: Seminar Xamarin.Forms

Demo #4 - AnimationsAmazing box animations

◦ Scale, rotate and change opacity of BoxView

BoxView

Page 26: Seminar Xamarin.Forms

Xamarin.Forms Dependency ServiceSometimes you like to access native objects of platform, for example Text-to-Speech

You can create service class in Android project with Android specific implementation and also you can create same service in iOS project

Both services will implements interface like ITextToSpeech and in shared code you can get Text-to-Speech service using DependencyService

Page 27: Seminar Xamarin.Forms

Xamarin.Forms ConclusionXamarin.Forms contains a lot more features like Navigation system, Messaging center and others

◦ Using Xamarin.Forms you can accelerate you development process

◦ And use modern code features like async/await or LINQ

Read more about Xamarin.Forms at http://developer.xamarin.com/guides/cross-platform/xamarin-forms/

Page 28: Seminar Xamarin.Forms

Xamarin.FormsDo you like Xamarin? Yes we like it too!

◦ We are looking for Xamarin developers for our parent company PRIA, send email to me [email protected] or to HR [email protected]

◦ Or don’t be shy and come to our offices, we have cookies ;)

Page 29: Seminar Xamarin.Forms

Q & AIf you have more question, you can contact me on:

◦ Twitter @martindeveloper

◦ Email [email protected]

Page 30: Seminar Xamarin.Forms

Thank you for your attention!