Skip to content

Commit

Permalink
Fix Shell Flyout Menu Visibility Issue When Navigating Between TabBar…
Browse files Browse the repository at this point in the history
… and Flyout Items (dotnet#25510)

* 25436 - Flyout menu should be visible after navigating from a menu item

* Alternative fix committed

* Added the testcases and its images

* Committed the windows image and changed the tap coordinates to Xpath for Android

---------

Co-authored-by: Karthik Raja <92788387+karthikraja-arumugam@users.noreply.github.com>
Co-authored-by: AhamedAliNishad <ahamedalinishad.j@syncfusion.com>
Co-authored-by: Rui Marinho <me@ruimarinho.net>
  • Loading branch information
4 people authored Nov 27, 2024
1 parent d91bf0a commit 0893ce0
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Shell/Shell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,7 +1860,7 @@ ShellAppearance GetAppearanceForPivot(Element pivot)
return null;
}

void NotifyFlyoutBehaviorObservers()
internal void NotifyFlyoutBehaviorObservers()
{
if (CurrentItem == null || GetVisiblePage() == null)
return;
Expand Down
10 changes: 7 additions & 3 deletions src/Controls/src/Core/Shell/ShellContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,14 @@ internal void EvaluateDisconnect()
// If the user has set the IsVisible property on this shell content to false
bool disconnect = true;

if (Parent is ShellSection shellSection &&
Shell shell = null;

if (Parent is ShellSection shellSection &&
shellSection.Parent is ShellItem shellItem &&
shellItem.Parent is Shell shell)
shellItem.Parent is Shell shellInstance)
{
disconnect =
shell = shellInstance;
disconnect =
!this.IsVisible || // user has set the IsVisible property to false
(_contentCache is not null && !_contentCache.IsVisible) || // user has set IsVisible on the Page to false
shell.CurrentItem != shellItem || // user has navigated to a different TabBar or a different FlyoutItem
Expand All @@ -243,6 +246,7 @@ shellSection.Parent is ShellItem shellItem &&

if (!disconnect)
{
shell?.NotifyFlyoutBehaviorObservers();
return;
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25436.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<local:TestShell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="using:Maui.Controls.Sample.Issues"
xmlns:issues="clr-namespace:Maui.Controls.Sample.Issues"
x:Class="Maui.Controls.Sample.Issues.Issue25436">

<FlyoutItem Title="Home" >
<ShellContent
ContentTemplate="{DataTemplate issues:Issue25436Firstpage}"
Route="home" />
</FlyoutItem>
<TabBar>
<ShellContent
ContentTemplate="{DataTemplate issues:Issue25436LoginPage}"
Route="login" />
</TabBar>

</local:TestShell>
98 changes: 98 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25436.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using Maui.Controls.Sample.Issues;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 25436, "[.NET 9] Shell Flyout menu not rendering after navigating from a MenuItem page", PlatformAffected.All)]
public partial class Issue25436 : TestShell
{
public Issue25436()
{
InitializeComponent();
}
protected override void Init()
{

}

}
public class Issue25436Firstpage : ContentPage
{
public Issue25436Firstpage()
{
var button = new Button
{
Text = "Click here to navigate back",
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center
};
button.Clicked += async (s, e) => await Shell.Current.GoToAsync("//login");
Content = button;
button.AutomationId = "BackButton";
Title = "_25436 first flyout";
}
}

public class Issue25436LoginPage : ContentPage
{
Issue25436INavigationService _navigationService;
public Issue25436LoginPage(Issue25436INavigationService navigationService)
{
_navigationService = navigationService;
var loginButton = new Button
{
Text = "Login"
};
loginButton.AutomationId = "Login";
loginButton.Clicked += OnLoginButtonClicked;

Content = new StackLayout
{
Children =
{
new Label { Text = "This is the login page" },
loginButton
}
};
Title = "_25436 login page";
}
private async void OnLoginButtonClicked(object sender, EventArgs e)
{
await _navigationService.GoToAsync("//home");
}
}

static class Issue25436Extensions
{
public static MauiAppBuilder Issue25436RegisterNavigationService(this MauiAppBuilder builder)
{
// Register services
builder.Services.AddSingleton<Issue25436INavigationService, Issue25436NavigationService>();

// Register pages
builder.Services.AddTransient<Issue25436LoginPage>();
builder.Services.AddSingleton<Issue25436Firstpage>();

return builder;
}
}

public interface Issue25436INavigationService
{
Task GoToAsync(string route);
}

public partial class Issue25436NavigationService : Issue25436INavigationService
{
public Task GoToAsync(string route)
{
if (Shell.Current is null)
{
throw new NotSupportedException($"Navigation with the '{nameof(GoToAsync)}' method is currently supported only with a Shell-enabled application.");
}

return Shell.Current.GoToAsync(route);
}
}

}

3 changes: 2 additions & 1 deletion src/Controls/tests/TestCases.HostApp/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public static MauiApp CreateMauiApp()
.Issue18720AddMappers()
.Issue18720EditorAddMappers()
.Issue18720DatePickerAddMappers()
.Issue18720TimePickerAddMappers();
.Issue18720TimePickerAddMappers()
.Issue25436RegisterNavigationService();

#if IOS || MACCATALYST

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#if !MACCATALYST
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
internal class Issue25436 : _IssuesUITest
{
public override string Issue => "[.NET 9] Shell Flyout menu not rendering after navigating from a MenuItem page";

public Issue25436(TestDevice testDevice) : base(testDevice) { }

[Test]
[Category(UITestCategories.Shell)]
public void FlyoutMenuShouldNotDisappearWhenNavigateUsingServices()
{
App.WaitForElement("BackButton");
App.Tap("BackButton");
App.WaitForElement("Login");
App.Tap("Login");
#if ANDROID
App.Tap(AppiumQuery.ByXPath("//android.widget.ImageButton[@content-desc='Open navigation drawer']"));
#else
App.Tap(FlyoutIconAutomationId);
#endif
VerifyScreenshot();
}

}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0893ce0

Please sign in to comment.