Skip to content

Fix Changing Shell.NavBarIsVisible does not update the nav bar #30339

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
12 changes: 12 additions & 0 deletions src/Controls/src/Core/Shell/BaseShellItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ internal static void PropagateFromParent(BindableProperty property, Element me)
if (me == null || me.Parent == null)
return;

// For Shell.NavBarIsVisibleProperty, find the shell instance for more accurate propagation
if (property == Shell.NavBarIsVisibleProperty)
{
var shell = me.FindParentOfType<Shell>();
if (shell is not null && shell.IsSet(property))
{
// Get the value from the Shell directly
me.SetValue(property, shell.GetValue(property));
return;
}
}

Propagate(property, me.Parent, me, false);
}

Expand Down
12 changes: 11 additions & 1 deletion src/Controls/src/Core/Shell/Shell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,17 @@ private static void OnNavBarIsVisibleChanged(BindableObject bindable, object old
?? (bindable as BaseShellItem)?.FindParentOfType<Shell>()
?? (bindable as Page)?.FindParentOfType<Shell>();

shell?.OnPropertyChanged(NavBarIsVisibleProperty.PropertyName);
if (shell != null)
{
// Notify about the property change
shell.OnPropertyChanged(NavBarIsVisibleProperty.PropertyName);

// Explicitly propagate the property change to all children
if (shell is IPropertyPropagationController controller)
{
controller.PropagatePropertyChanged(NavBarIsVisibleProperty.PropertyName);
}
}
}

/// <summary>
Expand Down
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.
57 changes: 57 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue17550.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 17550, "Changing Shell.NavBarIsVisible does not update the nav bar on Mac / iOS",
PlatformAffected.UWP)]
public class Issue17550 : TestShell
{
Button _toggleButton;

protected override void Init()
{
// Create a toggle button similar to the one in SandboxShell.xaml
_toggleButton = new Button
{
Text = Shell.GetNavBarIsVisible(this) ? "Hide NavBar" : "Show NavBar",
HeightRequest = 50,
WidthRequest = 150,
AutomationId = "NavBarToggleButton",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};

_toggleButton.Clicked += OnNavBarToggleButtonClicked;

// Add the button to a content page in the shell
Items.Add(new ShellContent
{
Content = new ContentPage
{
Title = "Home",
Content = new StackLayout
{
Children =
{
new Label
{
Text = "Toggle NavBar visibility",
HorizontalOptions = LayoutOptions.Center
},
_toggleButton
},
VerticalOptions = LayoutOptions.Center
}
}
});
}

void OnNavBarToggleButtonClicked(object sender, EventArgs e)
{
// Toggle the NavBar visibility
bool isCurrentlyVisible = Shell.GetNavBarIsVisible(this);
bool newVisibility = !isCurrentlyVisible;
Shell.SetNavBarIsVisible(this, newVisibility);

// Update the button text to reflect the new state
_toggleButton.Text = newVisibility ? "Hide NavBar" : "Show NavBar";
}
}
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using NUnit.Framework;
using NUnit.Framework.Legacy;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;
public class Issue17550 : _IssuesUITest
{
public Issue17550(TestDevice device) : base(device) { }
public override string Issue => "Changing Shell.NavBarIsVisible does not update the nav bar on Mac / iOS";

[Test, Order(1)]
[Category(UITestCategories.Shell)]
public void VerifyNavBarStatusAtInitialLoading()
{
App.WaitForElement("NavBarToggleButton");
VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending snapshots. Running a build.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image Snapshots already available in the latest build. Could you commit the images?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz , Pending snapshots has been added.

}

[Test, Order(2)]
[Category(UITestCategories.Shell)]
public void VerifyNavBarStatusAtRuntime()
{
App.WaitForElement("NavBarToggleButton");
App.Tap("NavBarToggleButton");
VerifyScreenshot();
}
}
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.
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.
Loading