ReactiveUI - confused about routing

I am in the process of comparing MvvmCross with ReactiveUI for a major pharmaceutical project in the Win Store, WP8, iOS, Droid. We have already chosen Xamarin.

I am completely unfamiliar with ReactiveUI. I really like what I see in principle, and I think that Paul is a genius. However, the details become a real bear. I spent several days tracking the documentation (the manual is from 2011 and it seems almost completely outdated - it doesn’t even contain the word "Router") and an example code.

I am looking at a sample from ReactiveUI.Samples Also, the MobileSample-RT project from the ReactiveUI solution.

I based my little hello world on the example of ReactiveUI.Samples Routing. Honestly, this is not a good example, since all he does is switch from AppBootstrapper to a single view. I am trying to do something similar to the "three pages" example from MobileSample-RT. The problem is that if I try something like this in my project:

HostScreen.Router.Navigate.Execute(RxApp.DependencyResolver.GetService(typeof(LoginViewModel))); 

Failure (pdb characters not loaded in ReactiveUI.dll)

If I try this:

 HostScreen.Router.NavigateCommandFor<LoginViewModel>().Execute(HostScreen); 

The same result is a hard failure. It really threw me as it looks like it should "just work."

I can call it:

 HostScreen.Router.Navigate.Execute(new LoginViewModel(HostScreen)); 

And it fits my mind, as expected. I also connected the back button on the main screen:

 this.OneWayBind(AppBootstrapper, x => x.Router.NavigateBack, x => x.BackButton.Command); 

And it really comes back from the point of view to which I just turned.

So now I want to move forward again. I press a button that does this (again):

 HostScreen.Router.Navigate.Execute(new LoginViewModel(HostScreen)); 

And I will return to this point of view. However, this time it takes 2 clicks on the back button to go back. If I go forward again, next time it will take 3 clicks. NavigationStack is populated with new instances of LoginViewModel.

So what is the correct routing / navigation way? Why are these commands broken? Instead of referring to the β€œnew” one each time in Navigate.Execute, how do I switch to a view model that is already in the navigation stack (or should it be there first?).

Thanks so much for any clarity you can provide.

+6
source share
1 answer

If you are building for iOS and Android, you just don’t want to use Routing - there is too much concept of routing conflicts with what you need to do on platforms (even on WP8 it was stretched, but I was able to hacky make it work). You must stick to the View-first location.

However, if you use Xamarin Forms, ReactiveUI works fine with VM-based routing (since Xamarin managed to do all the hacks to make this possible!). Check out https://github.com/paulcbetts/xamarinevolve2014 for his demo

I know that the documents suck and I am working on new ones:

+8
source

All Articles