SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
Cross-Platform
Mobile
Development
that Works.
Rob DeRosa
Enterprise Customer Success Engineer,
Key Accounts
We’re Here to Help
Rob DeRosa
Enterprise Customer
Success Engineer,
Key Accounts
rob.derosa@xamarin.com
DESIGN – DEVELOP - INTEGRATE TEST MONITOR
LEARN
xamarin.com/testcloud
✓ Automated UI testing
✓ Thousands of real devices
✓ Integration with CI systems
✓ Test any mobile app
✓ Find bugs before your
customers do
xamarin.com/insights
✓ Crash Reporting
✓ Page Views
✓ Events
✓ User Behavior
✓ Integrations
✓ Live, instructor lead courses
✓ DeveloperCertification
✓ Guest lectures
✓ Office Hours
✓ Lightning talks
✓ Latest topics
xamarin.com/university
Xamarin Platform
Shared C# codebase • 100% native API access • High performance
iOS C# UI Windows C# UIAndroid C# UI
Shared C# Mobile C# Server
Linux/Mono
CoreCLR
Azure
Shared C# Client/Server
MapKit UIKit iBeacon CoreGraphics CoreMotion
System.Data System.Windows System.Numerics System.Core System.ServiceModel
System.Net System System.IO System.Linq System.Xml
Text-to-speech ActionBar Printing Framework Renderscript NFC
System.Data System.Windows System.Numerics System.Core System.ServiceModel
System.Net System System.IO System.Linq System.Xml
Microsoft.Phone Microsoft.Networking Windows.Storage Windows.Foundation Microsoft.Devices
System.Data System.Windows System.Numerics System.Core System.ServiceModel
System.Net System System.IO System.Linq System.Xml
Xamarin.iOS
Xamarin.Android
Traditional Xamarin Approach With Xamarin.Forms:
Share UI code, all native
iOS C# UI Windows C# UIAndroid C# UI
Shared C# Business Logic
Shared UI Code
Shared C# Business Logic
✓ 40+ Pages, layouts, and controls
(Build with C# or XAML)
✓ Two-way data binding
✓ Navigation
✓ Animation API
✓ Dependency Service
✓ Messaging Center
✓ Styles, Converters, Behaviors
Shared C# Business Logic
Shared UI Code
<?xml version="1.0"  encoding="UTF-­‐8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.MainPage">
<TabbedPage.Children>
<ContentPage Title="Profile"  Icon="Profile.png">
<StackLayout Spacing="20" Padding="20” VerticalOptions="Center">
<Entry Placeholder="Username“  Text="{Binding  Username}"/>
<Entry Placeholder="Password” Text="{Binding  Password}"
IsPassword="true"/>
<Button Text="Login"  TextColor="White” BackgroundColor="#77D065"
Command="{Binding  LoginCommand}"/>
</StackLayout>
</ContentPage>
<ContentPage Title="Settings"  Icon="Settings.png">
<!-­‐-­‐ Settings -­‐-­‐>
</ContentPage>
</TabbedPage.Children>
</TabbedPage>
Layouts
Pages
Stack Absolute Relative Grid ContentView ScrollView Frame
Content MasterDetail Navigation Tabbed Carousel
ActivityIndicator BoxView Button DatePicker Editor
Entry Image Label ListView Map
OpenGLView Picker ProgressBar SearchBar Slider
Stepper TableView TimePicker WebView EntryCell
ImageCell SwitchCell TextCell ViewCell
Xamarin.Forms Ecosystem
Sport
Development goals:
• Provide a way for colleagues to
challenge and rank up
• Gain a deeperunderstanding of
Forms – capabilities/limitations
• Learn Azure Mobile Services
(WebAPI, EF, push)
Application Design Goals
• Simplified registration/authentication
• Athlete’s can join multiple leagues
• View current rank within ladder
• Athlete stats & challenge history
• Facilitate challenge flow (accept, nudge, post results)
Topics we’ll cover
• Dead-simple authentication with SimpleAuth
• Absolutely awesome AbsoluteLayout
• Creating & consuming providers (Toast, HUD)
• Creating & consuming custom controls
• Tricks – ImageButton, styled DateTime picker
• Animations and Parallax
• Insights & UITest
Front end - Xamarin.Forms
• XAML
• Bindings
• Converters
• Styles
• Reusable Controls
• Custom Renderers
• Messaging Center
• Dependency Service
Back end – Azure Mobile
• WebAPI – REST/JSON
• Entity Framework w/
SQL Database
• Cross-templated push
notifications
• Notification hubs
• Tag-based
Demo Time
Absolute Layout
• Used to control size and position of child elements
• LayoutBounds is based on LayoutFlags value
• SizeProportional, PositionProportional, All
• Element’s LayoutBounds are proportional to the
AbsoluteLayout’s bounds
• The x and y anchor points are interpolated as the child
elements position changes
SimpleAuth
• SimpleAuth – stupid simple
• github.com/clancey/simpleauth
var scopes = new[] {
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile"
};
var api = new GoogleApi("google", "clientid", "clientsecret") {
Scopes = scopes,
};
var account = await api.Authenticate();
Sample
Providers
• Use an interface to define intent
• Implement on each platform
• Use the Dependency Service to get a platform-specific
implementation at runtime
• Smaller utilities can use the same namespace/class without
the need for an interface
ToastNotifier Provider
public interface IToastNotifier
{
Task<bool> Notify(ToastNotificationType type, string title, string description,TimeSpan duration, object context = null);
void HideAll();
}
define
[assembly: Dependency(typeof(Sport.Android.ToastNotifier))]
...
public class ToastNotifier : IToastNotifier
{
public Task<bool> Notify(ToastNotificationType type, string title, string description,
TimeSpan duration, object context = null)
{
var taskCompletionSource = new TaskCompletionSource<bool>();
Toast.MakeText(Forms.Context, description, ToastLength.Short).Show();
return taskCompletionSource.Task;
}
public void HideAll()
{
}
}
implement
var toaster = DependencyService.Get<IToastNotifier>();
toaster.Notify(type, title ?? type.ToString().ToUpper(), message, TimeSpan.FromSeconds(2.5f));
use
Custom, Reusable Controls
• Equivalent to a WPF/ASP.NET User
Control
• Use Bindable Properties to allow
consumers to bind values
• Templated controls can allow for inner
content
• Subclass ContentView
Little Tricks
• Use layers for precise layout - position and size
• Use opacity on controls to handle a user event
• Examples
• ImageButton
• Styled Date and Time pickers
• Use VectorImages instead of bitmaps
• Reduce application footprint by including a single .svg file
• Control tint color and size dynamically
• Use an IsBusy flag to trigger progress
• Use a Busy : IDisposable to ensure flag always gets set to false
• Use static converters – less code, fewer objects
• Run tasks safely using a proxy task-runner
Let’s check out some code!
Vector Image
• Control size and tint color dynamically
• Reduce footprint by resourcing a single .svg file
Animations
• Super easy to use
• Basic animations are supported
• Scale
• Translate
• Fade
• Rotate
• Easing (Bounce, Cubic, Linear, Sin)
Sample
Animations
var speed = (uint)App.AnimationSpeed;
var ease = Easing.SinIn;
var pushRect = new Rectangle(Content.Width, btnPush.Bounds.Y, btnPush.Bounds.Width, btnPush.Height);
btnPush.FadeTo(0, speed, ease);
await btnPush.LayoutTo(pushRect, speed, ease);
var contRect = new Rectangle(Content.Width, btnCont.Bounds.Y, btnCont.Bounds.Width, btnCont.Height);
btnCont.FadeTo(0, speed, ease);
await btnCont.LayoutTo(contRect, speed, ease);
Parallax Effect
void Parallax()
{
if(_imageHeight <= 0)
_imageHeight = photoImage.Height;
var y = scrollView.ScrollY * .4;
if(y >= 0)
{
//Move the Image's Y coordinate a fraction
//of the ScrollView's Y position
photoImage.Scale = 1;
photoImage.TranslationY = y;
}
else
{
//Calculate a scale that equalizes the height vs scroll
double newHeight = _imageHeight + (scrollView.ScrollY * -1);
photoImage.Scale = newHeight / _imageHeight;
photoImage.TranslationY = scrollView.ScrollY / 2;
}
}
Insights & UITest
• Add custom events or implement at a base level
• Use StyleID to store the element identifier
• Share UITest code between iOS and Android
Xamarin Test Recorder
Source Code Analysis
435 lines
3.3%
413 lines
3.1%
12,471 lines
93.6%
Q & A
Thank you!
rob.derosa@xamarin.com
https://github.com/xamarin/sport
https://www.youtube.com/watch?v=GmdvxDVluRA

Más contenido relacionado

La actualidad más candente

HTML5 and SVG
HTML5 and SVGHTML5 and SVG
HTML5 and SVG
yarcub
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
rsebbe
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive Graphics
Blazing Cloud
 

La actualidad más candente (16)

HTML5 and SVG
HTML5 and SVGHTML5 and SVG
HTML5 and SVG
 
rlottie - a new approach to motion graphics ui
rlottie -  a new approach to motion graphics uirlottie -  a new approach to motion graphics ui
rlottie - a new approach to motion graphics ui
 
Graphics on the Go
Graphics on the GoGraphics on the Go
Graphics on the Go
 
What's a Core Image? An Image-Processing Framework on iOS and OS X
What's a Core Image? An Image-Processing Framework on iOS and OS XWhat's a Core Image? An Image-Processing Framework on iOS and OS X
What's a Core Image? An Image-Processing Framework on iOS and OS X
 
Themeroller 2.0: Refactoring for Speed
Themeroller 2.0: Refactoring for SpeedThemeroller 2.0: Refactoring for Speed
Themeroller 2.0: Refactoring for Speed
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
Windows 8: Shapes and Geometries
Windows 8: Shapes and GeometriesWindows 8: Shapes and Geometries
Windows 8: Shapes and Geometries
 
Beginners Guide to Modeling with Maya
Beginners Guide to Modeling with MayaBeginners Guide to Modeling with Maya
Beginners Guide to Modeling with Maya
 
Starting Core Animation
Starting Core AnimationStarting Core Animation
Starting Core Animation
 
Universal Image Loader: Story, Architecture, FAQ
Universal Image Loader: Story, Architecture, FAQUniversal Image Loader: Story, Architecture, FAQ
Universal Image Loader: Story, Architecture, FAQ
 
Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»Сергій Міськів, «SwiftUI: Animations»
Сергій Міськів, «SwiftUI: Animations»
 
Fastest css3 animations
Fastest css3 animations Fastest css3 animations
Fastest css3 animations
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive Graphics
 
4,000 Adams at 90 Frames Per Second | Yi Fei Boon
4,000 Adams at 90 Frames Per Second | Yi Fei Boon4,000 Adams at 90 Frames Per Second | Yi Fei Boon
4,000 Adams at 90 Frames Per Second | Yi Fei Boon
 
Performant, accessible animations with CSS & a dash of JavaScript
Performant, accessible animations with CSS & a dash of JavaScriptPerformant, accessible animations with CSS & a dash of JavaScript
Performant, accessible animations with CSS & a dash of JavaScript
 
xaml overview
xaml overviewxaml overview
xaml overview
 

Similar a Xamarin 9/10 San Diego Meetup

WordCamp 2012 - Seth Carstens Presentation (Responsive Width)
WordCamp 2012 - Seth Carstens Presentation (Responsive Width)WordCamp 2012 - Seth Carstens Presentation (Responsive Width)
WordCamp 2012 - Seth Carstens Presentation (Responsive Width)
Seth Carstens
 
Win j svsphonegap-damyan-petev-mihail-mateev
Win j svsphonegap-damyan-petev-mihail-mateevWin j svsphonegap-damyan-petev-mihail-mateev
Win j svsphonegap-damyan-petev-mihail-mateev
Mihail Mateev
 
Presentation wpf
Presentation wpfPresentation wpf
Presentation wpf
danishrafiq
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on Rails
Avi Kedar
 

Similar a Xamarin 9/10 San Diego Meetup (20)

Intuit Mobile Custom Views
Intuit Mobile Custom ViewsIntuit Mobile Custom Views
Intuit Mobile Custom Views
 
WordCamp 2012 - Seth Carstens Presentation (Responsive Width)
WordCamp 2012 - Seth Carstens Presentation (Responsive Width)WordCamp 2012 - Seth Carstens Presentation (Responsive Width)
WordCamp 2012 - Seth Carstens Presentation (Responsive Width)
 
Serverless Computing with Azure Functions and Xamarin
Serverless Computing with Azure Functions and XamarinServerless Computing with Azure Functions and Xamarin
Serverless Computing with Azure Functions and Xamarin
 
Building SPA’s (Single Page App) with Backbone.js
Building SPA’s (Single Page App) with Backbone.jsBuilding SPA’s (Single Page App) with Backbone.js
Building SPA’s (Single Page App) with Backbone.js
 
Win j svsphonegap-damyan-petev-mihail-mateev
Win j svsphonegap-damyan-petev-mihail-mateevWin j svsphonegap-damyan-petev-mihail-mateev
Win j svsphonegap-damyan-petev-mihail-mateev
 
Presentation wpf
Presentation wpfPresentation wpf
Presentation wpf
 
Tech Talk on Cloud Computing
Tech Talk on Cloud ComputingTech Talk on Cloud Computing
Tech Talk on Cloud Computing
 
Mike Taulty MIX10 Silverlight 4 Accelerated Fundamentals
Mike Taulty MIX10 Silverlight 4 Accelerated FundamentalsMike Taulty MIX10 Silverlight 4 Accelerated Fundamentals
Mike Taulty MIX10 Silverlight 4 Accelerated Fundamentals
 
DevOps Cardiff - Monitoring Automation for DevOps
DevOps Cardiff - Monitoring Automation for DevOpsDevOps Cardiff - Monitoring Automation for DevOps
DevOps Cardiff - Monitoring Automation for DevOps
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on Rails
 
Mobile gotcha
Mobile gotchaMobile gotcha
Mobile gotcha
 
Intro to Xamarin
Intro to XamarinIntro to Xamarin
Intro to Xamarin
 
How to create a Function App on Cosmos DB
How to create a Function App on Cosmos DBHow to create a Function App on Cosmos DB
How to create a Function App on Cosmos DB
 
Cross platform mobile app development with Xamarin
Cross platform mobile app development with XamarinCross platform mobile app development with Xamarin
Cross platform mobile app development with Xamarin
 
Automated UI Testing
Automated UI TestingAutomated UI Testing
Automated UI Testing
 
Future-Proof Responsive Web Design #RWD
Future-Proof Responsive Web Design #RWDFuture-Proof Responsive Web Design #RWD
Future-Proof Responsive Web Design #RWD
 
Future proof rwd
Future proof rwdFuture proof rwd
Future proof rwd
 
App innovationcircles xamarin
App innovationcircles xamarinApp innovationcircles xamarin
App innovationcircles xamarin
 
AWS 2016 re:Invent Launch Summary
AWS 2016 re:Invent Launch SummaryAWS 2016 re:Invent Launch Summary
AWS 2016 re:Invent Launch Summary
 
04 managing the database
04   managing the database04   managing the database
04 managing the database
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Xamarin 9/10 San Diego Meetup

  • 2. We’re Here to Help Rob DeRosa Enterprise Customer Success Engineer, Key Accounts rob.derosa@xamarin.com
  • 3. DESIGN – DEVELOP - INTEGRATE TEST MONITOR LEARN
  • 4. xamarin.com/testcloud ✓ Automated UI testing ✓ Thousands of real devices ✓ Integration with CI systems ✓ Test any mobile app ✓ Find bugs before your customers do
  • 5. xamarin.com/insights ✓ Crash Reporting ✓ Page Views ✓ Events ✓ User Behavior ✓ Integrations
  • 6. ✓ Live, instructor lead courses ✓ DeveloperCertification ✓ Guest lectures ✓ Office Hours ✓ Lightning talks ✓ Latest topics xamarin.com/university
  • 8. Shared C# codebase • 100% native API access • High performance iOS C# UI Windows C# UIAndroid C# UI Shared C# Mobile C# Server Linux/Mono CoreCLR Azure Shared C# Client/Server
  • 9. MapKit UIKit iBeacon CoreGraphics CoreMotion System.Data System.Windows System.Numerics System.Core System.ServiceModel System.Net System System.IO System.Linq System.Xml
  • 10. Text-to-speech ActionBar Printing Framework Renderscript NFC System.Data System.Windows System.Numerics System.Core System.ServiceModel System.Net System System.IO System.Linq System.Xml
  • 11. Microsoft.Phone Microsoft.Networking Windows.Storage Windows.Foundation Microsoft.Devices System.Data System.Windows System.Numerics System.Core System.ServiceModel System.Net System System.IO System.Linq System.Xml
  • 13.
  • 14. Traditional Xamarin Approach With Xamarin.Forms: Share UI code, all native iOS C# UI Windows C# UIAndroid C# UI Shared C# Business Logic Shared UI Code Shared C# Business Logic
  • 15. ✓ 40+ Pages, layouts, and controls (Build with C# or XAML) ✓ Two-way data binding ✓ Navigation ✓ Animation API ✓ Dependency Service ✓ Messaging Center ✓ Styles, Converters, Behaviors Shared C# Business Logic Shared UI Code
  • 16. <?xml version="1.0"  encoding="UTF-­‐8"?> <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MyApp.MainPage"> <TabbedPage.Children> <ContentPage Title="Profile"  Icon="Profile.png"> <StackLayout Spacing="20" Padding="20” VerticalOptions="Center"> <Entry Placeholder="Username“  Text="{Binding  Username}"/> <Entry Placeholder="Password” Text="{Binding  Password}" IsPassword="true"/> <Button Text="Login"  TextColor="White” BackgroundColor="#77D065" Command="{Binding  LoginCommand}"/> </StackLayout> </ContentPage> <ContentPage Title="Settings"  Icon="Settings.png"> <!-­‐-­‐ Settings -­‐-­‐> </ContentPage> </TabbedPage.Children> </TabbedPage>
  • 17. Layouts Pages Stack Absolute Relative Grid ContentView ScrollView Frame Content MasterDetail Navigation Tabbed Carousel
  • 18. ActivityIndicator BoxView Button DatePicker Editor Entry Image Label ListView Map OpenGLView Picker ProgressBar SearchBar Slider Stepper TableView TimePicker WebView EntryCell ImageCell SwitchCell TextCell ViewCell
  • 20.
  • 21. Sport Development goals: • Provide a way for colleagues to challenge and rank up • Gain a deeperunderstanding of Forms – capabilities/limitations • Learn Azure Mobile Services (WebAPI, EF, push)
  • 22. Application Design Goals • Simplified registration/authentication • Athlete’s can join multiple leagues • View current rank within ladder • Athlete stats & challenge history • Facilitate challenge flow (accept, nudge, post results)
  • 23. Topics we’ll cover • Dead-simple authentication with SimpleAuth • Absolutely awesome AbsoluteLayout • Creating & consuming providers (Toast, HUD) • Creating & consuming custom controls • Tricks – ImageButton, styled DateTime picker • Animations and Parallax • Insights & UITest
  • 24. Front end - Xamarin.Forms • XAML • Bindings • Converters • Styles • Reusable Controls • Custom Renderers • Messaging Center • Dependency Service Back end – Azure Mobile • WebAPI – REST/JSON • Entity Framework w/ SQL Database • Cross-templated push notifications • Notification hubs • Tag-based
  • 26. Absolute Layout • Used to control size and position of child elements • LayoutBounds is based on LayoutFlags value • SizeProportional, PositionProportional, All • Element’s LayoutBounds are proportional to the AbsoluteLayout’s bounds • The x and y anchor points are interpolated as the child elements position changes
  • 27. SimpleAuth • SimpleAuth – stupid simple • github.com/clancey/simpleauth var scopes = new[] { "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile" }; var api = new GoogleApi("google", "clientid", "clientsecret") { Scopes = scopes, }; var account = await api.Authenticate();
  • 29. Providers • Use an interface to define intent • Implement on each platform • Use the Dependency Service to get a platform-specific implementation at runtime • Smaller utilities can use the same namespace/class without the need for an interface
  • 30. ToastNotifier Provider public interface IToastNotifier { Task<bool> Notify(ToastNotificationType type, string title, string description,TimeSpan duration, object context = null); void HideAll(); } define [assembly: Dependency(typeof(Sport.Android.ToastNotifier))] ... public class ToastNotifier : IToastNotifier { public Task<bool> Notify(ToastNotificationType type, string title, string description, TimeSpan duration, object context = null) { var taskCompletionSource = new TaskCompletionSource<bool>(); Toast.MakeText(Forms.Context, description, ToastLength.Short).Show(); return taskCompletionSource.Task; } public void HideAll() { } } implement var toaster = DependencyService.Get<IToastNotifier>(); toaster.Notify(type, title ?? type.ToString().ToUpper(), message, TimeSpan.FromSeconds(2.5f)); use
  • 31. Custom, Reusable Controls • Equivalent to a WPF/ASP.NET User Control • Use Bindable Properties to allow consumers to bind values • Templated controls can allow for inner content • Subclass ContentView
  • 32. Little Tricks • Use layers for precise layout - position and size • Use opacity on controls to handle a user event • Examples • ImageButton • Styled Date and Time pickers • Use VectorImages instead of bitmaps • Reduce application footprint by including a single .svg file • Control tint color and size dynamically • Use an IsBusy flag to trigger progress • Use a Busy : IDisposable to ensure flag always gets set to false • Use static converters – less code, fewer objects • Run tasks safely using a proxy task-runner Let’s check out some code!
  • 33. Vector Image • Control size and tint color dynamically • Reduce footprint by resourcing a single .svg file
  • 34. Animations • Super easy to use • Basic animations are supported • Scale • Translate • Fade • Rotate • Easing (Bounce, Cubic, Linear, Sin)
  • 36. Animations var speed = (uint)App.AnimationSpeed; var ease = Easing.SinIn; var pushRect = new Rectangle(Content.Width, btnPush.Bounds.Y, btnPush.Bounds.Width, btnPush.Height); btnPush.FadeTo(0, speed, ease); await btnPush.LayoutTo(pushRect, speed, ease); var contRect = new Rectangle(Content.Width, btnCont.Bounds.Y, btnCont.Bounds.Width, btnCont.Height); btnCont.FadeTo(0, speed, ease); await btnCont.LayoutTo(contRect, speed, ease);
  • 37. Parallax Effect void Parallax() { if(_imageHeight <= 0) _imageHeight = photoImage.Height; var y = scrollView.ScrollY * .4; if(y >= 0) { //Move the Image's Y coordinate a fraction //of the ScrollView's Y position photoImage.Scale = 1; photoImage.TranslationY = y; } else { //Calculate a scale that equalizes the height vs scroll double newHeight = _imageHeight + (scrollView.ScrollY * -1); photoImage.Scale = newHeight / _imageHeight; photoImage.TranslationY = scrollView.ScrollY / 2; } }
  • 38. Insights & UITest • Add custom events or implement at a base level • Use StyleID to store the element identifier • Share UITest code between iOS and Android
  • 40. Source Code Analysis 435 lines 3.3% 413 lines 3.1% 12,471 lines 93.6%
  • 41. Q & A