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

Navigation RouteNotifier.RouteChanged not invoked #2606

Open
3 tasks
KWodarczyk opened this issue Nov 8, 2024 · 3 comments
Open
3 tasks

Navigation RouteNotifier.RouteChanged not invoked #2606

KWodarczyk opened this issue Nov 8, 2024 · 3 comments
Labels
kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification.

Comments

@KWodarczyk
Copy link

KWodarczyk commented Nov 8, 2024

Current behavior

RouteNotifier.RouteChanged is not fired, Application it stuck at loading screen

Expected behavior

RouteNotifier.RouteChanged should fire when navigator.NavigateRouteAsync is called

App.xaml.cs

    private void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
    {
        views.Register(
            new ViewMap(ViewModel: typeof(ShellViewModel)),
            new ViewMap<MainPage, MainViewModel>(),
            new ViewMap<FirstPage, FirstViewModel>(),
            new DataViewMap<SecondPage, SecondViewModel, Entity>()
        );

        routes.Register(
            new RouteMap("", View: views.FindByViewModel<ShellViewModel>(),
                Nested:
                [
                    new ("Main", View: views.FindByViewModel<MainViewModel>(),IsDefault:true)
                ]
            )
        );
    }

Main Page xaml

<Page x:Class="UnoAppNavigation2.Presentation.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="using:UnoAppNavigation2"
      xmlns:Presentation="using:UnoAppNavigation2.Presentation"
      xmlns:uen="using:Uno.Extensions.Navigation.UI"
      xmlns:utu="using:Uno.Toolkit.UI"
      Loaded="Page_Loaded"
      Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

  <Grid uen:Region.Attached="True" RowDefinitions="auto,*">
    <StackPanel Grid.Row="0" HorizontalAlignment="Left" Orientation="Horizontal" Background="DarkSlateGray">
         <TextBlock>
           <Run Text="URL:"/>
           <Run x:Name="UrlPath"/>
         </TextBlock>
    </StackPanel>

        <NavigationView Grid.Row="1"
            uen:Region.Attached="true"
            PaneDisplayMode="Top"
            IsSettingsVisible="False"
            ItemInvoked="NavigationView_ItemInvoked"
            IsBackButtonVisible="Collapsed"
            IsBackEnabled="False">
            <NavigationView.MenuItems>

                <NavigationViewItem
                  Content="One"
                  x:Name="OneTab"
                  uen:Region.Name="{x:Bind local:PageNames.FirstPage}" />

                <NavigationViewItem
                  Content="Two"
                  x:Name="TwoTab"
                  uen:Region.Name="{x:Bind local:PageNames.SecondPage}" />

            </NavigationView.MenuItems>

            <Grid uen:Region.Attached="True"
                  uen:Region.Navigator="Visibility">

              <Presentation:FirstPage Visibility="Collapsed" uen:Region.Name="{x:Bind local:PageNames.FirstPage}"/>
              <Presentation:SecondPage Visibility="Collapsed" uen:Region.Name="{x:Bind local:PageNames.SecondPage}"/>

            </Grid>
        </NavigationView>
    </Grid>
</Page>

Main page that navigates to FirstPage on Loaded

public sealed partial class MainPage : Page
{
    private App? _app;

    public MainViewModel? ViewModel { get; set; }

    public MainPage()
    {
        _app = (Application.Current as App);

        INavigator navigator = this.Navigator();

        this.InitializeComponent();

        UrlPath.Text =  _app?.MainHref + " base url:"+_app.BaseUrl;
    }

    private void NavigationView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
    {
        Console.WriteLine($"==== Navigation invoked =====");
    }

    private async void Page_Loaded(object sender, RoutedEventArgs e)
    {
        var navigator = this.Navigator();
        Console.WriteLine($"====    Navigation to {PageNames.FirstPage} =======");
        var result = await navigator.NavigateRouteAsync(this, PageNames.FirstPage);  //This does not invoke RouteChange
    }
}

First Page that subscribes to RoutChanged event

public sealed partial class FirstPage : Page
{
    private App _app;

    public FirstPage()
    {
        _app = (Application.Current as App);

        this.InitializeComponent();

        var notifier = _app.Host.Services.GetService<IRouteNotifier>();

        notifier.RouteChanged += OnRouteChanged;

        Debug.WriteLine("============= First  Page Ctor ===========");

        Debug.WriteLine($"is Rount NOtifier null ? {notifier is null}");
    }

    private void OnRouteChanged(object? sender, RouteChangedEventArgs e)
    {
        Debug.WriteLine($"===== In First Page route changed to {e.Region.Name}");
    }

    private void Page_Loaded(object sender, RoutedEventArgs e)
    {
        Console.WriteLine("============= First  Page Loaded ===========");
    }

    private void Page_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
    {
        Console.WriteLine("============= First  Page Context Canchged ===========");
    }
}

Page Loaded screen

image

Application gets stuck at loading

image

How to reproduce it (as minimally and precisely as possible)

Build project attached and run it in Windows Apps Sdk target or WASM
Uploading UnoAppNavigation2.zip…

Environment

Nuget Package (s):

Package Version(s):

"Uno.Sdk": "5.4.10"

Affected platform(s):

  • WebAssembly
  • Windows

Visual Studio:

  • 2022 (version: )

Relevant plugins:

Visual Studio 2022
"Uno.Sdk": "5.4.10"

Anything else we need to know?

@KWodarczyk KWodarczyk added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification. labels Nov 8, 2024
@eriklimakc
Copy link
Contributor

@KWodarczyk Thank you for reporting this issue. It seems that the link to the repro app you provided is not working correctly. Could you please check and provide an updated link? Thank you!

@KWodarczyk
Copy link
Author

@eriklimakc hi, not sure if i still have that project but will try to find it, i used "click to add files" and added .zip but not sure why it's not working. I will try to do it again but this can be also reproduces from the pasted code above.

@KWodarczyk
Copy link
Author

KWodarczyk commented Nov 15, 2024

UnoAppNavigation2.zip

@eriklimakc hope this works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification.
Projects
None yet
Development

No branches or pull requests

2 participants