BurkusCat / Burkus.Mvvm.Maui

A simple MVVM framework for .NET MAUI. It provides: navigation, lifecycle events, parameter passing, native dialog abstractions, and testability.
MIT License
27 stars 5 forks source link

[Feature] TabbedPage support #10

Closed BurkusCat closed 11 months ago

BurkusCat commented 1 year ago

Is your feature request related to a problem? Please describe. Tabs are common in mobile applications but introduce some navigation complexity. This library should make that easier.

Describe the solution you'd like I would like methods for switching tabs, a parameter for choosing which tab is selected when I first navigate to a tabbedpage, navigation events to trigger correctly for tabbedpages, new navigation events for switching to/from tabs.

Describe alternatives you've considered N/A Proposed APIs

// INavigationService
Task SwitchTab(tabTitle); // or SelectTab?

// Should the tab title or tabbedpage type be used?

Additional context Some implementation thoughts:

public async Task SelectTab<T>(TabbedPage tabbedPage)
            where T : Page
        {
            foreach (var child in tabbedPage.Children)
            {
                if (child.GetType() == typeof(T))
                {
                    tabbedPage.CurrentPage = child;
                    return;
                }

                if (child is NavigationPage)
                {
                    if (((NavigationPage)child).CurrentPage.GetType() == typeof(T))
                    {
                        tabbedPage.CurrentPage = child;
                        return;
                    }
                }
            }
        }
BurkusCat commented 1 year ago

A prototype method has been added for switching tabs (https://github.com/BurkusCat/Burkus.Mvvm.Maui/commit/9cbe493f0fd10e4692980fcb5e73ad9ebf5b9b07) that allows you switch tab using the page type Task SelectTab<T>() where T : Page.

BurkusCat commented 11 months ago

I've opened #30 to cover switching tab events