Enable and control iOS 11 Large Titles in Xamarin.Forms

With iOS 11, Apple introduced a bunch of new design elements to its mobile platform. One of them are larger titles, that sit in the Navigation Bar and can be scrolled away when more space is needed. Large Titles can be enabled with a few lines of code in iOS. To use them with Xamarin.Forms, we need to extend the framework on our own, as the new titles are not officially supported yet.

iOS 11 Large Titles Screenshots

 

Enable Large Titles

To add support for Large Titles in Xamarin.Forms all we need to do is overriding the existing NavigationRenderer and enable Large Titles application-wide. Simply add this Renderer to your iOS project and they will be shown everywhere.

 

Control when to display Large Titles

Being in control of when to display the new titles or not is a nice feature as they totally do not make sense on every page and this gives us more flexibility on when and where to use them.

Unfortunately, Xamarin.Forms is struggling with the new Large Titles and bottom offsets sometimes, especially when combined with a TabbedPage. So we need a way to switch them off manually for each page.

Extend Content Page

For this, create a new type of ContentPage in your Xamarin.Forms project, that is aware of Large Titles and offers a property to switch them on and off manually.

Every page, that should be able to switch off large titles (we enable them by default in the Custom Renderer above), must now be type of our newly created page. This has to be declared in XAML…

… and the code-behind as well.

Add a Custom Renderer

All we need now is a Custom Renderer for the new page, that respects the HasLargeTitle property and sets the in iOS 11 introduced LargeTitleDisplayMode property accordingly. Create a new Custom Renderer in the iOS project and expose it.

Et voilà! With 12 lines of code, Xamarin.Forms becomes capable of using the new Large Titles and looks nice and modern for Apple’s new version of iOS.

Swipecards: A Tinder-like swipe control for Xamarin.Forms

For a side-project of mine, I created a Xamarin.Forms control, that lets the user wipe away cards in different directions, similar to the popular Tinder app.

The control is still work in progress and will be extended over time, but I decided to publish the current version as it was good enough to go into production for my project. Feel free to use it, contribute and provide feedback! It supports fully customizable ItemTemplates and Data Binding for most properties.

Take a look at the GitHub Repository for further details and a full API-reference. You will also find a sample project to play around with.

If you want to use it in your projects, simply add the NuGet package to your Xamarin.Forms project and add the control in your XAML layout.

Avoid Simulator, Emulator and Testing statistics in Visual Studio Mobile Center

When tracking usage statistics and crashes with Visual Studio Mobile Center, you usually only want real-world data in there and filter out data that gets generated while developing or testing the app. To avoid sophisticated insights like those in the screenshot below, developers need to define, when Visual Studio Mobile Center should track data and when it should not.

Visual Studio Mobile Center's Analytics tabs shows development data

Analytics and crash data usually should not impact those statistics, when an app is

  • Running in Debug Mode
  • Running on a Simulator or Emulator
  • Running in the Xamarin Test Cloud

Before starting the client analytics using the MobileCenter.Start() method, we should scan the environment to decide whether to run this command or not. For this, we implement a method on each platform, that scans if the current app environment is a real-world scenario.

Debug Mode can be checked easily using the #if DEBUG compiler directive. Even when not running on .NET, most other frameworks should have an equivalent for this.

If the app is running in a Simulator or Emulator can be detected by checking the current runtime architecture with Runtime.Arch on iOS or Fingerprint with Build.Fingerprint on Android.

The Xamarin Test Cloud sets specific environment variables on its devices, that can get examined using Environment.GetEnvironmentVariable().

Abstraction

Creating an interface for the small Environment Service helps to unify its implementations and usage within Dependency Injection.

iOS implementation

On Apple’s platforms, an easy architecure check tells us, if the app is running or a simulator or real device.

Android implementation

Android does not have the concepts of Simulators and uses full Hardware Emulation instead, which means we have to check the real or emulated devices’ fingerprints. There are multiple Android Emulators out there but looking for "vbox" or "generic" did the trick for me.

Add the real-world check before starting to track analytics

