dotnet / MobileBlazorBindings

Experimental Mobile Blazor Bindings - Build native and hybrid mobile apps with Blazor
MIT License
1.2k stars 151 forks source link

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

Open Dreamescaper opened 3 years ago

Dreamescaper commented 3 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 3 years ago

Requires #418 .

Dreamescaper commented 3 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" />
    );
}