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 unable to select a tab after backing out of a page and returning. #25011

Merged
merged 11 commits into from
Jan 15, 2025
4 changes: 4 additions & 0 deletions src/Controls/src/Core/TabbedPage/TabbedPage.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ void OnHandlerDisconnected(FrameworkElement? platformView)
Appearing -= OnTabbedPageAppearing;
Disappearing -= OnTabbedPageDisappearing;
if (_navigationView != null)
{
_navigationView.SelectedItem = null;
_navigationView.SelectionChanged -= OnSelectedMenuItemChanged;
}

OnTabbedPageDisappearing(this, EventArgs.Empty);

Expand Down Expand Up @@ -331,6 +334,7 @@ internal static void MapItemsSource(ITabbedViewHandler handler, TabbedPage view)
vm.UnselectedTitleColor = view.BarTextColor?.AsPaint()?.ToPlatform();
vm.SelectedForeground = view.SelectedTabColor?.AsPaint()?.ToPlatform();
vm.UnselectedForeground = view.UnselectedTabColor?.AsPaint()?.ToPlatform();
vm.IsSelected = page == view.CurrentPage;
});

handler.UpdateValue(nameof(TabbedPage.CurrentPage));
Expand Down
36 changes: 36 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue24741.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 24741, "Unable to select tab after backing out of page and returning", PlatformAffected.UWP)]
public class Issue24741 : NavigationPage
{
public Issue24741() : base(new TestPage())
{
}

public class TestPage : TestContentPage
{
protected override void Init()
{
Title = "Issue 24741";

var navigationButton = new Button
{
AutomationId = "NavigateButton",
Text = "Navigate to TabbedPage"
};

navigationButton.Clicked += (s, e) =>
{
Navigation.PushAsync(new Issue24741TabbedPage());
};

var content = new VerticalStackLayout
{
navigationButton
};

Content = content;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue24741TabbedPage"
xmlns:issues="clr-namespace:Maui.Controls.Sample.Issues">
<issues:Issue24741Page1 />
<issues:Issue24741Page2 />
</TabbedPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace Maui.Controls.Sample.Issues;

public partial class Issue24741TabbedPage : TabbedPage
{
public Issue24741TabbedPage()
{
InitializeComponent();
}
}

public class Issue24741Page1 : ContentPage
{
public Issue24741Page1()
{
Title = "Page 1";

var content = new Button
{
AutomationId = "Page1Button",
Text = "Page 1"
};

content.Clicked += async (sender, args) =>
{
await Navigation.PopAsync();
};

Content = new VerticalStackLayout
{
content
};
}
}

public class Issue24741Page2 : ContentPage
{
public Issue24741Page2()
{
Title = "Page 2";

var content = new Button
{
AutomationId = "Page2Button",
Text = "Page 2"
};

content.Clicked += async (sender, args) =>
{
await Navigation.PopAsync();
};

Content = new VerticalStackLayout
{
content
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#if WINDOWS
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

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

public override string Issue => "Unable to select tab after backing out of page and returning";

[Test]
[Category(UITestCategories.TabbedPage)]
public void SelectTabAfterNavigation()
PureWeen marked this conversation as resolved.
Show resolved Hide resolved
PureWeen marked this conversation as resolved.
Show resolved Hide resolved
{
const string Page2Title = "Page 2";

// 1. Navigate to the TabbedPage.
App.WaitForElement("NavigateButton");
App.Tap("NavigateButton");

// 2. Click the second Tab.
App.Tap(Page2Title);

// 3. Navigate back.
App.WaitForElement("Page2Button");
App.Tap("Page2Button");

// 4. Repeat the process. Navigate to the TabbedPage.
App.WaitForElement("NavigateButton");
App.Tap("NavigateButton");

// 2. Click the second Tab.
App.Tap(Page2Title);

// 6. Screenshot to validate the result.
VerifyScreenshot();
App.Back();
}
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public bool IsSelected
{
_isSelected = value;
OnPropertyChanged(nameof(Background));
OnPropertyChanged(nameof(TitleColor));
UpdateForeground();
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/TestUtils/src/UITest.Appium/AppiumApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public virtual IUIElement FindElement(IQuery query)
#nullable disable
public virtual IUIElement FindElementByText(string text)
{
return AppiumQuery.ByXPath("//*[@text='" + text + "' or @Name='" + text + "']").FindElement(this);
// Android (text), iOS (label), Windows (Name)
return AppiumQuery.ByXPath("//*[@text='" + text + "' or @label='" + text + "' or @Name='" + text + "']").FindElement(this);
}
#nullable enable

Expand All @@ -101,7 +102,8 @@ public virtual IReadOnlyCollection<IUIElement> FindElements(string id)

public virtual IReadOnlyCollection<IUIElement> FindElementsByText(string text)
{
return AppiumQuery.ByXPath("//*[@text='" + text + "' or @Name='" + text + "']").FindElements(this);
// Android (text), iOS (label), Windows (Name)
return AppiumQuery.ByXPath("//*[@text='" + text + "' or @label='" + text + "' or @Name='" + text + "']").FindElements(this);
}

public virtual IReadOnlyCollection<IUIElement> FindElements(IQuery query)
Expand Down
Loading