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 issue with NavigationView ShoulderNavigation always not behaving correctly #3145

Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions dev/NavigationView/NavigationView.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#include "pch.h"
Expand Down Expand Up @@ -2671,9 +2671,11 @@ bool NavigationView::BumperNavigation(int offset)
// that meets the conditions, in the same direction.
const auto shoulderNavigationEnabledParamValue = ShoulderNavigationEnabled();
const auto shoulderNavigationForcedDisabled = (shoulderNavigationEnabledParamValue == winrt::NavigationViewShoulderNavigationEnabled::Never);
const auto shoulderNavigationOptionalDisabled = (shoulderNavigationEnabledParamValue == winrt::NavigationViewShoulderNavigationEnabled::WhenSelectionFollowsFocus
&& SelectionFollowsFocus() == winrt::NavigationViewSelectionFollowsFocus::Disabled);

if (!IsTopNavigationView()
|| !IsNavigationViewListSingleSelectionFollowsFocus()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should we remove this function altogether? This is more or less a relic now since we are not using ListView anymore and the function doesn't do anything we couldn't do elsewhere (and we already do in a few cases).

Copy link
Contributor

Choose a reason for hiding this comment

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

It does seem pretty trivial, I think it would probably be easier to parse the code if we removed it


In reply to: 471540013 [](ancestors = 471540013)

|| shoulderNavigationOptionalDisabled
|| shoulderNavigationForcedDisabled)
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,5 +469,85 @@ public void ArrowKeyHierarchicalNavigationTest()

}
}

[TestMethod]
public void VerifyShoulderNavigationEnabledAlwaysIsConsistent()
{
using (var setup = new TestSetupHelper(new[] { "NavigationView Tests", "Top NavigationView Test" }))
{
var navView = FindElement.ByName("NavView");
var shoulderNavigationEnabled = new ComboBox(FindElement.ByName("ShoulderNavigationEnabledSetter"));
var selectionFollowsFocusComboBox = new ComboBox(FindElement.ByName("SelectionFollowsFocusSetter"));

Log.Comment("Set ShoulderNavigation to always");
shoulderNavigationEnabled.SelectItemByName("ShoulderNavigationEnabledAlways");

Log.Comment("Set SelectionFollowsFocus to enabled");
selectionFollowsFocusComboBox.SelectItemByName("SelectionFollowsFocusEnabled");

Log.Comment("Select first item");
FindElement.ByName("HomeItem").Click();
Wait.ForIdle();
Verify.AreEqual("Home", GetSelectedItem());

GamepadHelper.PressButton(navView, GamepadButton.RightShoulder);
Wait.ForIdle();
Verify.AreEqual("Apps", GetSelectedItem());

Log.Comment("Set SelectionFollowsFocus to disabled");
selectionFollowsFocusComboBox.SelectItemByName("SelectionFollowsFocusDisabled");
Wait.ForIdle();

GamepadHelper.PressButton(navView, GamepadButton.RightShoulder);

Wait.ForIdle();
Verify.AreEqual("Games", GetSelectedItem());
}

string GetSelectedItem()
{
return FindElement.ByName("SelectionChangedResult").GetText();
}
}

