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 content clipping regression #2717

Conversation

Felix-Dev
Copy link
Contributor

Description

This PR fixes a NavigationView content clipping regression in closed compact mode introduced with WinUI 2.4.

Motivation and Context

Fixes #2541.

How Has This Been Tested?

Added interaction test + visually

Screenshots:

Current cutoff text in closed compact mode excluding this PR:
image

WinUI 2.3 closed compact look restored with this PR:
image
(The cutoff NavigationViewItem content is "Menu Item".)

@msft-github-bot msft-github-bot added the needs-triage Issue needs to be triaged by the area owners label Jun 19, 2020
@StephenLPeters
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@StephenLPeters
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Felix-Dev
Copy link
Contributor Author

Felix-Dev commented Jun 23, 2020

Hmmm...the two failing tests in Azure Pipelines work fine for me locally and looking at their test code I also can't see anything which would make them fail based on my additions in this PR. I'm also up-to-date with the master branch except for PR c5fa8a6 which does not touch the NavigationView. The two failing tests in question failed already a few days ago too when we first ran Azure Pipelines on this PR.

Thoughts?

@ranjeshj ranjeshj added area-NavigationView NavView control needs-cherrypicktorelease PR tagged for cherry-pick to the current release branch (but not yet picked) team-Controls Issue for the Controls team and removed needs-triage Issue needs to be triaged by the area owners labels Jun 24, 2020
@StephenLPeters
Copy link
Contributor

The tests are only failing on RS2 with the following errors:
NavigationViewTests.SelectionTests.SelectionFollowFocusTest:
[Error]: IsTrue [File d:\a\1\s\dev\NavigationView\NavigationView_InteractionTests\SelectionTests.cs Line: 141]

000001_Screenshot (41)

NavigationViewTests.SelectionTests.MenuItemAutomationSelectionTest:
[Error]: IsTrue [File d:\a\1\s\dev\NavigationView\NavigationView_InteractionTests\SelectionTests.cs Line: 178]

000016_Screenshot (1)

@StephenLPeters
Copy link
Contributor

Sorry this info isn't available to you, the Azure Dev Ops team says they are looking at the issue.

@StephenLPeters
Copy link
Contributor

@Felix-Dev the Azure Dev Ops issue has been resolved, you should now be able to see the test failures yourself.

@Felix-Dev
Copy link
Contributor Author

@StephenLPeters I am looking at the tests in question and I cannot notice anything here why my additional test code added to the test UI would cause these tests to fail.

NavigationViewTests.SelectionTests.SelectionFollowFocusTest:
[Error]: IsTrue [File d:\a\1\s\dev\NavigationView\NavigationView_InteractionTests\SelectionTests.cs Line: 141]

I took a look at the line and this is the failing code:

The error above says "IsTrue". How am I supposed to read that? Does it mean Verify.IsTrue(secondItem.HasKeyboardFocus); is actually false, thus secondItem.HasKeyboardFocus is false? Otherwise, "IsTrue" here is the expected value and shouldn't cause the test to fail.

And again, I don't have an idea right now why my addition of another NavigationViewItem as the new last one of the NavigationViewItems would cause this tests to fail here. The "Apps" and "Games" NavigationViewItems are untouched by me in this PR.

Similar story as for the other failing test.

I suppose I could cut out my added test code and add it to one of the other many NavigationView test pages in the MUXControlsTestApp, though that would just be me randomly trying to fix failing tests I don't know why they are failing in the first place.

How should we proceed here then?

@StephenLPeters
Copy link
Contributor

The test output indicates the verify that failed so in this case it indicates that the Verify.IsTrue(secondItem.HasKeyboardFocus) failed indicating secondItem.HasKeyboardFocus is false. These tests are only failing on RS2, so make sense that they don't fail locally. I haven't had time to look at why that might be the case.

@Felix-Dev
Copy link
Contributor Author

Felix-Dev commented Jul 1, 2020

Seems like we have to wait for someone form the team then to look at the test failures on RS2 more closely as I won't be able to set up an environment here where I could inspect those myself.

@StephenLPeters
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@StephenLPeters
Copy link
Contributor

@Felix-Dev are you still blocked here?

@Felix-Dev
Copy link
Contributor Author

@StephenLPeters I will hopefully be able to take a final look at this today and move the failing tests to another existing test page for now. I think I will go with the existing "NavigationVew Regression Test" test page as that page will do it (instead of setting up a new test page). Does that sound reasonable to you?

@StephenLPeters
Copy link
Contributor

@StephenLPeters I will hopefully be able to take a final look at this today and move the failing tests to another existing test page for now. I think I will go with the existing "NavigationVew Regression Test" test page as that page will do it (instead of setting up a new test page). Does that sound reasonable to you?

Awesome! that does sound reasonable.

