Emixam23
Emixam23

Reputation: 3964

Xamarin - Different views for each platform

I am currently working on Xamarin project and after some research, I am confused about how cross platform UI works.

Let's take the 3 following smartphones:

  1. Samsung Galaxy S5
  2. iPhone 6 Microsoft
  3. Lumia 640 LTE

Three phones with three different types of controls. Samsung has 3 buttons at the bottom, whereas the iPhone has just 1 button. The Microsoft phone has 3 buttons like the Samsung, but those are different. So this is why I am confused.

The cross platform design shown in the tutorials such as this tutorial shows a shared design.

However, my goal isn't to make the same interface for each platform. I saw this article which is similar to what I want to make. We have the same app logic, but the design depends of the platform

Example app screenshots In order: Android, iOS and Windows Phone

Now, here is the app architecture proposed by Xamarin

Xamarin app topology

To achieve a different design per platform, I must not create a "Forms Xaml Page" in the shared project, but create 3 different pages (1 per platform). However, I'm not sure how this can be achieved.

At the launch, each app executes the following code line:

LoadApplication(new App());

So, if I make 3 different interfaces, how can I load the one specific to the platform the app is running on?

Also, if we use the MVC pattern (I know about MVVM, I just do not understand it at the moment), make 3 differents views, each one with a controller, but only share models/data/motor. (MVC -> 1M/3V/3C).

Upvotes: 1

Views: 1113

Answers (2)

Stefan Wanitzek
Stefan Wanitzek

Reputation: 2124

A good approach for a cross-platform project with platform-specific UIs is to use MvvmCross or a similar library.

The TipCalc-Project is a sample app which shares business logic via a Portable Class Library (PCL) and makes use of the MVVM-pattern (Model View ViewModel). You have a separated UI-project per platform (Android, iOS, ...) and reuse the functionality from your PCL.

This allows to share a large amount of your business code without using Xamarin.Forms and without any compromises regarding your UI.

You should have a basic understanding of MVVM and Dependency Injection for this approach.

Upvotes: 3

BytesGuy
BytesGuy

Reputation: 4127

With Xamarin.Forms, you are sharing the app logic and potentially all of the UI code by using the Forms API. This means the app interface will be fairly similar on all platforms.

With the non-Forms approach you share the app logic and then any UI code can go in the platform specific project and use the platform specific API.

Reading your requirements, I would suggest you look towards the non-Forms based approach of sharing code with Xamarin, rather than using Forms.

We have some good guides to get your started with this as well as a sample and case study.

Upvotes: 2

Related Questions