[TestMethod]
public void VerifyShoulderNavigationEnabledOnlySelectionFollowsFocusIsCorrect()
{
using (var setup = new TestSetupHelper(new[] { "NavigationView Tests", "Top NavigationView Test" }))
{
var navView = FindElement.ByName("NavView");
var shoulderNavigationEnabled = new ComboBox(FindElement.ByName("ShoulderNavigationEnabledSetter"));
var selectionFollowsFocusComboBox = new ComboBox(FindElement.ByName("SelectionFollowsFocusSetter"));

Log.Comment("Set ShoulderNavigation to always");
shoulderNavigationEnabled.SelectItemByName("ShoulderNavigationEnabledWhenSelectionFollowsFocus");

Log.Comment("Set SelectionFollowsFocus to enabled");
selectionFollowsFocusComboBox.SelectItemByName("SelectionFollowsFocusEnabled");

Log.Comment("Select first item");
FindElement.ByName("HomeItem").Click();
Wait.ForIdle();
Verify.AreEqual("Home", GetSelectedItem());

GamepadHelper.PressButton(navView, GamepadButton.RightShoulder);
Wait.ForIdle();
Verify.AreEqual("Apps", GetSelectedItem());

Log.Comment("Set SelectionFollowsFocus to disabled");
selectionFollowsFocusComboBox.SelectItemByName("SelectionFollowsFocusDisabled");
Wait.ForIdle();

GamepadHelper.PressButton(navView, GamepadButton.RightShoulder);

Wait.ForIdle();
Verify.AreEqual("Apps", GetSelectedItem());
}

string GetSelectedItem()
{
return FindElement.ByName("SelectionChangedResult").GetText();
}
}
}
}
43 changes: 31 additions & 12 deletions dev/NavigationView/TestUI/TopMode/NavigationViewTopNavOnlyPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
AccessKey="H">
<muxcontrols:NavigationView.MenuItems>
<muxcontrols:NavigationViewItem x:Name="HomeItem" Content="Home" Icon="Home" />
<muxcontrols:NavigationViewItem x:Name="HomeItem" Content="Home" Icon="Home" AutomationProperties.Name="HomeItem"/>
<muxcontrols:NavigationViewItem x:Name="AppsItem" Icon="Shop" Tag="Apps" /> <!-- AppsItem only have Icon and no content -->
<muxcontrols:NavigationViewItem x:Name="SuppressSelection" Content="SuppressSelection" Icon="Emoji" SelectsOnInvoked="False" />
<muxcontrols:NavigationViewItem x:Name="GamesItem" Content="Games" Icon="Emoji"/>
Expand Down Expand Up @@ -57,18 +57,37 @@
<CheckBox x:Name="BackButtonVisibilityCheckbox" AutomationProperties.Name="BackButtonVisibilityCheckbox" Content="Back Visible" Checked="BackButtonVisibilityCheckbox_Checked" Unchecked="BackButtonVisibilityCheckbox_Unchecked" IsChecked="True" Margin="5"/>
<TextBlock VerticalAlignment="Center">BackButtonHolder width:</TextBlock>
</StackPanel>
<ComboBox x:Name="PaneDisplayModeCombobox"
AutomationProperties.Name="PaneDisplayModeCombobox"
Header="PaneDisplayMode"
SelectionChanged="PaneDisplayModeCombobox_SelectionChanged"
Margin="5">
<ComboBoxItem Content="Auto" Tag="Auto" />
<ComboBoxItem Content="Left" Tag="Left" />
<ComboBoxItem Content="Top" Tag="Top" />
<ComboBoxItem Content="LeftCompact" Tag="LeftCompact" />
<ComboBoxItem Content="LeftMinimal" Tag="LeftMinimal" />
</ComboBox>
<StackPanel Orientation="Horizontal">
<ComboBox x:Name="PaneDisplayModeCombobox"
AutomationProperties.Name="PaneDisplayModeCombobox"
Header="PaneDisplayMode"
SelectionChanged="PaneDisplayModeCombobox_SelectionChanged"
Margin="5">
<ComboBoxItem Content="Auto" Tag="Auto" />
<ComboBoxItem Content="Left" Tag="Left" />
<ComboBoxItem Content="Top" Tag="Top" />
<ComboBoxItem Content="LeftCompact" Tag="LeftCompact" />
<ComboBoxItem Content="LeftMinimal" Tag="LeftMinimal" />
</ComboBox>

<ComboBox x:Name="ShoulderNavigationEnabledSetter" AutomationProperties.Name="ShoulderNavigationEnabledSetter"
SelectionChanged="ShoulderNavigationEnabledSetter_SelectionChanged"
SelectedIndex="0"
Header="ShoulderNavigationEnabled">
<ComboBoxItem AutomationProperties.Name="ShoulderNavigationEnabledAlways">Always</ComboBoxItem>
<ComboBoxItem AutomationProperties.Name="ShoulderNavigationEnabledWhenSelectionFollowsFocus">WhenSelectionFollowsFocus</ComboBoxItem>
<ComboBoxItem AutomationProperties.Name="ShoulderNavigationEnabledNever">Never</ComboBoxItem>
</ComboBox>

<ComboBox x:Name="SelectionFollowsFocusSetter" AutomationProperties.Name="SelectionFollowsFocusSetter"
SelectionChanged="SelectionFollowsFocusSetter_SelectionChanged"
SelectedIndex="0"
Header="SelectionFollowsFocus">
<ComboBoxItem AutomationProperties.Name="SelectionFollowsFocusEnabled">Enabled</ComboBoxItem>
<ComboBoxItem AutomationProperties.Name="SelectionFollowsFocusDisabled">Disabled</ComboBoxItem>
</ComboBox>
</StackPanel>

<StackPanel Orientation="Horizontal">
<Button x:Name="ChangeGamesContent" Click="ChangeGamesContent_Click" Content="ChangeGamesContent" />
<Button x:Name="ClearNavItemContent" Click="ClearNavItemContent_Click" Content="ClearNavItemContent" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,5 +283,37 @@ private void SetInvalidSelectedItem_Click(object sender, RoutedEventArgs e)
{
NavView.SelectedItem = new CheckBox();
}

private void ShoulderNavigationEnabledSetter_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string selectedItem = (e.AddedItems[0] as ComboBoxItem).Content as string;

switch (selectedItem)
{
case "Always":
NavView.ShoulderNavigationEnabled = Microsoft.UI.Xaml.Controls.NavigationViewShoulderNavigationEnabled.Always;
break;
case "WhenSelectionFollowsFocus":
NavView.ShoulderNavigationEnabled = Microsoft.UI.Xaml.Controls.NavigationViewShoulderNavigationEnabled.WhenSelectionFollowsFocus;
break;
case "Never":
NavView.ShoulderNavigationEnabled = Microsoft.UI.Xaml.Controls.NavigationViewShoulderNavigationEnabled.Never;
break;
}
}
private void SelectionFollowsFocusSetter_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string selectedItem = (e.AddedItems[0] as ComboBoxItem).Content as string;

if(selectedItem == "Enabled")
{
NavView.SelectionFollowsFocus = Microsoft.UI.Xaml.Controls.NavigationViewSelectionFollowsFocus.Enabled;
}
else
{
NavView.SelectionFollowsFocus = Microsoft.UI.Xaml.Controls.NavigationViewSelectionFollowsFocus.Disabled;

}
}
}
}