Xamarin Forms is a fantastic abstraction on top of iOS, Android, Windows and Mac. It allows you to write one UI that is shared between platforms using the underlying UI controls native to each OS. The downside to this is the lowest-common-denominator model - only the features that are available on all platforms are provided out of the box. Luckily Xamarin provides a swathe of techniques to allow you to add platform specific tweaks.
In this session we will look at some of these techniques, from the small number of platform specifics provided out of the box by Xamarin, to writing effects and implementing your own custom renderers. Each technique will be demonstrated with a live coded example showing just how easy they are to get working.
By the end of this session you will have an understanding of the different tools you can use to make platform-specific tweaks to the UI, and be able to write your own effects and custom renderers.
Write once, run everywhere - iOS, Android, UWP, WPF, macOS, Linux, Tizen, Native UI
To most Forms IS Xamarin
Fast to market - EROAD Inspect
To make Forms work on all platforms means it’s a lowest common denominator model
Only features that work on all platforms are available
Simplicity was key as well, so only the basics were ported
Beautiful design - part of it is good typography.
Designers love fonts and want different weights all over the place
Not easy in Forms
Problem - designer wants light fonts. How can we do this?
Look at two ways to do it - effects, custom renderers
Only going to cover iOS and Android, but principles apply to all platforms
Effects - lightweight ways to manipulate underlying controls
Attach to a control to allow you to tweak the underlying control
Forms - wraps native controls in Forms controls
Put an entry on the screen, on iOS you get a UITextField, Android gives an EditText
Effects attach to these controls
Effects are NOT control specific - can attach to any control
Demo on for iOS and Android
Effect for font
Two parts - platform effect for the platform, routing effect in core project
Effects have an Id with a two part key - resolution group name and effect name
Platform specific - resolution group name registered in assembly as first part of key
Effect exported by name
Allows multiple effect NuGets with same effect name to not clash.
Effects can be read off control to evaluate properties
All forms controls use renderers to convert from Forms to Native
These renderers are open, so you can tweak to suit, or write your own
All forms controls use renderers to convert from Forms to Native
These renderers are open, so you can tweak to suit, or write your own
ExportRenderer tells Xamarin Forms which renderer to use for a control
You can export your own renderers to ‘override’ the default from Xamarin Forms
Own renderers derived from the Xamarin ones with customizations
Demo on for iOS and Android
Renderer
Renderer has control and element - native control and Forms element
Effects when you want to tweak certain controls only, and want to add effects to multiple types
Renderers for tweaking all controls of one type