XamarinXamarin.AndroidXamarin.Forms

What is .NET MAUI? Evolution of Xamarin.Forms

Contents

Microsoft held its annual Microsoft Build conference for developers using Windows, Xamarin, Microsoft Azure and other Microsoft technologies in May 2020. This conference had important news for mobile application developers. .NET Multiplatform App UI, ie .NET MAUI, was the main agenda of this conference.

Microsoft plans to bring all .NET platforms together with .NET 5. The MAUI Framework is also a result of this. It will no longer be necessary to develop separate projects on each platform as in Xamarin.Forms. With a single project architecture, it will be possible to develop on all platforms.

In this post, we will examine this issue that concerns mobile application developers in more detail. However, if you want to understand the subject better, let’s first take a brief look at Xamarin’s journey.

Xamarin’s Journey

  • 2011– Miguel de Icaza and Nat Freidman founded Xamarin. With Xamarin, they offered a solution that can develop cross-platform applications on .NET and C# based Android, iOS and Windows.
  • 2013– Xamarin has released 2.0. This version consisted of Xamarin Studio and Visual Studio components.
  • 2014– Xamarin released Xamarin.Forms to solve the user interface problem for each platform. It is now possible to develop interfaces and define functions to these interfaces via C# or XAML.
  • 2016– Microsoft bought Xamarin.

And we came to today’s Xamarin from those days with constant updates.

Now back to the main topic.

What is .NET MAUI?

In short, .NET Multiplatform App UI is the evolution of .NET MAUI Xamarin.Forms. Besides all the features in Xamarin.Forms, MAUI will come with many new features.

In conventional Xamarin projects, we were creating separate projects for each platform and continuing on that project. In other words, we were creating separate projects for Android and iOS for Windows and developing separate projects. Naturally, this resulted in a situation that took a lot of time and increased the project size considerably.

With MAUI, it will be possible to develop applications for Android, iOS and Windows over a single project architecture. So 3 different layers come down to 1. We will no longer have to wait long while running a project.

MAUI, Introducing dotnet multiplatform app ui
MAUI, Introducing dotnet multiplatform app ui

In the traditional Xamarin project structure, resources, images and special functions were found in platform-specific files. With MAUI, different platforms will be under Platforms, resources under Resources, pictures under Images.

MAUI, Multiplatform app development
MAUI, Multiplatform app development

We will also be able to develop MAUI projects with Visual Studio Code. As you know, it was not possible to develop applications in Xamarin with Visual Studio Code. Therefore, developers had to use Visual Studio. I don’t need to tell you how slow it is.

In addition, we will now be able to run projects with faster emulators. We will install the emulators we want to test and these devices will appear as listed one after another, regardless of the platform. Those late Google Phone emulators had annoyed the developers. And that’s why they looked for the solution in other emulators.

.NET MAUI Namespaces

With the MAUI, .NET namespace names will also be updated and naming according to the new structure will be used. Xamarin.Forms will evolve to System.Maui and Xamarin.Essentials to System.Device.

As you know, Xamarin.Essentials and Xamarin.Forms are already included in the project as NuGet plugin. When it comes to updates to these add-ons, problems sometimes arise in the application running with the old version. Fortunately, with MAUI, Xamarin.Forms and Xamarin.Essentials will appear as part of the project, not as additions to the project.

System.Maui, System.Devices
System.Maui, System.Devices

How will MAUI projects be generated?

Visual Studio and Visual Studio Code can be used on macOS and Visual Studio on Windows to create projects that work with MAUI. Also, .NET CLI support will be added to .NET Core CLI and we will be able to start a project with a simple command.

dotnet new maui

What Will Happens to Xamarin.Native?

It will be included in both Xamarin.iOS and Xamarin.Andorid .NET 6 platform. And it will be called .NET for iOS and .NET for Android. In addition, CLI support will also come for native platforms and development will become faster.

NET-For-iOS-and-Android
NET-For-iOS-and-Android

We will be able to start projects on Android and iOS platforms with the following CLI commands. There will be no changes in the platform specific namespaces. So there will be no problems for your native projects.

dotnet new ios
dotnet new android

