So here's my dilemma. I was building a cross-platform app with Xamarin.Forms Shell, but it has some limitations for the grander scope of what my employer is trying to achieve, so I'm having to rebuild the core navigation.
In Shell, I used TabBar and simply declared all the pages with the Navigation Schema of Routing and then simply just had to call for Shell.GoToAsync() to navigate to each page from anywhere within the app itself.
In switching to TabbedPage, I'm having trouble getting the navigation to work. I get the error "PushAsync is not supported globally on Android, please use a NavigationPage" and the same error for iOS. So I can't get to any level beyond the child page of the TabbedPage itself.
This is the code I have for my StartPage
<TabbedPage>
<NavigationPage
Title="Home" Style="{StaticResource BaseNavigationStyle}">
<NavigationPage.IconImageSource>
<FontImageSource
FontFamily="{DynamicResource FontAwesomeSolid}"
Glyph="{StaticResource HomeIcon}"
Size="{StaticResource GlyphSize}"
Color="White"/>
</NavigationPage.IconImageSource>
<x:Arguments>
<page:HomePage />
</x:Arguments>
</NavigationPage>
<NavigationPage x:Name="Items_Dashboard"
Title="Items" Style="{StaticResource BaseNavigationStyle}">
<NavigationPage.IconImageSource>
<FontImageSource
FontFamily="{DynamicResource FontAwesomeSolid}"
Glyph="{StaticResource ItemsIcon}"
Size="{StaticResource GlyphSize}"
Color="White"/>
</NavigationPage.IconImageSource>
<x:Arguments>
<page:ItemDashboard />
</x:Arguments>
</NavigationPage>
<NavigationPage x:Name="Orders_Dashboard"
Title="Orders" Style="{StaticResource BaseNavigationStyle}">
<NavigationPage.IconImageSource>
<FontImageSource
FontFamily="{DynamicResource FontAwesomeSolid}"
Glyph="{StaticResource OrdersIcon}"
Size="{StaticResource GlyphSize}"
Color="White"/>
</NavigationPage.IconImageSource>
<x:Arguments>
<page:OrdersDashboard />
</x:Arguments>
</NavigationPage>
</TabbedPage>
So I'm doing what I believe was in the official docs about essentially wrapping each page in a NavigationPage, and on launch it works as expected, but when I try to link up a click from an object within any of the child pages, I get the error above.
Ultimately my navigation structure is something like this:
ALL NESTED WITHIN THE TABBEDPAGE
Home
-- Page 1 [MODAL]
-- Page 2 [MODAL]
-- Page 3 [MODAL]
Items
-- Page A
-- -- Page AA [MODAL]
-- Page B
-- -- Page BA
-- -- Page BB [MODAL]
-- Page C
-- -- Pace CA
-- -- Page CB
-- -- Page CC
-- -- -- Page CCA [MODAL]
So following this pattern, the user would tap on the Items Tab, then from a list on the displayed page they'd click and be taken to Page A, from where they can launch the Modal Page AA. All the while using the Back Arrow to navigate down the path as necessary.
In my App.cs code behind I'm doing this, because I want a LOGIN and LOADING screen depending on whether the user is logged in/out.
protected override void OnStart()
{
State = new AppState();
GetCurrentBarrels();
LoadStyles();
if (!string.IsNullOrWhiteSpace(State.ApiToken))
{
// Load to SplashScreen for background loading to avoid white space
MainPage = NewLoadingPage();
// Load Encryption Key;
Barrel.EncryptionKey = State.ApiToken;
}
else
{
// If no token automatically drop user to login
MainPage = NewLoginPage();
}
}
public static NavigationPage NewLoginPage()
{
var page = new NavigationPage(new LoginPage());
return page;
}
public static NavigationPage NewLoadingPage()
{
var page = new NavigationPage(new LoadingSplashPage());
return page;
}
Then from LOGIN or LOADING, I call for this:
public static void ShowShell()
{
//Current.MainPage.Navigation.PopAsync();
//Current.MainPage = _shell = new AppShell();
Current.MainPage.Navigation.PopAsync();
Current.MainPage = new StartPage();
}
I've gone round and round with this, trying to figure out how to get it to work. If I wrap new StartPage() inside a new NavigationPage(), then I wind up with the Navigation Bar above the Navigation Bar of all my pages. I need the Navigation structure, but I don't want to lose my custom view that I'm implementing through a BasePage.
Does anyone have any ideas of either what I'm doing wrong? or how to deal with navigation and TabbedPage?