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

[Windows]Fixed Shell Navigating event issue when switching tabs #27197

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,22 @@ private void OnNavigationTabChanged(NavigationView sender, NavigationViewSelecti

var selectedItem = (NavigationViewItemViewModel)args.SelectedItem;

if (selectedItem.Data is ShellSection shellSection)
if (selectedItem.Data is ShellSection shellSection && VirtualView.Parent is Shell shell)
{
NavigationViewItemViewModel? currentItem = null;
foreach (var item in _mainLevelTabs)
{
if (shell.CurrentItem?.CurrentItem is not null && item.Data == shell.CurrentItem.CurrentItem)
{
currentItem = item;
break;
}
}
if (PlatformView is NavigationView navView && navView?.SelectedItem is not null && navView.SelectedItem != currentItem)
{
((IShellItemController)shell.CurrentItem!).ProposeSection(shellSection);
}

((Shell)VirtualView.Parent).CurrentItem = shellSection;
}
else if (selectedItem.Data is ShellContent shellContent)
Expand Down
36 changes: 36 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25599.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8" ?>
<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue25599"
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues">
<TabBar>
<Tab Title="Home" x:Name="FirstTab" AutomationId="Tab1">
<ShellContent
Title="Home" >
<ShellContent.ContentTemplate>
<DataTemplate>
<ContentPage x:Name="firstPage">
<StackLayout>
<Button Text="Click" Clicked="Button_Clicked" AutomationId="HomePageButton"/>
<Label Text="Home Page" AutomationId="HomePageLabel"/>
</StackLayout>
</ContentPage>
</DataTemplate>
</ShellContent.ContentTemplate>
</ShellContent>
</Tab>
<Tab Title="Settings" x:Name="SecondTab">
<ShellContent>
<ShellContent.ContentTemplate>
<DataTemplate>
<ContentPage x:Name="secondPage">
<StackLayout>
<Label x:Name="settingsPageLabel" Text="SettingsPage" />
</StackLayout>
</ContentPage>
</DataTemplate>
</ShellContent.ContentTemplate>
</ShellContent>
</Tab>
</TabBar>
</Shell>
35 changes: 35 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25599.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 25599, "OnNavigating wrong target when tapping the same tab", PlatformAffected.iOS)]
public partial class Issue25599 : Shell
{
public Issue25599()
{
InitializeComponent();
}

private async void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new DetailsPage());
}

public class DetailsPage : ContentPage
{
public DetailsPage()
{
Title = "DetailsPage";

Content = new StackLayout
{
Children =
{
new Label
{
Text = "Details Page",
AutomationId = "DetailsPageLabel"
}
}
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#if TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_IOS // To fix the issue in ios https://github.com/dotnet/maui/pull/25749#pullrequestreview-2554186362
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue25599 : _IssuesUITest
{
public Issue25599(TestDevice testDevice) : base(testDevice){ }

public override string Issue => "OnNavigating wrong target when tapping the same tab";

[Test]
[Category(UITestCategories.Navigation)]
public void NavigatingEventFired()
{
App.WaitForElement("HomePageButton");
App.Tap("HomePageButton");
App.WaitForElement("DetailsPageLabel");
App.Tap("Home"); // Tapping already selected tab using Title
App.WaitForElement("DetailsPageLabel");
App.WaitForNoElement("HomePageLabel"); // Navigation does not occur when clicking on an already selected tab
}
}
}
#endif
Loading