Xamarin.Forms Vs Xamarin Vs Native Mobile App Development
There has been lot of scuffle among developers as to which is a better platform for mobile app development. What to use, when to use, why to use? Here I talk about the new Xamarin.Forms, Xamarin and their utility as compared to native platforms.
Xamarin.Forms is a cross-platform UI toolkit which allows developers to easily create native user interface layouts that can be shared across Android, iOS, and Windows Phone.
Xamarin: Xamarin without Xamarin.Forms is the traditional method of creating cross-platform applications with Xamarin. Here we use a native Xamarin.Android project or a native Xamarin.iOS project to define UI for each platform, we can add Windows Phone apps also.
Native Mobile app development: Apps developed by native development used on specific mobile operating system. UI and Business logic are developed separately in Objective-C or Swift for iOS and Java for Android.
Why should a developer use Xamarin.Forms:
- Helpful for identical UI
Xamarin.Forms allows to have an almost identical UI layout on all platforms (Android, iOS, and Windows Phone) with shared UI code.
Main.xaml <?xml version="1.0" encoding="UTF-8"?> <TabbedPage xmlns="" xmlns:x="" x:Class="MyApp.LoginPage"> <TabbedPage.Children> <ContentPage Title="Profile" Icon="ProfileIcon.png"> <StackLayout Spacing="20" Padding="10" VerticalOptions="Center"> <Entry Placeholder="Username" Text="{Binding Username}"/> <Entry Placeholder="Password" Text="{Binding Password}" IsPassword="true"/> <Button Text="Login" TextColor="White" BackgroundColor="#6BBB5A" Command="{Binding LoginCommand}"/> </StackLayout> </ContentPage> <ContentPage Title="Settings" Icon="SettingsIcon.png"> <!-- Settings --> </ContentPage> </TabbedPage.Children> </TabbedPage>
- Reduces development time
Since more code sharing is possible using Xamarin.Forms, it reduces the overall development time and the app can be developed in short time span. Xamarin.Forms condense the tedious and repetitive bits of cross-platform multi-device programming.
- Regular feature enhancement and support from Microsoft
Microsoft’s investment in Xamarin has helped the platform to improve upon the security and other features. Moreover, Microsoft has started collaborating Xamarin with other inhouse technologies/platforms.
Every app needs a backend, and with Azure Mobile Apps it become simple to add backend to your mobile application by adding as little as four lines of code.
Enterprise Mobility Applications can be developed using Xamarin.Forms, as these apps require little platform-specific functionality, identical UI and more effort related to business logic.
- XAML markup
XAML code is short and easy to read. The developer can choose between C# or XAML markup to write code with attractive UI, data-binding and styles.
The code written in C# for the UI i.e.
Main.cs using Xamarin.Forms; var profilePage = new ContentPage { Title = "Profile", Icon = "ProfileIcon.png", Content = new StackLayout { Padding = 20, Spacing = 20, VerticalOptions = LayoutOptions.Center, Children = { new Entry { Placeholder = "Username"}, new Entry { Placeholder = "Password", IsPassword = true }, new Button { Text = "Login", TextColor = Color.White, BackgroundColor = Color.FromHex("6BBB5A") }}} }; var settingsPage = new ContentPage { Title = "Settings", Icon = "SettingsIcon.png", (...) }; var loginPage = new TabbedPage { Children = { profilePage, settingsPage } };
When to use Xamarin technology
- For complex UI requirements
If your app design is complex, it’s recommended not to use Xamarin.Forms. But in case of apps where code sharing is more essential than custom UI, Xamarin.Forms can be used.
Suppose if you have to develop a ‘listview’ with drag and drop functionality. Xamarin.Forms requires much efforts than Xamarin.Android or Xamarin.iOS development.
- XAML constraints
Xamarin.Forms uses XAML. There are certain performance constraints like: XAML views are parsed at runtime, which adds additional overhead when creating views which affects performance.
- Limited Functionality
Few methods and properties which are platform specific are not available in Xamarin.Forms. This requires you to write the code for different platforms i.e. Xamarin.Android or Xamarin.IOS
Common code to multiple platforms
Networking, parsing logic (including error handling), navigation logic , business logic, models are shared between all versions of the app. UI specific work is done in Xamarin.Android ,Xamarin.IOS and Windows Phone.
UI specific code is done in Xamarin.iOS, Xamarin.Android, Windows Phone which are explained below:
- iOS: Xamarin.iOS allows us to create iOS applications in C# using the same UI controls we would in Objective-C and Xcode.
- Android: Xamarin.Android allows us to create Android applications in C# using the same UI controls we would in Java.
- Windows Phone: Windows Phone development is done native in C# with shared business logic.
Based on simple mathematics we present the complete picture below:
Comparison of Xamarin.Forms Vs Xamarin without Xamarin.Forms Vs Native development :
Effort chart
Assuming the development cost/hour to be $30, and work/day to be 8 hours.
Cost of using Xamarin.Forms:
If we use Xamarin.Forms and with effort of 100 man days, it will cost $24000(100 * 8 * $30).
Cost of using Xamarin: without Xamarin.Forms:
If we use Xamarin(without Xamarin.Forms) and with effort of 200 man days, it will cost $48000(200 *8 * $30).
Cost of using Native development
If we use native development and with effort of 300 man days, it will cost $72000(300 * 8* $30).
Money Saved:
Using Xamarin platform is of immense value be it Xamarin.Forms or Xamarin.Android and Xamarin.IOS. The above scenario helps understand the significance and value generated through Xamarin.