Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for MAUI RoutedViewHost #3303

Merged
merged 10 commits into from
Jul 8, 2022

Conversation

ili
Copy link
Contributor

@ili ili commented Jul 2, 2022

Fix for #3035

What is the current behavior?

  1. Direct Router.NavigationStack manipulations are not affected on MAUI's NavigationPage.Navigation.NavigationStack
  2. MAUI's NavigationPage.PoppedToRoot event is not supported
  3. Double navigation to the same VM occures on application start

What is the new behavior?

Bugs are fixed
Sample app: https://github.com/ili/ReactiveUI-Navigation-Issue/tree/fix-maui-navigation

Other information:

Direct NavigationPage.Navigation manipulations are used to avoid page activations.

@codecov
Copy link

codecov bot commented Jul 2, 2022

Codecov Report

Merging #3303 (6a2394f) into main (196b8a6) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #3303   +/-   ##
=======================================
  Coverage   63.83%   63.83%           
=======================================
  Files         157      157           
  Lines        5726     5726           
=======================================
  Hits         3655     3655           
  Misses       2071     2071           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 196b8a6...6a2394f. Read the comment docs.

@glennawatson
Copy link
Contributor

Let me test and check out the code for you tomorrow. If it looks good I'll do a release for you then.

Thanks

@ili ili requested a review from glennawatson July 4, 2022 04:57
@ChrisPulman
Copy link
Member

Thanks for this PR.
I have tested the Android version and this seems to work as expected.

When I tested the same demo on Windows unfortunately the demo displays a blank screen due to a slightly different start-up process. I refactored some of the code to get it working however then I was then faced with a multitude of cross threading issues.
I will look into this in more detail to see if it's something to do with the manipulation of the core Navigation stack or just a scheduler issue elsewhere.

@ChrisPulman
Copy link
Member

I can verify that both Windows and Android Targets now operate with the latest commit.
Waiting for @RLittlesII to verify Mac/iOS and to accept the PR

MainThread.BeginInvokeOnMainThread(() =>
{
pg.Title = vm.UrlPathSegment;
});
Copy link
Contributor Author

@ili ili Jul 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChrisPulman there is the problem with setting title - setting it directly will break later binding.

Also if there are cross-thread issues may be it would be better to do smth like this:

	Router?
		.Navigate
		.ObserveOn(RxApp.MainThreadScheduler) // <-- here
		.SelectMany(_ => PagesForViewModel(Router.GetCurrentViewModel()))
		.SelectMany(async page =>

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that it will only affect the ability to bind the Title, which with other platforms such as Xamarin we set the Title property too.
However there could be some argument that we shouldn't be setting this property on any platform to allow the implementor to choose what and how the properties are set or bound.
There should be commonality across the platforms in my opinion.
I'll ask @glennawatson to add his opinion on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChrisPulman i can't say about Xamarin, may be there are some difference between Xamarin bindings & MAUI compiled bindings, but the fact is - setting Title on navigating breaks bindings. I'v commented this code in my local RoutedViewHost implementation, and this saves :)

@@ -205,7 +209,13 @@ protected virtual Page PageForViewModel(IRoutableViewModel vm)

ret.ViewModel = vm;

return (Page)ret;
var pg = (Page)ret;
MainThread.BeginInvokeOnMainThread(() =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't using the inbuilt RxUI way of doing this, so might be better to use RxApp.MainThreadScheduler

@glennawatson
Copy link
Contributor

Sorry @ili we think we've identified an issue with Maui and the windows target unrelated to your code in regards to the schedulers.

I think this is why ObserveOn is failing for @ChrisPulman and a lot of the sample.

Will get @RLittlesII to do a test of your sample to make sure it works fine on iOS and then we can do a release soon, and we will work on solving the scheduler issue for Maui.

In terms of the auto title setting. I'm thinking having a property setting if that functionality is desirable is the way to go. This will allow an easier migration path for existing Xamarin users but more flexibility to users like yourself who don't want that functionality.

@ili
Copy link
Contributor Author

ili commented Jul 6, 2022

@glennawatson @ChrisPulman really sorry if my comment would be stupid and obvious, but i'v faced with Windows cross thread exceptions until added reference to ReactiveUI.WinUI to my project:

	<ItemGroup Condition="'$(TargetFramework)' == 'net6.0-windows10.0.19041.0'">
	  <PackageReference Include="ReactiveUI.WinUI">
	    <Version>18.2.5</Version>
	  </PackageReference>
	</ItemGroup>

Use ObserveOn(RxApp.MainThreadScheduler) and RxApp.MainThreadScheduler.Schedule to handle cross threading.
Copy link
Member

@ChrisPulman ChrisPulman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for review of @RLittlesII before approval

/// <summary>
/// The Set Title on Navigate property.
/// </summary>
public static readonly BindableProperty SetTitleOnNavigateProperty = BindableProperty.Create(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added Set Title On Navigate Property

.DisposeWith(disposable);

Router?
.Navigate
.SelectMany(_ => PageForViewModel(Router.GetCurrentViewModel()))
.ObserveOn(RxApp.MainThreadScheduler)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added ObserveOn(RxApp.MainThreadScheduler)

if (SetTitleOnNavigate)
{
RxApp.MainThreadScheduler.Schedule(() => pg.Title = vm.UrlPathSegment);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used RxApp.MainThreadScheduler.Schedule to handle cross threading

@glennawatson glennawatson enabled auto-merge (squash) July 8, 2022 01:41
@glennawatson glennawatson merged commit 8fa79d1 into reactiveui:main Jul 8, 2022
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants