CalciumFramework / Samples

Samples demonstrate how to use some of the features of Codon.
3 stars 2 forks source link

Codon navigation service with hamburger menu #6

Open abrasat opened 7 years ago

abrasat commented 7 years ago

Is it possible to use the codon framework navigation service combined with the xamarin.forms hamburger menu ( master-detail page ) ? (In this case the application "MainPage" is the MasterDetailPage, and the codon framework xamarin.forms sample uses in the implementation of INavigationService (the FormsNavigationService class) as the first element in the navigation stack. And it is also possible that every item from the hamburger menu has its own navigation stack. The INavigationService does not have any property/method that allows to set the navigation stack root element.)

If yes, could you please add it to the codon framework xamarin.forms sample, or post a code snippet here ?

abrasat commented 7 years ago

Is it posssible to use the NavigationService from the sample to set the Detail property of the MasterDetailPage to a new page, when the selected item from the master menu has changed ? I am looking for a way to use the Navigation page assigned to the Detail property of the MasterDetail page to implement the navigation methods from the navigation service from the Xamarin.Forms sample.

DVaughan commented 7 years ago

Yes, you could register an Action with the RoutingService. But, I'd probably publish a message using the IMessenger. Subscribe to the message in your MasterDetail page's view-model; then have the view-model coordinate displaying the detail page.

abrasat commented 7 years ago

Thank you for your solution. Should the message contain the Detail page to be displayed, or where should the MasterDetail view model get that information from ? And the MasterDetail view model has to access the MasterDetail page UI object in view to set the Detail property.

DVaughan commented 7 years ago

It depends on your architecture. Ideally I prefer not to send UI elements via the messenger. I would expose a list of view-models for each detail page from your MasterDetail view-model. I would have a property like CurrentDetailViewModel. When that property changes, the MasterDetail page can switch to the detail page corresponding to the CurrentDetailViewModel.

abrasat commented 7 years ago

Ok, thanks. I have to redesign the application. Actually I resolve the ViewModels in the OnAppearing method of the page. To cache all the detail view-models I will probably have to resolve them all at the application start and put them in the "static" list with view-models corrwsponding to the detail pages.

What solution would you recommend to handle in the view-model code the IsPresented flag used by the MasterDetail page (needs to be reset when a new Detail page is selected) ?

Regarding the Codon INavigationService interface, it could be also helpful to extend it in a future release, to be able to handle navigation also when using a MasterDetail page in the application (for instance a flag hat allows the reset of the NavigationStack, when the selected Detail item changes).

abrasat commented 7 years ago

... also a "ChangeDetailPage" method would be useful in INavigationService, when using MasterDetailPages. Does the Codon framework contain any helper methods to instantiate views from view models ? Such a feature would be practical when the CurrentDetailViewModel changes and a new Detail View/Page must be displayed. Another nice feature would be to extend the Codon ViewModelBase class with a kind of "Name" property, I could use this as a key in the list with view-models of the detail pages stored in the MasterDetail view-model.