What Will Happens to Xamarin.Forms?

After .NET MAUI is released, support will be given to Forms applications for a while. Bug fixes and support will continue to be provided until 2022. There is already a large community supporting Xamarin. So there will not be any problems during the transition period.

Design Patterns in MAUI (MVVM vs MVU)

We will be able to use the MVVM design pattern we currently use in Xamarin.Forms projects in MAUI. Currently, many Xamarin.Forms applications use the MVVM architecture. In other words, we will be able to continue developing applications with MVVM or MVU pattern according to our request. Below is a simple example working with the MVVM pattern.

<StackLayout>
    <Label Text="Welcome to .NET MAUI!" />
    <Button Text="{Binding Text}" 
            Command="{Binding ClickCommand}" />
</StackLayout>
public Command ClickCommand { get; }
public string Text  { get; set; } = "Click me";
int count = 0;
void ExecuteClickCommand ()
{
    count++;
    Text = $"You clicked {count} times.";
}

If you are still using the old method in your Xamarin projects, you should now switch to the MVVM architecture.

Fortunately, in addition to this, MAUI will support MVU design patterns. MVU opens as Model- View – Update. Already, the MVU pattern is very popular in cross-platform applications. As a result, Xamarin will keep up with this trend with .NET MAUI.

No more notifications from Model to ViewModel to update Views in MVU. By applying only the necessary changes necessary, the UI can be updated quickly with a one-way data flow. For example, below is a basic counter example of a .NET MAUI project. This is a good example of using the MVU pattern.

readonly State<int> count = 0;
[Body]
View body() => new StackLayout
{
    new Label("Welcome to .NET MAUI!"),
    new Button(
        () => $"You clicked {count} times.",
        () => count.Value ++)
    )
};

Notice that the Views are defined under [Body]. It is possible to dynamically update the view with a few lines of code in the MVU pattern. In the MVVM pattern, we define these commands in the ViewModel layer, which causes the UI to update slowly.

The MVU pattern will also get Blazor support. Thanks to the Blazor framework, you can directly interfere with the view as if you were writing JavaScript inside the XAML structures. In other words, you can update the UI faster by writing C# as if you were writing JavaScript.

.NET MAUI Roadmap

We will start using MAUI with .NET 6. Next, Microsoft will release the preview version in late 2020 and the final version in late 2021.

The roadmap specified on the MAUI’s GitHub page is as follows particularly:

  • (Late 2020) .NET MAUI Preview 1
  • (Early 2021) .NET MAUI Preview 2
  • (Early 2021) .NET MAUI Preview 3
  • (Mid 2021) .NET MAUI Preview 4
  • (Mid 2021) .NET MAUI Preview 5
  • (September 2021) .NET MAUI Release Candidate
  • (November 2021) .NET MAUI General Availability

Xamarin developments will continue throughout the period until the MAUI is released. After the MAUI is published, Xamarin support will be provided for 1 year. During this time, Xamarin projects are expected to move.

Conclusion

MAUI is an evolved Xamarin.Forms with more features. So there is nothing less, more.

In summary, what innovations await us?

  • No need for separate layers for iOS and Android as before. So three layers go down to one.
  • MVU pattern and Blazor framework will be supported as well as MVVM pattern.
  • With .NET CLI, we will be able to start the project with a simple command. No more waiting for the project to stand up for minutes.
  • Xamarin.Essentials will be in the MAUI project as System.Device, not NuGet plugin.
  • The Xamarin.Native structure will not change, only the names of the platforms in .NET 6 will change.

During these radical changes, developers together will experience new experiences.

Finally, what do you think of these changes. Do you think Xamarin will reach more users as it evolves as MAUI? Or will it be disappointing? Express your thoughts in the comments.

Also, share this blog post on social media and help more people learn.

Related Links

Serkan

Software Engineer. Problem solver. Music practitioner. Thinker. Industrious.

Related Articles

2 Comments

  1. I hope MAUI will have better support for UWP (Windows Desktop) apps than Xamarin, where quite often it was an afterthought and many features like Shell not working correctly.

    I am looking forward to using MAUI, although concerned that it is a long wait for the stable release.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button