Xamarin Versus .NET MAUI
1. Platform Architecture
First and foremost, the main change in platform architecture is that .NET MAUI is integrated with .NET 6.0 to be a part of the Journey to One .NET.
With Xamarin.Forms, developers may become frustrated working with multiple projects targeting multiple platforms; keeping images, fonts, and platform-related code organized; adding different dependencies, and resolving them if they’re referenced as NuGet packages. Encountering these problems, developers are now addressed in .NET MAUI with a single project.
Since .NET MAUI is a simple project app, it works on a multitarget-based structure. A .NET MAUI app contains a Platforms folder, with subfolders representing platforms such as Android, iOS Maccatalyst, and Windows to target platform-specific code that starts the app on platforms. It can also be multitargeted based on your own file name. Generally, the file name target pattern is to include the platform as an extension in the file name. For example:
MainPage.android.cs targeting Android
MainPage.iOS.cs targeting iOS and Mac
MainPage.Windows.cs targeting Windows
MainPage.android.cs targeting Android
MainPage.iOS.cs targeting iOS and Mac
MainPage.Windows.cs targeting Windows
2. Supported Platforms and Versions
The main difference in platform support between Xamarin and .NET MAUI is in their support for Windows. Xamarin supports UWP, whereas .NET MAUI supports WinUI. Have a look at the following table for support version details.
3. .NET CLI
Another major difference is that .NET MAUI runs on .NET CLI. The .NET command-line interface (CLI) is a cross-platform toolchain for developing, building, running, and publishing .NET apps. This .NET CLI provides .NET MAUI apps with a seamless build and run experience.
4. Renderer and Handler Architectures
In Xamarin, controls are made with renderers. When developers want to customize a native controls’ UI, they must use a custom renderer to do so. These renderers cost the users heavily in terms of performance and app size.
But .NET MAUI uses handler architecture that is very loosely coupled with native assembly. With a native platform, this results in a lightweight app with better performance.
You can use renderers here if needed. You can reuse Xamarin.Forms custom renderer when porting.
5. .NET 6
.NET MAUI is integrated into .NET 6, whereas Xamarin.Forms is a .NET Framework. Due to .NET 6 integration, you can use the following .NET 6 and C#10 features in .NET MAUI:
Nullable enable/disable and nullable reference types
Note: If you are porting your app from Xamarin.Forms to .NET MAUI, you may not be able to use all these .NET 6.0 and C# features, because you may face limitations on your existing code.
Nullable enable/disable and nullable reference types
6. Resource Maintenance
.NET MAUI took over Xamarin in terms of resources, especially in terms of images. You do not need to maintain a set of images for the platform- or device-specific needs. A single SVG image is enough to meet all platform and device requirements. The SVG image gets turned into a .png image to work on all platforms.
7. Hot Reload Support
Support for hot reload in Xamarin versus .NET MAUI is detailed in the table.
8. Graphics APIs
In Xamarin, there is no direct API available to fulfill any drawing requirements. You have to do it on the native side using renderers. But .NET MAUI now abstracts native drawing and brings you better graphics APIs. The cross-platform graphics functionality in .NET MAUI provides a drawing canvas for drawing and painting shapes.
The brush is the primary type.
9. Configuring Resources and Services
Unlike Xamarin, .NET MAUI apps are bootstrapped using the .NET Generic Host. So, if you want to initialize any fonts, services, or third-party libraries, it can be done through that from a single location.
10. Accessibility
Typically in Xamarin, we use automation properties and native APIs to provide proper accessibility to screen readers for text in the controls used in an app.
But .NET MAUI provides semantic properties to provide accessibility values in apps (you can use automation properties in .NET MAUI, but the recommended approach is semanticproperties).
11. Supported Patterns
Another important difference is pattern support.
12. Blazor apps
Developing Blazor hybrid apps is not possible in Xamarin, but you can build .NET MAUI Blazor apps.
13. Cross-platform APIs for device features
Both Xamarin and .NET MAUI can provide the following cross-platform APIs for native device features. According to this Microsoft documentation, the following are the cross-platform APIs available.
Access to sensors, such as the accelerometer, compass, and gyroscope on devices.
Ability to check the device’s network connectivity state, and detect changes.
Provide information about the device the app is running on.
Copy and paste text to the system clipboard, between apps.
Pick single or multiple files from the device.
Store data securely as key/value pairs.
Utilize built-in text-to-speech engines to read text from the device.
Initiate browser-based authentication flows that listen for a callback to a specific app registered URL.
Cross-platform APIs for device features are also integrated with MAUI under Microsoft.Maui.Essentials namespace.
Access to sensors, such as the accelerometer, compass, and gyroscope on devices.
Ability to check the device’s network connectivity state, and detect changes.
Provide information about the device the app is running on.
Copy and paste text to the system clipboard, between apps.
Pick single or multiple files from the device.
Store data securely as key/value pairs.
Utilize built-in text-to-speech engines to read text from the device.
Initiate browser-based authentication flows that listen for a callback to a specific app registered URL.
No comments:
Post a Comment