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

NavigationView: Fix IsPaneOpen=false ignored on launch when pane is launched in Left expanded state #3197

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
19 changes: 12 additions & 7 deletions dev/NavigationView/NavigationView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3846,14 +3846,19 @@ void NavigationView::OnIsPaneOpenChanged()
}
else if (!m_isOpenPaneForInteraction && !isPaneOpen)
{
if (auto splitView = m_rootSplitView.get())
if (const auto splitView = m_rootSplitView.get())
{
// splitview.IsPaneOpen and nav.IsPaneOpen is two way binding. There is possible change that SplitView.IsPaneOpen=false, then
// nav.IsPaneOpen=false. We don't need to set force flag in this situation
if (splitView.IsPaneOpen())
{
m_wasForceClosed = true;
}
// splitview.IsPaneOpen and nav.IsPaneOpen is two way binding. If nav.IsPaneOpen=false and splitView.IsPaneOpen=true,
// then the pane has been closed by API and we treat it as a forced close.
// If, however, splitView.IsPaneOpen=false, then nav.IsPaneOpen is just following the SplitView here and the pane
// was closed, for example, due to app window resizing. We don't set the force flag in this situation.
m_wasForceClosed = splitView.IsPaneOpen();
}
else
{
// If there is no SplitView (for example it hasn't been loaded yet) then nav.IsPaneOpen was set directly
// so we treat it as a closed force.
m_wasForceClosed = true;
}
}

Expand Down
171 changes: 165 additions & 6 deletions dev/NavigationView/NavigationView_ApiTests/NavigationViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ private NavigationView SetupNavigationView(NavigationViewPaneDisplayMode paneDis
return navView;
}


private NavigationView SetupNavigationViewScrolling(NavigationViewPaneDisplayMode paneDisplayMode = NavigationViewPaneDisplayMode.Auto)
{
NavigationView navView = null;
Expand Down Expand Up @@ -276,6 +275,166 @@ public void VerifyPaneDisplayModeChangingPaneAccordingly()
}
}

