Dreamescaper / BlazorBindings.Maui

MAUI Blazor Bindings - Build native and hybrid MAUI apps with Blazor
MIT License
253 stars 23 forks source link

Add the ability to perform non-Shell page navigation #44

Closed Dreamescaper closed 2 years ago

Dreamescaper commented 2 years ago

Currently we have ShellNavigationManager for url-based navigation, but it has its own limitations:

I would suggest to add a service for navigation, which would allow to work with components:

interface INavigationService
{
    Task PushAsync<T>(Dictionary<string, object> arguments = null, bool animated = true) where T: IComponent;
    Task PushModalAsync<T>(Dictionary<string, object> arguments = null, bool animated = true) where T: IComponent;

    // Optional, just for convenience (as you can do same now via NativeElement property)
    Task PopToRootAsync(bool animated = true);
    Task PopModalAsync(bool animated = true);
    Task PopAsync(bool animated = true);    
}

This way navigation would look smth like that:

       @inject INavigationService NavigationService

    async Task Navigate()
    {
        await NavigationService.PushAsync<MyPage>(new()
        {
            [nameof(MyPage.Parameter1)] = arg1,
            [nameof(MyPage.Parameter2)] = arg2
        });
    }

It would be great to design this service with extensibility in mind, so that I could, for example, add extension method ShowPopupAsync to display XCT's Popup.

Open questions:

Dreamescaper commented 2 years ago

We could also provide RenderFragment overloads to allow a bit exotic syntax:

async Task Navigate()
{
    await NavigationService.PushAsync(
        @<MyPage Parameter1="arg1" Parameter2="arg2" />
    );
}