adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
568 stars 47 forks source link

Change mainpage at runtime #103

Closed MattePozzy closed 1 year ago

MattePozzy commented 1 year ago

Hi, I need to change the main page and navigate to it, at runtime.

In Xamarin.forms I did in this way:

SyncPage syncPage = new SyncPage();
NavigationPage.SetHasNavigationBar(syncPage, true);
Application.Current.MainPage = new NavigationPage(syncPage);

How can I do with ReactorUi? Thank you.

adospace commented 1 year ago

you can navigate to a new page: https://adospace.gitbook.io/mauireactor/components/navigation/navigation

you can also swap the window content with code like this: https://adospace.gitbook.io/mauireactor/components/window

MaTToX3 commented 1 year ago

Why don't you just render a different component based on state?

internal class MainPageState
{
    public bool IsAuthenticated { get; set; }
}

internal class MainPage : Component<MainPageState>
{
    public override VisualNode Render()
    {
        if (!State.IsAuthenticated)
        {
            return new LoginPage()
                .OnLoggedIn(loginResult => 
                    SetState(x => x.IsAuthenticated = loginResult.IsSuccess));
        }

        return new ShellPage();
    }
}
MattePozzy commented 1 year ago

Why don't you just render a different component based on state?

internal class MainPageState
{
    public bool IsAuthenticated { get; set; }
}

internal class MainPage : Component<MainPageState>
{
    public override VisualNode Render()
    {
        if (!State.IsAuthenticated)
        {
            return new LoginPage()
                .OnLoggedIn(loginResult => 
                    SetState(x => x.IsAuthenticated = loginResult.IsSuccess));
        }

        return new ShellPage();
    }
}

I have done a sort of! Thank you