@Felix-Dev
Copy link
Contributor Author

Merged with master.

@StephenLPeters
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@StephenLPeters
Copy link
Contributor

@Felix-Dev the change to use lab test frame dimensions locally just got checked in. Could you merge in master and try running the failing tests again? I'm hoping that accounts for the difference in environments that is causing the lab failures

@Felix-Dev
Copy link
Contributor Author

Felix-Dev commented Sep 2, 2020

@StephenLPeters Merged with master.

Unfortunately, I couldn't find all of the failing tests again (previous Azure Pipelines build failures say they are no longer available), but thatnks to the comversattion here, at least one failing test in the pipeline but succeeding for me locally was SettingsCanBeUnselected(). After merging with master, I can now now verify that it fails locally for me too.

It just fails (and presumably all the other failing tests) because of my addition of two additional NavigationViewItems on the used test page here. If I remove these two items again, SettingsCanBeUnselected() succeeds as expected.

Honestly, since the addition of two more NavigationViewItems to the main NavigationView test page (NavigationViewTestPage) appears to create so much "pain" unrelated specifically to this issue, I am considering moving my added interaction test (which also checks the ContentPresenter margin of child menu item) to a different test page, untouched by the majority of the tests. Not yet sure which page (I'll have to take a closer look).

@StephenLPeters
Copy link
Contributor

Does it fail because the test is trying to click a button that is off screen? can we just call invoke instead, or if clicking is important call BringIntoView first?

@Felix-Dev
Copy link
Contributor Author

Yep, the unrelated test fails because the addition of two more NavigationViewItems pushed the settings button off the screen (prior to the CI frame PR, the settings button still fit into the screen area so it ran fine for me). I can take a look at your suggestion here.

@Felix-Dev
Copy link
Contributor Author

@StephenLPeters
The culprit in the failing SettingsCanBeUnselected() test is the Settings NavigationViewItem:

I can not call Invoke() instead of Click() on it because the InvokePattern is not implemented for the NavigationViewItem.

I did not find a BringIntoView() method but there is a UIElement.StartBringIntoView() method. That is asynchronous though so I looked for an alternative here to scroll the Settings NavigationViewItem into view. My idea was to grab the ScrollViewer responsible for scrolling the NavigationViewItems and tell it to scroll to the bottom - thus scrolling Settings NavigationViewItem into view:

private void BringSettingsIntoViewButton_Click(object sender, RoutedEventArgs e)
{
    if (VisualTreeUtils.FindElementOfTypeInSubtree<ItemsRepeaterScrollHost>(NavView) is ItemsRepeaterScrollHost scrollHost)
    {
        scrollHost.ScrollViewer.ChangeView(null, double.MaxValue, null);
    }
}

Unfortunately, while the ChangeView() method is indeed executed with each button press here, no scrolling happens:
scrollviewer-not-scrolling

Am I missing something here?

@StephenLPeters
Copy link
Contributor

@Felix-Dev
Copy link
Contributor Author

Felix-Dev commented Sep 3, 2020

@StephenLPeters Unfortunately, that method is currently not available in UWP.

@marcelwgn
Copy link
Contributor

It is available in UWP: https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.uielement.startbringintoview?view=winrt-19041

Also looks like there are merge conflicts you need to resolve @Felix-Dev .

@Felix-Dev
Copy link
Contributor Author

Felix-Dev commented Sep 3, 2020

StartBringIntoView() != BringIntoView() (it's asynchronous). That threw me a loop yesterday night but it seems that adding a Wait.ForIdle() call in the interaction test is enough to have the test reliably scroll Settings into view.

@marcelwgn
Copy link
Contributor

Beside the asynchronity BringIntoView and StartBringIntoView should be the same though, and Wait.ForIdle shouldn't care whether it's async or not. But if it works now, that's great.

@Felix-Dev
Copy link
Contributor Author

@StephenLPeters Merged with master and fixed failing SettingsCanBeUnselected() interaction test.

Will look into the other failing tests the pipeline should throw out.

@StephenLPeters
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Felix-Dev
Copy link
Contributor Author

@StephenLPeters Fixed remaining failing interaction tests.

@StephenLPeters
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@StephenLPeters StephenLPeters merged commit dc08d9b into microsoft:master Sep 9, 2020
Kinnara added a commit to Kinnara/ModernWpf that referenced this pull request Sep 13, 2020
@Felix-Dev Felix-Dev deleted the user/Felix-Dev/navview-contentcutoff-regressionfix branch November 3, 2020 18:50
@ranjeshj ranjeshj removed the needs-cherrypicktorelease PR tagged for cherry-pick to the current release branch (but not yet picked) label Aug 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NavigationView NavView control team-Controls Issue for the Controls team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NavigationViewItem content clipping regression in 2.4.x
5 participants