Valerie
Valerie

Reputation: 659

First tab in Freshmvvm custom navigation page doesn't show after SwitchOutRootNavigation

I have a Xamarin Forms PCL project, which uses Freshmvvm custom navigation. The app has two navigation containers. One for authentication the other is main tabbed container. When the App starts up the authentication stack is used. After the user authenticates the first tab page is displayed, and the user can successfully navigate between tabs. If the user clicks logout (which is an action of a modal settings page which is pushed from 2nd tab page) we switch to the authentication stack with

CoreMethods.SwitchOutRootNavigation(NavStacks.LoginNavStack);

Enter login credentials again to re-authenticate and this time the 2nd tab is displayed to the user (should have been 1st tab). Also, clicking the 1st tab doesn't display it. I can click the 3rd tab, and then clicking the 1st tab will work.

As a test, I created an empty page/pagemodel with a logout button and added the empty pagemodel to 3 tabbed containers. Repeating the login, logout, login scenario several times, I noticed that whichever tab I clicked the logout button from (remember it's displayed on each tab), this is the tab that gets displayed 1st (as the selected tab) after re-authentication.

I'm not sure why this is happening, but I am looking for ways to always have the 1st tab in the container be the one displayed 1st to the user; so basically looking for ideas.

Upvotes: 1

Views: 342

Answers (1)

Fabricio P.
Fabricio P.

Reputation: 141

Had the same issue and with FreshMVVM >= v2.2 a new method SwitchSelectedTab<T> to the CoreMethods class got introduced.

So, before you log out and switch your root navigation back to the login-related navigation stack then issue a switch to the tab you would like to appear after a successful login. i.e.:

CoreMethods.SwitchSelectedTab< _YOUR_LANDING_PageModel >();

Upvotes: 0

Related Questions