ebook img

Xamarin in Action: Creating native cross-platform mobile apps PDF

2018·14.38 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Xamarin in Action: Creating native cross-platform mobile apps

Creating native cross-platform mobile apps Jim Bennett F James Montemagno OREWORDBY M A N N I N G A sneak peak... By building Xamarin apps using the MVVM design pattern, you too can reuse 80% of your code across iOS and Android. iOS Android C# C# App layer C# UI layer C# C# View Binding UI logic View C# layer model Business C# Model logic layer Picking the right thread... We all hate mobile apps that are unresponsive. Here’s how to decide what to run on a background thread. Does this use Does this take UI thread or Does this No No No external resources more than 100 ms background involve the UI? (DB, web)? on a slow device? thread Yes Yes Yes Background Background UI thread thread thread Xamarin in Action CREATING NATIVE CROSS-PLATFORM MOBILE APPS JIM BENNETT MANNING SHELTERISLAND ForonlineinformationandorderingofthisandotherManningbooks,pleasevisit www.manning.com.Thepublisheroffersdiscountsonthisbookwhenorderedinquantity. Formoreinformation,pleasecontact SpecialSalesDepartment ManningPublicationsCo. 20BaldwinRoad POBox761 ShelterIsland,NY11964 Email:[email protected] ©2018byManningPublicationsCo.Allrightsreserved. Nopartofthispublicationmaybereproduced,storedinaretrievalsystem,ortransmitted,in anyformorbymeanselectronic,mechanical,photocopying,orotherwise,withoutpriorwritten permissionofthepublisher. Manyofthedesignationsusedbymanufacturersandsellerstodistinguishtheirproductsare claimedastrademarks.Wherethosedesignationsappearinthebook,andManning Publicationswasawareofatrademarkclaim,thedesignationshavebeenprintedininitialcaps orallcaps. Recognizingtheimportanceofpreservingwhathasbeenwritten,itisManning’spolicytohave thebookswepublishprintedonacid-freepaper,andweexertourbesteffortstothatend. Recognizingalsoourresponsibilitytoconservetheresourcesofourplanet,Manningbooks areprintedonpaperthatisatleast15percentrecycledandprocessedwithouttheuseof elementalchlorine. ManningPublicationsCo. Developmenteditor: EleshaHyde 20BaldwinRoad Revieweditor: AleksandarDragosavljevic´ POBox761 Technicaldevelopmenteditor: GaryPark ShelterIsland,NY11964 Projecteditor: KevinSullivan Copyeditor: AndyCarroll Proofreader: CorbinCollins Technicalproofreader: TomaszCielecki Typesetter: DottieMarsico Illustrator: AprilMilne Coverdesigner: MarijaTudor ISBN9781617294389 PrintedintheUnitedStatesofAmerica 1 2 3 4 5 6 7 8 9 10 – EBM – 23 22 21 20 19 18 To the amazing Nat and Evie, for your unwavering love and support whilst I was glued to my laptop. brief contents PART 1 GETTING STARTED WITH XAMARIN....................................1 1 ■ Introducingnativecross-platformapplicationswithXamarin 3 2 ■ HelloMVVM—creatingasimplecross-platform appusingMVVM 25 3 ■ MVVM—themodel-view–viewmodeldesignpattern 50 4 ■ Helloagain,MVVM—understandingandenhancingoursimple MVVMapp 81 5 ■ Whatarewe(a)waitingfor?Anintroductiontomultithreading forXamarinapps 113 PART 2 BUILDING APPS.............................................................153 6 ■ DesigningMVVMcross-platformapps 155 7 ■ Buildingcross-platformmodels 195 8 ■ Buildingcross-platformviewmodels 241 9 ■ BuildingsimpleAndroidviews 288 10 ■ BuildingmoreadvancedAndroidviews 319 11 ■ BuildingsimpleiOSviews 345 12 ■ BuildingmoreadvancediOSviews 385 v vi BRIEFCONTENTS PART 3 FROM WORKING CODE TO THE STORE............................409 13 ■ Runningmobileappsonphysicaldevices 411 14 ■ TestingmobileappsusingXamarinUITest 436 15 ■ UsingAppCentertobuild,test,andmonitorapps 467 16 ■ Deployingappstobetatestersandthestores 505 contents foreword xv preface xvii acknowledgments xix aboutthisbook xxi aboutthecoverillustration xxvi PART 1 GETTING STARTED WITH XAMARIN.................... 1 1 Introducing native cross-platform applications with Xamarin 3 1.1 IntroducingXamarinmobileapps 4 Vendor-specificnativeapps 5 ■ Cordova 6 ■ Xamarinnative apps 7 ■ Xamarin.Forms 10 ■ Xamarindevelopertools 12 Mobile-optimizeddevelopmentlifecycle 13 1.2 Creatingproduction-qualitymobileapps 14 Design 15 ■ Develop 17 ■ Test 18 ■ Build 21 Distribute 22 ■ Monitor 22 1.3 Rinseandrepeat… 23 2 Hello MVVM—creating a simple cross-platform app using MVVM 25 2.1 WhatareUIdesignpatterns? 26 2.2 MVVM—thedesignpatternforXamarinapps 27 2.3 Whatiscross-platformcode? 31 .NETStandardclasslibraries 32 vii viii CONTENTS 2.4 Gettingstarted—creatingyourfirstsolution 34 Requirements—whathardwareorsoftwaredoyouneedforeach mobileplatform? 35 ■ Creatingthesolution 36 ■ Whathavewe justcreated? 42 ■ Buildingandrunningtheapps 43 2.5 Isthisreallyacross-platformapp? 47 3 MVVM—the model-view–view model design pattern 50 3.1 Themodellayer 52 3.2 Theview-modellayer 53 Stateandbehavior 54 ■ Valueconversion 65 ■ Testability 67 3.3 Theviewlayer 68 3.4 Binding 69 Sourceandtarget 69 ■ Bindingmode 70 ■ Bindingisnot cross-platform 70 ■ Valueconverters 72 3.5 Theapplicationlayer 74 3.6 Navigation 75 View-first 76 ■ View-model–first 76 ■ Whichonetouse? 78 3.7 Revisitingthesquare-rootcalculatorapp 78 4 Hello again, MVVM—understanding and enhancing our simple MVVM app 81 4.1 AdeeperdiveintoourHelloCross-PlatformWorld app 82 Themodel 82 ■ Theviewmodel 82 ■ Theapplication layer 83 ■ Theview 84 4.2 ExpandingonourHelloWorldapp 92 Using.NETStandardpluginstoaccessdevice-specificcode 93 InstallingtheXamarintext-to-speechplugin 95 ■ Addingthe cross-platformcode 97 ■ Inversionofcontrol 98 ■ Wiringupthe AndroidUI 105 ■ WiringuptheiOSUI 106 5 What are we (a)waiting for? An introduction to multithreading for Xamarin apps 113 5.1 Whydoweneedmultithreadedcode? 114 5.2 Whatarethreads? 117 Buyingcoffee 117 ■ Sowhatisathread? 120 ■ Aquick roundup 121

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.