Provides .NET MAUI tools to help with everyday challenges.
Nalu.Maui
provides a set of classes to help you with everyday challenges encountered while working with .NET MAUI.
The core library is intended to provide a set of common use utilities.
Have you ever noticed that when the user backgrounds the app on iOS, the app is suspended, and the network requests will fail due to The network connection was lost
?
This is really annoying: it forces us to implement complex retry logic, especially considering that the request may have already hit the server.
To solve this issue, we provide a NSUrlBackgroundSessionHttpMessageHandler
to be used in your HttpClient
to allow http request to continue even when the app is in the background.
#if IOS
var client = new HttpClient(new NSUrlBackgroundSessionHttpMessageHandler());
#else
var client = new HttpClient();
#endif
To make this work, you need to change your AppDelegate
as follows:
[Export("application:handleEventsForBackgroundURLSession:completionHandler:")]
public virtual void HandleEventsForBackgroundUrl(UIApplication application, string sessionIdentifier, Action completionHandler)
=> NSUrlBackgroundSessionHttpMessageHandler.HandleEventsForBackgroundUrl(application, sessionIdentifier, completionHandler);
Check out the Core Wiki for more information.
The MVVM navigation service offers a straightforward and robust method for navigating between pages and passing parameters.
The navigation system utilizes Shell
under the hood, allowing you to easily define the flyout menu, tabs, and root pages.
We use a fluent API instead of strings to define navigations, supporting both Relative
and Absolute
navigation, including navigation guards to prompt the user before leaving a page.
// Push the page registered with the DetailPageModel
await _navigationService.GoToAsync(Navigation.Relative().Push<DetailPageModel>());
// Navigate to the `SettingsPageModel` root page
await _navigationService.GoToAsync(Navigation.Absolute().ShellContent<SettingsPageModel>());
Passing parameters is simple and type-safe.
// Pop the page and pass a parameter to the previous page model
await _navigationService.GoToAsync(Navigation.Relative().Pop().WithIntent(new MyPopIntent()));
// which should implement `IAppearingAware<MyPopIntent>`
Task OnAppearingAsync(MyPopIntent intent) { ... }
You can also define navigation guards to prevent navigation from occurring.
ValueTask<bool> CanLeaveAsync() => { ... ask the user };
There is an embedded leak-detector to help you identify memory leaks in your application.
See more on the Navigation Wiki.
Cross-platform layouts and utilities for MAUI applications simplify dealing with templates and BindinginContext
in XAML.
if
statement in XAML?
<nalu:ToggleTemplate Value="{Binding HasPermission}"
WhenTrue="{StaticResource AdminFormTemplate}"
WhenFalse="{StaticResource PermissionRequestTemplate}" />
<nalu:ViewBox ContentBindingContext="{Binding SelectedAnimal}"
IsVisible="{Binding IsSelected}">
<views:AnimalView x:DataType="models:Animal" />
</nalu:ViewBox>
TemplateSelector
directly like we do on a CollectionView
?
<nalu:TemplateBox ContentTemplateSelector="{StaticResource AnimalTemplateSelector}"
ContentBindingContext="{Binding CurrentAnimal}" />
Find out more on the Layouts Wiki.