Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
25 changes: 24 additions & 1 deletion src/Controls/src/Core/Shell/ShellSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,30 @@ static void OnCurrentItemChanged(BindableObject bindable, object oldValue, objec

if (shellSection.Parent?.Parent is IShellController shell && shellSection.IsVisibleSection)
{
shell.UpdateCurrentState(ShellNavigationSource.ShellContentChanged);
if (shellSection.Parent?.Parent is Shell parentShell && shellSection.IsVisibleSection)
Comment thread
jpd21122012 marked this conversation as resolved.
Resolved
{
var navigationManager = parentShell.NavigationManager;

var proposedState = ShellNavigationManager.GetNavigationState(
parentShell.CurrentItem,
shellSection,
(ShellContent)newValue,
null,
null);
Comment thread
jpd21122012 marked this conversation as resolved.
Resolved

var navArgs = new ShellNavigatingEventArgs(
parentShell.CurrentState,
proposedState,
ShellNavigationSource.ShellContentChanged,
true);
Comment thread
jpd21122012 marked this conversation as resolved.
Resolved

navigationManager.HandleNavigating(navArgs);

if (navArgs.Cancelled)
return;

Comment thread
jpd21122012 marked this conversation as resolved.
Resolved
((IShellController)parentShell).UpdateCurrentState(ShellNavigationSource.ShellContentChanged);
}
Comment thread
jpd21122012 marked this conversation as resolved.
Resolved
}

shellSection.SendStructureChanged();
Expand Down
68 changes: 68 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue34318.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.ApplicationModel;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 34318, "Shell Navigating event should fire on ShellContent change", PlatformAffected.All)]
public class Issue34318 : Shell
{
public Issue34318()
{
// When Shell.Navigating fires, broadcast a message the page test can observe
Navigating += (s, e) => MessagingCenter.Send(this, "NavigatingFired");

Comment thread
jpd21122012 marked this conversation as resolved.
Resolved
var section = new ShellSection();

Comment thread
jpd21122012 marked this conversation as resolved.
Resolved
var contentA = new ShellContent
{
Content = new Issue34318_PageA()
};

var contentB = new ShellContent
{
Content = new ContentPage { Title = "PageB", Content = new Label { Text = "Page B", AutomationId = "PageBLabel" } }
};

section.Items.Add(contentA);
section.Items.Add(contentB);

var item = new ShellItem();
item.Items.Add(section);

Items.Add(item);
}

public class Issue34318_PageA : ContentPage
{
Label resultLabel;

public Issue34318_PageA()
{
Title = "PageA";
Comment thread
jpd21122012 marked this conversation as resolved.
Resolved
resultLabel = new Label { Text = "Waiting", AutomationId = "ResultLabel" };

var button = new Button { Text = "Change Content", AutomationId = "ChangeContentButton" };
button.Clicked += (s, e) =>
{
if (Parent is ShellSection section && section.Items.Count > 1)
{
section.CurrentItem = section.Items[1];
Comment thread
jpd21122012 marked this conversation as resolved.
Resolved
}
};

// Update the label when the shell raises Navigating (message sent from Shell)
MessagingCenter.Subscribe<Shell>(this, "NavigatingFired", (sender) =>
{
MainThread.BeginInvokeOnMainThread(() =>
{
resultLabel.Text = "Navigating";
});
});

Content = new VerticalStackLayout
{
Children = { button, resultLabel }
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue34318 : _IssuesUITest
{
public Issue34318(TestDevice device) : base(device) { }

public override string Issue => "Shell Navigating event should fire on ShellContent change";

[Test]
[Category(UITestCategories.Shell)]
public void NavigatingFiresWhenShellContentChanges()
{
// Wait for the page and button
App.WaitForElement("ChangeContentButton");

// Tap the button to change the current ShellContent
App.Tap("ChangeContentButton");

// Wait for the label to update via the Navigating message
App.WaitForElement("ResultLabel");

App.WaitForElement("Navigating");

var text = App.FindElement("ResultLabel").GetText();

Assert.That(text, Is.EqualTo("Navigating"));
}
}
Loading