[TestMethod]
public void VerifyPaneDisplayModeAndIsPaneOpenInterplayOnNavViewLaunch()
{
Log.Comment("--- PaneDisplayMode: LeftMinimal ---");
VerifyForPaneDisplayModeLeftMinimal();

Log.Comment("--- PaneDisplayMode: LeftCompact ---");
VerifyForPaneDisplayModeLeftCompact();

Log.Comment("--- PaneDisplayMode: Left ---");
VerifyForPaneDisplayModeLeft();

Log.Comment("--- PaneDisplayMode: Auto ---");
VerifyForPaneDisplayModeAuto();

void VerifyForPaneDisplayModeLeftMinimal()
{
Log.Comment("Verify pane is closed when IsPaneOpen=true");
var navView = SetupNavView(NavigationViewPaneDisplayMode.LeftMinimal, true);

RunOnUIThread.Execute(() =>
{
Verify.IsFalse(navView.IsPaneOpen, "NavigationView pane should have been closed");
});

Log.Comment("Verify pane is closed when IsPaneOpen=false");
navView = SetupNavView(NavigationViewPaneDisplayMode.LeftMinimal, false);

RunOnUIThread.Execute(() =>
{
Verify.IsFalse(navView.IsPaneOpen, "NavigationView pane should have been closed");
});
}

void VerifyForPaneDisplayModeLeftCompact()
{
Log.Comment("Verify pane is closed when IsPaneOpen=true");
var navView = SetupNavView(NavigationViewPaneDisplayMode.LeftCompact, true);

RunOnUIThread.Execute(() =>
{
Verify.IsFalse(navView.IsPaneOpen, "NavigationView pane should have been closed");
});

Log.Comment("Verify pane is closed when IsPaneOpen=false");
navView = SetupNavView(NavigationViewPaneDisplayMode.LeftCompact, false);

RunOnUIThread.Execute(() =>
{
Verify.IsFalse(navView.IsPaneOpen, "NavigationView pane should have been closed");
});
}

void VerifyForPaneDisplayModeLeft()
{
Log.Comment("Verify pane is open when IsPaneOpen=true");
var navView = SetupNavView(NavigationViewPaneDisplayMode.Left, true);

RunOnUIThread.Execute(() =>
{
Verify.IsTrue(navView.IsPaneOpen, "NavigationView pane should have been open");
});

Log.Comment("Verify pane is closed when IsPaneOpen=false");
navView = SetupNavView(NavigationViewPaneDisplayMode.Left, false);

RunOnUIThread.Execute(() =>
{
Verify.IsFalse(navView.IsPaneOpen, "NavigationView pane should have been closed");
});
}

void VerifyForPaneDisplayModeAuto()
{
Log.Comment("Verify pane is closed when launched in minimal state and IsPaneOpen=true");
var navView = SetupNavView(NavigationViewPaneDisplayMode.Auto, true, NavigationViewDisplayMode.Minimal);

RunOnUIThread.Execute(() =>
{
Verify.IsFalse(navView.IsPaneOpen, "NavigationView pane should have been closed");
});

Log.Comment("Verify pane is closed when launched in compact state and IsPaneOpen=true");
navView = SetupNavView(NavigationViewPaneDisplayMode.Auto, true, NavigationViewDisplayMode.Compact);

RunOnUIThread.Execute(() =>
{
Verify.IsFalse(navView.IsPaneOpen, "NavigationView pane should have been closed");
});

Log.Comment("Verify pane is open when launched in expanded state and IsPaneOpen=true");
navView = SetupNavView(NavigationViewPaneDisplayMode.Auto, true, NavigationViewDisplayMode.Expanded);

RunOnUIThread.Execute(() =>
{
Verify.IsTrue(navView.IsPaneOpen, "NavigationView pane should have been open");
});

Log.Comment("Verify pane is closed when launched in minimal state and IsPaneOpen=false");
navView = SetupNavView(NavigationViewPaneDisplayMode.Auto, false, NavigationViewDisplayMode.Minimal);

RunOnUIThread.Execute(() =>
{
Verify.IsFalse(navView.IsPaneOpen, "NavigationView pane should have been closed");
});

Log.Comment("Verify pane is closed when launched in compact state and IsPaneOpen=false");
navView = SetupNavView(NavigationViewPaneDisplayMode.Auto, false, NavigationViewDisplayMode.Compact);

RunOnUIThread.Execute(() =>
{
Verify.IsFalse(navView.IsPaneOpen, "NavigationView pane should have been closed");
});

Log.Comment("Verify pane is closed when launched in expanded state and IsPaneOpen=false");
navView = SetupNavView(NavigationViewPaneDisplayMode.Auto, false, NavigationViewDisplayMode.Expanded);

RunOnUIThread.Execute(() =>
{
Verify.IsFalse(navView.IsPaneOpen, "NavigationView pane should have been closed");
});
}

NavigationView SetupNavView(NavigationViewPaneDisplayMode paneDisplayMode, bool isPaneOpen, NavigationViewDisplayMode displayMode = NavigationViewDisplayMode.Expanded)
{
NavigationView navView = null;
RunOnUIThread.Execute(() =>
{
navView = new NavigationView();
navView.MenuItems.Add(new NavigationViewItem() { Content = "MenuItem" });

navView.PaneDisplayMode = paneDisplayMode;
navView.IsPaneOpen = isPaneOpen;
navView.ExpandedModeThresholdWidth = 600.0;
navView.CompactModeThresholdWidth = 400.0;

if (paneDisplayMode == NavigationViewPaneDisplayMode.Auto)
{
switch (displayMode)
{
case NavigationViewDisplayMode.Minimal:
navView.Width = navView.CompactModeThresholdWidth - 10.0;
break;
case NavigationViewDisplayMode.Compact:
navView.Width = navView.ExpandedModeThresholdWidth - 10.0;
break;
case NavigationViewDisplayMode.Expanded:
navView.Width = navView.ExpandedModeThresholdWidth + 10.0;
break;
}
}

Content = navView;
});

IdleSynchronizer.Wait();
return navView;
}
}

[TestMethod]
public void VerifyDefaultsAndBasicSetting()
{
Expand Down Expand Up @@ -641,18 +800,18 @@ public void VerifyCanNotAddWUXItems()
}

[TestMethod]
public void VerifyVerifyHeaderContentMarginOnTopNav()
public void VerifyHeaderContentMarginOnTopNav()
{
VerifyVerifyHeaderContentMargin(NavigationViewPaneDisplayMode.Top, "VerifyVerifyHeaderContentMarginOnTopNav");
VerifyHeaderContentMargin(NavigationViewPaneDisplayMode.Top, "VerifyVerifyHeaderContentMarginOnTopNav");
}

[TestMethod]
public void VerifyVerifyHeaderContentMarginOnMinimalNav()
public void VerifyHeaderContentMarginOnMinimalNav()
{
VerifyVerifyHeaderContentMargin(NavigationViewPaneDisplayMode.LeftMinimal, "VerifyVerifyHeaderContentMarginOnMinimalNav");
VerifyHeaderContentMargin(NavigationViewPaneDisplayMode.LeftMinimal, "VerifyVerifyHeaderContentMarginOnMinimalNav");
}

private void VerifyVerifyHeaderContentMargin(NavigationViewPaneDisplayMode paneDisplayMode, string verificationFileNamePrefix)
private void VerifyHeaderContentMargin(NavigationViewPaneDisplayMode paneDisplayMode, string verificationFileNamePrefix)
{
UIElement headerContent = null;

Expand Down