-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix for MAUI RoutedViewHost #3303
Conversation
Codecov Report
@@ 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.
|
Let me test and check out the code for you tomorrow. If it looks good I'll do a release for you then. Thanks |
Thanks for this PR. 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 can verify that both Windows and Android Targets now operate with the latest commit. |
MainThread.BeginInvokeOnMainThread(() => | ||
{ | ||
pg.Title = vm.UrlPathSegment; | ||
}); |
There was a problem hiding this comment.
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 =>
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(() => |
There was a problem hiding this comment.
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
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 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. |
@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
|
Use ObserveOn(RxApp.MainThreadScheduler) and RxApp.MainThreadScheduler.Schedule to handle cross threading.
There was a problem hiding this 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( |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
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. |
Fix for #3035
What is the current behavior?
Router.NavigationStack
manipulations are not affected on MAUI'sNavigationPage.Navigation.NavigationStack
NavigationPage.PoppedToRoot
event is not supportedVM
occures on application startWhat 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.