Before starting the MobileCenter service now, we can simply fire an EnvironmentService.IsRunningInRealWorld() check and only proceed if it is positive.

When using Xamarin.Forms, just add [assembly: Xamarin.Forms.Dependency(typeof(EnvironmentService))] to the platform implementations and call them using Xamarin.Form’s built-in Dependency Service.

This should avoid having sophisticated Development and Testing data in you Visual Studio Mobile Center Analytics and Crashes section. Enjoy the cleaned up dashboards!

Useful Developer Tools #8: Colormind

A while ago, I wrote about the Adobe Color Wheel here, which helps design noobies to create a color scheme for their product using colors that fit together. The challenge with Color Wheel is, that you still need a “feeling” for colors to create a good looking scheme.

Colormind goes one step further and literally generates you a complete color scheme without having the user know anything about colors. It also offers pre-defined schemes for Christmas, Spring and more. When you are struggling with color schemes, colormind.io might be something for you!

 

Replace your old cronjobs with free Azure Functions within 5 minutes

For some of my older projects, I had some repetitive tasks where a simple job triggers a script to run and load some data from the web. For this, I used good old cronjobs like the ones cronjob.de offers. As this was expensive und quite unsatisfying in terms of flexibility, I decided to move them over to Azure, which just took me five minutes and cost me nothing.

My old cronjobs just did a super simple thing: They called a PHP script every 15 minutes, which was hosted at a hosting provider and did some work for me. So the cronjobs were simple HTTP calls and I had no feedback about results, success or failure. So it was time to move the over to Azure Functions.

Create an Azure Function App

Azure Functions are the Serverless solution that Microsoft offer in their cloud. In a Serverless context, you even go one step further than PaaS does and only provide some code to the cloud that should run, when  you want it to. You don’t care about the architecture beneath it and just want your code to run. Perfect for recurring jobs.

To create a new Azure Function, log into the Azure Portal, select Add > Compute > Function App and follow the wizard to create a service for your functions.

Add your first function

Once Azure has finished creating your Function App, you can create your first function in it. The quickstart guides you through the creation of your first one. As we want to create a cronjob equivalent, the Timer scenario looks like the best one for us. As a .NET guy, I choose C# as my language, but you can also pick JavaScript is you like.

As soon as the function got created, we can start coding. To replace my existing cronjobs, I wrote the following lines.

Define the trigger

Now that the logic is created, we have to define a trigger for the function. At the side menu, we can find several settings. At the Integrate tab, we can define triggers. Because we chose the Timer template earlier, a timer trigger has already been created for us. In the Schedule box, we can define the trigger time formatted as a Cron expression. The predefined 0 */5 * * * * will trigger the function every 5 minutes, so let’s increase it to 15 minutes: 0 */15 * * * *.

Test your function

To test what we created, get back to the Develop tab and open the Logs by clicking at the according button at the top. Now we can Run the function and follow its process in the Logs window. For more details, you can visit the Monitor tab in the menu.

What does it cost?

Nothing. For the moment, at least. As we chose the Consumption Plan as the Hosting plan for our function when creating them, we will be billed on a pay-per-use mode.

The price for execution time is $0.000016/GB-s and $0.20 per Million executions. For us it is still free, as the first 400,000 GB-s or the first 1 Million executions come for free every month. If your function got 1 GB of RAM attached and runs for one second, Microsoft counts this as a GB-s.

Does it scale?

It does and this is one of the coolest things about Azure Functions. Up to a specific (very large) size, these functions scale automatically and provision the best possible compute base automatically to keep them performant. But please keep in mind that the programming model for Azure Functions is stateless and there are VMs running below, that are not visible for you. So state-inconsistency and VM startup time is something you might have to consider.

What’s next?

If you liked the concept of Azure Functions, why don’t you create more? There are many more triggers beside the timer like WebHooks, EventHubs, or Blob Storage changes. Of yourse, you can alos trigger a function manually, with the REST API. You can also define outputs for the results of your functions to use them for processing data.

So give it a try and fall in love with Serverless Computing!

Useful Developer Tools #7: Spotify playlist “Ambience While Coding”

The new year has just started and many of us still have some holiday to spend time on our beloved coding projects. I personally love listening to some music while coding but especially when it comes to concentration, I find songs with lyrics distracting.

Good thing, that Spotify user Emiliy Cheng created a beautiful playlist full of orchestral and movie songs, perfectly for coding: Ambience While Coding (Orchestral, Epic, Movie Scores). If you are in love with code and music, you should check it out!

Interested in more Useful Developer Tools? Take a look at the whole series.

Wallpaper of the month (December 2016): Blurry Corn

New month, new wallpaper. As it is getting really cold outside, I decided to use a summer wallpaper, that is also compatible with 21:9 ulta-wide screens!

You can find all wallpapers of this series inside this OneDrive folder.

Blurry Corn

Free self-guided Xamarin workshop

Two days ago, I gave a Xamarin workshop at the Microsoft Technical Summit 2016 conference in Darmstadt (Germany). This was a full-day workshop with a Xamarin introduction at the beginning and a guided workshop experience, where the participants learned how to

  • Setup a Xamarin development environment
  • Create native cross-platform apps with Xamarin
  • Share as much business logic as possible between iOS, Android and Windows
  • Share layouts with Xamarin.Forms
  • Create a clean architecture
  • Spin up an Azure Cloud backend and connect the app to it easily

I decided to make this workshop open and available for free, so that anyone can take it as a self-guided tour through the world of Xamarin development. So feel free to use it in whichever form you like. If you get stuck or have questions, don’t hesitate to ask them here in the comments.

Screen Shot 2016-12-10 at 22.30.58

Beside, as this is an open-source project, contributions are very welcome! If you know something better, have a good idea, want to correct something or know a better teaching style please feel free to create a pull request. This workshop is getting better with every single contribution!

Have fun with it. You can find the workshop on GitHub.

 

Useful Developer Tools #6: App Icons and Resizers

Finding the right icons for your applications can be a tough task. Especially resizing them for the different platforms is super annoying. That is why I would like to share my favorite icon sources and resizing tools with you.

Finding icons

There are many different icon sources in the web with different quality and range. These are my favorites.

The Noun Project
Pros: Icons for literally everything, CC and paid licenses
Cons: Account required, CC icons come with attribution inside the image

Flaticon
Pros: iOS Style mainly, dimensions and color can be modified online, no account
Cons: iOS Style mainly

Resizing icons

Finding icons is only the first step. In most cases (especially when developing for mobile) icons have to be resized for different screen resolutions and densities. Here are my favorite tools for doing this:

App Icon Resizer
Pros: Resizes for iOS and Android, web-tool
Cons: No Windows, only for toolbar and application icons

Final Android Resizer
Pros: Resizes everything for Android
Cons: No iOS or Windows, Java tool (has to be downloaded)

I hope that helps to find a smarter and faster way through the icon jungle. If you know some other cool icon sources or tools, please reveal them in the comments!

Move your Xamarin.Forms Toolbar to the bottom on Windows

While iOS and Android typically have their toolbars and menus at the top of the page, on Windows you will find it at the bottom in most cases. Unfortunately, Xamarin.Forms renders all toolbar to the top of the page per default, even on Windows. So if you define a toolbar like this, it will appear at the top of the page, when running the Winows application, which is very uncommon there and might look strange to a Windows user.

Previously, you had to write a custom renderer, to modify the toolbar. Xamarin.Froms 2.3.3, which has faced its stable release a couple of days ago, introduces Platform-Specifics, that can modify some UI elements for specific platforms. The toolbar is one of them and we can attach a ToolbarPlacement to it with a single line of code.

However, these Platform-Specifics are still very limited, so we have to keep in mind that

  • Toolbar Placement can only be set application wide, not per page
  • Toolbar Placement can only be set on a NavigationPage

xamFormsBottomToolbar

But it works and it is only one single line, that gives a Xamarin.Forms app on Windows a way more natural look!