I have the following navigation structure in my application:
Rootpage (MvxMasterDetailPagePresentation, Root, WrapInNavigationPage = false)
|- NavigationPage (MvxMasterDetailPagePresentation, Master)
|- SettingsPage (MvxMasterDetailPagePresentation, Detail)
|- DevicesPage (MvxMasterDetailPagePresentation, Detail) navigates to:
DevicePage (MvxTabbedPagePresentation, Root)
|- ConfigurationTabPage (MvxTabbedPagePresentation, Tab, WrapInNavigationPage = false)
|- MeasurementTabPage (MvxTabbedPagePresentation, Tab, WrapInNavigationPage = false) navigates to:
StartMeasurementPage (MvxModalPresentation)
Navigating between the RootPage (MasterDetail) and the DevicePage (TabbedPage) works just as expected. I can go back and forth without any issues on both Android and iOS and everything looks and feels just as expected.
Now I have added a nother layer to my navigation:
I can navigate to the StartMeasurementPage without any problem. The modal dialog opens just as expected and the blend in animation also looks nice on both platforms.
Now it gets weird:
When closing the modal dialog using await NavigationService.Close(this); my modal dialog fades out as expected but then also the Tabbed pages disapear after animation has finished and I am back at the RootPage.
Navigation behaves as expected and brings me back to the previously selected tab in my DevicesPage
Can't really provide any steps except for rebuilding a navigation pattern like I have.
Version: 6.2.1
Platform:
Just to be clear, this is a forms app? Also what exact version are you on?
Correct, it's a Xamarin Forms app and I'm using MvvmCross 6.2.1 and Xamarin.Forms 3.2.0.871581
https://github.com/michaelkollmann/mvvmcrossissue/
Here you can find my solution (removed all the unimportant stuff) to reproduce the issue.
Once you have it running it should be pretty obvious what's going wrong here
GitHub
Contribute to michaelkollmann/mvvmcrossissue development by creating an account on GitHub.
@michaelkollmann cool, thanks. Will take a look soon.
Anything yet?
It appears to me this is a Xamarin Forms issue. At the time of calling close on the modal there is only the modal in the ModalStack, while the NavigationStack seems to be empty.
Calling PopModalAsync here does strange things. It seems to navigate forwards to the RootPage, not back. Look at the Toolbar.
Are you sure?
I have created the same navigation pattern in Xamarin Forms without mvvmcross and the app works as expected. But maybe there is a difference that I can't see?
https://github.com/michaelkollmann/xamFormsNavIssue
GitHub
Contribute to michaelkollmann/xamFormsNavIssue development by creating an account on GitHub.
I can also reproduce this issue in the Playground xamarin forms project.
I added a "ShowTabChildCommand" command to the SplitDetailViewModel
ShowTabChildCommand = new MvxAsyncCommand(async () => await NavigationService.Navigate<TabsRootViewModel>());
...
public IMvxAsyncCommand ShowTabChildCommand { get; private set; }
and a button to the SplitDetailPage
<Button mvx:Bi.nd="Command ShowTabChildCommand" Text="Show Tab Child" />
Sadly I cannot debug the MvxFormsPagePresenter. For some reason Visual Studio doesn't stop on breakpoints when debugging. At least on android. Not sure if I am at looking in the right place
Would you be able to submit this as a WIP PR so it's easy for me to take a look?
When creating the pull request I noticed what ACTUALLY was causing this issue.
Setting the NoHistory property of the MvxTabbedPagePresentation attribute to false leads to the unexpected navigation behavior. Not sure if it is actually related to navigating from a master / detail to a tabbed page.
Anything at all?
Sorry for the spam but I kinda need this functionality for the project I'm working on...
Got it! Took some time but now I finally understand what's going on here.
When closing the modal dialog the ViewAppeared method of the RootPage (MvxMasterDetailPagePresentation) gets called again.
In the playground the called method is SplitRootViewModel.ViewAppeared()
this caused the ShowInitialViewModel() and ShowDetailViewModel() to be called again.
I'd expect the ViewAppeared method not to be called when closing a modal dialog further down in my navigation stack.
Most helpful comment
Got it! Took some time but now I finally understand what's going on here.
When closing the modal dialog the ViewAppeared method of the RootPage (MvxMasterDetailPagePresentation) gets called again.
In the playground the called method is
SplitRootViewModel.ViewAppeared()this caused the
ShowInitialViewModel()andShowDetailViewModel()to be called again.I'd expect the ViewAppeared method not to be called when closing a modal dialog further down in my navigation stack.