PRISM XF Modal Navigation and the ever growing navigation stack
I don't know if this issue is a defect so much as a be aware of, and I'm sure for a lot of people it's obvious, but with PRISM XF you can't just navigate around your app only using navigationService.Navigate("page",options)
For example, we have a simple 5 page app, 3 are for submitting data, one is a dashboard that reports on the data and one is a "Home" page that lets you get to the four other pages. When a person submits data from the data entry pages we navigate them to a home page where typically they do nothing since the primary purpose of the app is just entering data from the first page, but sometimes they may choose to go to the dashboard page, or go enter stuff on one of the other less used data entry pages. Each of those pages go back to the home page when they submit the data. Each page also has a small button that lets them go back to the home page.
The problem is in our attempt to replicate the behavior of our Windows App we've just used DelegateCommand with the navigationService.navigate to send to wherever they want to go.
Since we don't want to bury the pages within an XF NavigationPage (which wastes space we need) modal navigation is how it is done, at least according to our understanding, and given that PRISM defaults to that style of navigation we probably incorrectly assumed we could just do it the same as we always did.
I'm sure you see the issue, each time we navigate to a page we are just pushing another page onto the stack. If you navigate to a page that already has been navigated to, you just end up creating another copy on the stack, memory drops rapidly and eventually you crash.
We've still not figured out a good workaround that doesn't require us to use the unwanted NavigationPage. I think we might be able to limit the amount of pages on the stack and clear the rest but that isn't ideal. In a perfect world I'd love Prism to detect that a page has already been visited and then to serve up that copy from the existing stack.
I've got no idea if that is technically possible but it would solve a huge problem for us.
This is not a defect or an issue. Think about how you would accomplish this without Prism. You would have to manually remove and add your view instances around your modal stack. So you would always have to keep track of your page instances, and the iterate the stack to find it's current position, remove it, then put it back in the stack where you want based on where you are going and where you are coming from. Also, you should not be using modal as you primary navigation mechanism using XF. Modal works a lot differently on the other platforms. For Windows it uses a navigation page under the covers so its seems like it works, but try on iOS and Android and you will soon discover different behavior. You need to think hard about the flow or your application and how users get from one screen to another. You'll use a combination of Navigate and GoBack to manage your stack in Prism.
We are researching how to cache pages in XF for reuse, but there is a lot to be considered before we can implement something like that.
By the way, Prism doesn't default to modal. It tries to be smart about what you want to do based on the current page and target page. The latest preview has a lot of navigation improvements including useModalMavigation is null be default.
I understand it isn't an issue from a PRISM XF functionality standpoint, so I guess it should be a feature request.
That being said it is problem if one incorrectly thinks they can use PRISM XF in the exact same way they did on Windows.
For people coming from Windows Apps you don't have to think about it, PRISM just works by saying navigate here or there due to how the under lying system works.
With XF you can't use the navigation service the same, even though (if you don't know better) it will seem like you can. Given it is so early in the PRISM XF development cycle, there's not much out there documenting the difference. I thought it would be good to at least have something out there so people can learn from my stupidity.
Apologies for putting it in the issues section. I'm not sure where else to post or ask this kind of info.
As always, thank you for your help
Jeff
Sent from my Windows Phone
From: Brian Lagunasmailto:[email protected] Sent: 12/23/2015 6:09 PM To: PrismLibrary/Prismmailto:[email protected] Cc: Jeff Dalbymailto:[email protected] Subject: Re: [Prism] PRISM XF Modal Navigation and the ever growing navigation stack (#370)
This is not a defect or an issue. Think about how you would accomplish this without Prism. You would have to manually remove and add your view instances around your modal stack. So you would always have to keep track of your page instances, and the iterate the stack to find it's current position, remove it, then put it back in the stack where you want based on where you are going and where you are coming from. Also, you should not be using modal as you primary navigation mechanism using XF. Modal works a lot differently on the other platforms. For Windows it uses a navigation page under the covers so its seems like it works, but try on iOS and Android and you will soon discover different behavior. You need to think hard about the flow or your application and how users get from one screen to another. You'll use a combination of Navigate and GoBack to manage your stack in Prism.
We are researching how to cache pages in XF for reuse, but there is a lot to be considered before we can implement something like that.
— Reply to this email directly or view it on GitHubhttps://github.com/PrismLibrary/Prism/issues/370#issuecomment-167017076.
This is the right place to start such a discussion, so keep the thoughts/suggestions coming. XF has turned out to be a very big pain in the butt when it comes navigation. It has the strangest nav pattern I've ever seen when there are two different navigation stacks and each page can have its own nav stack. It's things like this that make it difficult to share code cross plat.
I'm hoping that as Prism for XF matures, we can find more common ground to share across all plats.
You know XF supports UWP now so you could technically target all plat forms with the same VMs using Prism for XF.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.