class: title, smokescreen, shelf, no-footer background-image: url(/assets/images/presentations/xamarin-from-2020-to-2021/highway-to-heaven.jpg) # Xamarin from 2020 to 2021 ## Highway to heaven --- class: col-2 # Agenda Xamarin is well alive and if we needed a year to be convinced by this, then 2020 was that year. Of course the pandemic did not easy our lives and some of us might have followed less what was happening in the Xamarin ecosystem. In this talk we are a going to look back at 2020 to better understand 2021. 1. Xamarin 2. Visual Studio 3. Xamarin.Forms 4. What's next --- class: title, fogscreen, no-footer background-image: url(/assets/images/presentations/xamarin-from-2020-to-2021/monkey-debug.jpg) # Xamarin.Android --- class: compact # Xamarin.Android For about two years, native Android development has switched to a much more modular approach, aiming to improve performance while shrinking app sizes. 2020 has been the year where Xamarin really integrated all of these new features. In addition to features enabling better compilation and deployement times, many great features have been introduced: *App Bundle, Compression LZ4, Mono.Android and reference nullable types, IntelliSense improvements, Android 11 support, Bindings projects, Kotlin bindings, D8 and R8, Manifest merger, Startup tracing, AAPT2, Android Apply Changes, AndroidX and API 29.* --- class: roomy # App Bundles Xamarin finalised the support of App Bundles at the beginning of 2020. App Bundles are a new packaging format for Android that dramaticaly reduces the download and install size of the app for final users. In order to create them, Xamarin uses the same `BundleTool` tool as Android native developers ??? BundleTool version 0.14.0 --- # Android 11 support Xamarin has brought support of Android 11 quite recently. These bindings take advantage of C# 8.0's support for default and static interface members to provide C# interface APIs that more closely match the original Android APIs. Because of this change, some classes have been marked as obsolete. For example, `TextClassifier.HintTextIsEditable` is now as `ITextClassifier.HintTextIsEditable`, and the old `TextClassifier.HintTextIsEditable` field is marked `[Obsolete]`. --- class: compact # Compression LZ4 Managed assemblies are now compressed by default for release builds reducing app sizes. This compression uses the LZ4 algorithm is now used during builds and uncompressed at app launch. You can deactivate this default behaviour by tweaking your csproj: ```xml
false
``` *Note: This feature is intended to replace the older Bundle assemblies into native code.* ??? Managed assemblies are now compressed by default for Release configuration builds, resulting in significantly smaller APK and Android App Bundle sizes. Assemblies are compressed with the LZ4 algorithm during builds and then decompressed on device during app startup. For a small example Xamarin.Forms application, this reduced the APK size from about 23 megabytes to about 17 megabytes while only increasing the time to display the first page of the app from about 780 milliseconds to about 790 milliseconds. If needed, the new behavior can be disabled for a particular project by opening the project file in Visual Studio or another text editor and setting the AndroidEnableAssemblyCompression MSBuild property to false in the .csproj file: --- # Mono.Android nullable reference types The Mono.Android assembly has been annotated for compatibility with C# 8.0 nullable reference type checks. Projects can now use code from Mono.Android in a nullable context and take profit of nullability verifications. To enable nullability checks you can tweak your csproj: ```
enable
``` --- # Intellisense improvements `Java.Lang.Object` contains several properties and methods that are required to be `public` to support Xamarin.Android Java bindings but are not intended to be used in hand-written code. ``` - Java.Lang.Object.JniPeerMembers - Java.Lang.Object.PeerReference - Java.Lang.Object.JniPeerMembers - ... ``` These members are now hidden from IntelliSense, making it easier to find the useful members. *Note: Hidden does not mean removed.* --- class: compact # Binding projects Binding projects bridge .NET and native worlds. They are the ones allowing the usage of native SDK from C#. Here is a small list of the interesting points: - Bindings projects support for methods with more than 14 parameters. - Usage of `mapping` and `field` elements without specifying the jni associated attributes. - Deprecation of `jar2xml` parser and the code generation target `XamarinAndroid`. ```xml
class-parse
``` ```xml
XAJavaInterop1
``` --- # Kotlin bindings Android platform is constantly evolving and Kotlin is gaining traction and may replace Java in the end. A number of SDKs have already migrated from Java to Kotlin. The ability to use components built in Kotlin is more important than ever for Xamarin developers. It is now possible to create binding projects for Kotlin components with some additional steps compared to the Java ones. --- class: compact # D8 and R8 Google has depreciated the DX Dex compiler in favour of D8. Starting february 2021 it will not be part of Android SDK or Android Studio. In order to follow the evolution of native tooling Xamarin now encourages migration to d8 and r8 as well. ```xml
d8
``` --- class: compact # Manifest merger Your project might have a single manifest file but your dependencies might have manifests as well. Sometimes conflicts occurs and the manifest merger helps by combining those manifests with heuristics and rules that you provide. It is now possible to use the same manifest merger from Google for better compatibility. ```xml
``` --- class: roomy # Startup tracing Last year, Mono introduced the ability to use an integrated AOT profiler to generate an AOT profile. Xamarin comes with an `enable startup tracing` feature that improves the generated AOT code for better startup time at with a small impact on app size. It is now possible to provide custom profiles to further control the impact of the feature on app size. --- # AAPT2 AAPT2, or Android Asset Packaging Tool, is a generation tool used to compile and package resources of your apps. It analyses, indexes and compile resources in a binary format optimised for the Android platform. It is not a new thing per say but it has been defined it is now default value for projects and has been updated to version 4.0.0. To activate it: ```xml
true
``` --- # Android Apply Changes Apply changes allows you to push resources modifications on an already executing application. This is very useful while working on xml or axml files. ![](/assets/images/presentations/xamarin-from-2020-to-2021/apply-changes.png# max-50pct center) *Apply changes is a native feature now exposed to Xamarin.Android applications and should not be mistaken with Xamarin.Forms Hot Reload.* --- class: roomy # AndroidX and API 29 AndroidX replaces Android support librairies and integrating them requires efforts. New features will not be ported to support librairies. ![](/assets/images/presentations/xamarin-from-2020-to-2021/androidxlogo.png# w-20pct db fr ml-4) Starting november 2020, all application updates need to target the API 29 to be published to Google Play Store. Some features necessary for your app may only be available in AndroidX then. ??? It is not possible to speak of Xamarin Android in 2020 without speaking about AndroidX. This subject alone would require a talk. Integrating AndroidX is necessary to have a future proof app. --- class: title, fogscreen, no-footer background-image: url(/assets/images/presentations/xamarin-from-2020-to-2021/apple.jpg) # Xamarin.iOS ??? Much fewer updates compared to Android. --- class: roomy # Xamarin.iOS Most updates relates to the added support of iOS 14 and Xcode 12. Many bug fixes have been made like some race conditions or some crashes. Several missing enums have been added (`NFCReaderError`, `SecAuthenticationType`). Numerous APIs have been updated. --- # UIWebView UIWebView API is now obsolete. Migrating to WKWebView should be done quickly. If your app still references this type, you can remove it thanks to the linker by adding these additional parameters: ```xml --optimize=force-rejected-types-removal ``` Starting april 2020, App Store **rejects** new applications using UIWebView. App updates have **until december 2020** to comply. ??? WKWebView ensures that compromised web content does not impact your app. --- class: roomy # Swift bindings More and more SDKs moved from Objective-C to Swift. As long as a Swift library provides Objective-C header files, it is possible to generate Swift bindings. Do not forget to add the `Xamarin.iOS.SwiftRuntimeSupport` nuget package. --- class: title, fogscreen, no-footer background-image: url(/assets/images/presentations/xamarin-from-2020-to-2021/visual-studio.jpg) # Visual Studio ??? Lot of new features have been integrated to support Xamarin features and improve productivity. - Unit tests - IntelliSense - Android - Xamarin.Forms --- class: roomy img-right # Unit tests ![](/assets/images/presentations/xamarin-from-2020-to-2021/debug-ut.png) In Visual Studio for Mac it is now possible to launch and debug a unit test by right clicking on it. And yes that small change deserves a slide on its own! --- class: img-right # IntelliSense ![](/assets/images/presentations/xamarin-from-2020-to-2021/intellisense.png) - Generation of `IComparable` and `IEquatable` types and to automatic initialisation of properties and fields for optional parameters. - Generation of properties during the creation of a constructor. - Improvements over the autocompletion of `DateTime` and `TimeSpan` types. --- class: img-right # Android ![](/assets/images/presentations/xamarin-from-2020-to-2021/android-diagnostics.png) - To simplify the migration to AndroidX, Visual Studio provides a migration assistant. - Android XML file support improved with a faster and more stable experience, better autocompletion of attributes, tags etc... - It is possible to set a configuration file for the Android layout diagnostic features. --- class: roomy # Xamarin.Forms - Revamped template selection experience to make it more visual - Flyout and Tabbed templates uses the Shell - Improvements to the XAML editor (color previewer, hierarchy viewer) - Improved Hot Reload - New environment settings to allow changing emulators configuration (light/dark mode, font sizes, ...) - XAML Binding Failures Window - And many more --- class: title, fogscreen, no-footer background-image: url(/assets/images/presentations/xamarin-from-2020-to-2021/monkey-debug.jpg) # Xamarin.Forms --- class: roomy # Xamarin.Forms 4.5+ Xamarin Forms 2020 releases contain a lot of new cross-platform controls (CheckBox, RadioButton, CollectionView, CarouselView, Drag and Drop, Shapes, SwipeView). These new features inject new creative potential for your application designs to create beautiful, interactive experiences. Most of the base controls are optimised. --- class: roomy # AndroidX Xamarin.Forms include the latests AndroidX librairies. Bonus : No need to update your code. --- # Embedded Fonts It was possible to use custom fonts by adding them in each platform projects (iOS and Android). Today, just add your fonts in Xamarin.Forms's project as resources. ```csharp using Xamarin.Forms; [assembly: ExportFont("CuteFont-Regular.ttf")] ``` ```xml
``` --- class: roomy # StateTriggers (1/2) StateTriggers represent a set of rules that VisualStates enforce based on certain conditions. Every VisualState has a collection of StateTriggerBase that indicate when the VisualState should be applied. If any of the triggers are active, the VisualState will be applied. --- class: compact # StateTriggers (2/2) ```xml
...
``` --- # VisualStateManager (1/2) The Visual State Manager (VSM) provides a structured way to make visual changes to the user interface from code. In most cases, the user interface of the application is defined in XAML, and the XAML includes markup describing how the Visual State Manager affects the visuals of the user interface. ```csharp VisualStateManager.GoToState(PlayPauseToggle, (e.State == MediaElementState.Playing) ? "playing" : "paused"); ``` --- class: compact # VisualStateManager (2/2) ```xml
...
``` --- class: compact # Shell Modal One of the most interresting feature while using Shell is the URI navigation. It is possible to diplay a page as Modal by using the property Shell.PresentationMode. ```xml
// your content
``` To access the page : ```csharp Routing.RegisterRoutes("registration", typeof(RegistrationModal)); Shell.Current.GoToAsync("//login/registration"); ``` --- class: compact # PlatformSpecifics Platform-specifics allow you to consume functionality that's only available on a specific platform, without implementing custom renderers or effects. First add the XAML namespace for your platform : `clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core` And then you can use it this way : ```xml
``` --- class: compact # CarouselView & IndicatorView - The CarouselView is a view for presenting data in a scrollable layout, where users can swipe to move through a collection of items. - By default, a CarouselView will display its items in a horizontal list. - The IndicatorView is a control displaying indicators that represent the number of items, and current position, in a CarouselView. ```xml
``` --- class: compact # SwipeView The SwipeView is a container control that wraps around an item of content, and provides context menu items that are revealed by a swipe gesture. ```xml
...
``` --- class: compact # MediaElement MediaElement is a view for playing video and audio. Media that is supported by the underlying platform can be played from the following sources: - The web, using a URI (HTTP or HTTPS). - A resource embedded in the platform application, using the `ms-appx:///` URI scheme. - Files that come from the app's local and temporary data folders, using the `ms-appdata:///` URI scheme. - The device's library. ```xml
``` --- class: compact # Dual Screen (1/2) Dual-screen devices like the Microsoft Surface Duo or Galaxy Fold and Fold 2 facilitate new user-experience possibilities for your applications. The TwoPaneView class represents a container with two views that size and position content in the available space, either side-by-side or top-to-bottom. ```xml
...
...
``` --- class: compact # Dual Screen (2/2) The DualScreenInfo class enables you to determine which pane your view is on, how big it is, what posture the device is in, the angle of the hinge, and more. On Android and UWP platform projects : GetHingeAngleAsync retrieves the current angle of the device hinge. ```csharp var hingeAngle = await DualScreenInfo.Current.GetHingeAngleAsync(); ``` --- class: compact # Expander The Xamarin.Forms Expander control provides an expandable container to host any content. The control has a header and content, and the content is shown or hidden by tapping the Expander header. ```xml
``` --- class: compact # Grid No need to present the control Grid. In XAML, the row and column characteristics of a Grid can be specified using a simplified syntax that avoids having to define RowDefinition and ColumnDefinition objects for each row and column. ```xml
``` --- class: compact # Shapes and Paths A Shape is a type of View that enables you to draw a shape to the screen. ```xml
``` The Path class derives from the Shape class, and can be used to draw curves and complex shapes. These curves and shapes are often described using Geometry objects. ```xml
``` --- class: compact # GestureRecognizers A drag and drop gesture enables items, and their associated data packages, to be dragged from one onscreen location to another location using a continuous gesture. Drag and drop can take place in a single application, or it can start in one application and end in another. ```xml
``` --- # XAML Hot reload XAML Hot Reload plugs into your existing workflow to increase your productivity and save you time. With Hot Reload, when you save your XAML file, the changes are reflected live in your running app. In addition, your navigation state and data will be maintained, enabling you to quickly iterate on your UI without losing your place in the app. Spend less time rebuilding and deploying your apps to validate UI changes! --- class: title, fogscreen, no-footer background-image: url(/assets/images/presentations/xamarin-from-2020-to-2021/maui.jpeg) # Next ? --- class: compact # Supported IDE and breaking changes Remove support for Visual Studio 2017. Visual Studio 2019 is the minimum version to use. **Breaking changes:** - Move MediaElement to Xamarin Community Toolkit. - Move C# Markup Extensions to Xamarin Community Toolkit - Move Expander to Xamarin Community Toolkit. - Remove support for Visual Studio 2017. - Cease publishing DataPages, remove from solution. - Rename MasterDetailPage. - Remove UIWebView. - Remove XFCorePostProcessor.Tasks. --- # .NET Multi-platform app UI Xamarin.Forms 5.0 will be the last major version of Xamarin.Forms. New major features and developments will now be in .NET MAUI and the Xamarin Community Toolkit. - Cross-platform, native UI - Single project, single codebase - Deploy to multiple devices, mobile & desktop - Evolution of Xamarin.Forms - Targeting .NET, previews end of year [https://github.com/dotnet/maui](https://github.com/dotnet/maui) --- class: compact # MAUI modern app patterns MVVM ```xml
``` MVU ```csharp readonly State
count = 0; [Body] View body() => new StackLayout { new Label("Welcome to .NET MAUI!"), new Button(() => $"You clicked {count} times.", () => count.Value ++)) }; ``` --- class: roomy # MAUI - Visual Studio code as a first class citizen - Namespaces of Xamarin native and Xamarin Essentials expected to be moved to System.Devices.* - Compatibility with dual screen devices - Support of Android, iOS, macOS, Windows and even Blazor **The best is yet to come !** --- # Slides .qrcode.db.fr.w-40pct.ml-4[] Slides are available on [john's blog](/presentations/). Scan the QrCode for direct access. @johnthiriet - [Twitter](https://twitter.com/JohnThiriet) - [LinkedIn](https://linkedin.com/in/JohnThiriet) @paulin_laroche - [Twitter](https://twitter.com/paulin_laroche) - [LinkedIn](https://linkedin.com/in/paulinlaroche)