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 bug where changing the DisplayMode would raise SelectionChanged with SelectedItem as null #1395

Conversation

marcelwgn
Copy link
Collaborator

@marcelwgn marcelwgn commented Oct 1, 2019

Description

Changed the parameter passed to SetSelectedItemAndExpectItemInvokeWhenSelectionChangedIfNotInvokedFromAPI from nullptr to the settings item instead.

Changed code where we update the settings item to set the m_shouldIgnoreNextSelectionChange flag to true, so SelectionChanged ignores that selection change.

Motivation and Context

Fixes #148

How Has This Been Tested?

Added new interaction test, which tests whether the item passed from SelectionChanged event is null or not.

Screenshots (if appropriate):

@marcelwgn marcelwgn requested a review from a team as a code owner October 1, 2019 10:36
@jevansaks
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@licanhua
Copy link
Contributor

licanhua commented Oct 9, 2019

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@StephenLPeters
Copy link
Contributor

StephenLPeters commented Oct 10, 2019

The failing tests looks like a legitimate failure. @chingucoding and @licanhua FYI.

@licanhua
Copy link
Contributor

From last build, Look like InteractionTests.NavigationViewTests.EnsureLeftSettingsRetainsFocusAfterOrientationChanges is impacted by this PR.

@marcelwgn
Copy link
Collaborator Author

From last build, Look like InteractionTests.NavigationViewTests.EnsureLeftSettingsRetainsFocusAfterOrientationChanges is impacted by this PR.

I tried reproducing the problem locally. but the test is always succeeding. I have also tried setting the MaxTestedVersion to different Windows versions but the test is still not failing. Am I missing something?

@StephenLPeters
Copy link
Contributor

From last build, Look like InteractionTests.NavigationViewTests.EnsureLeftSettingsRetainsFocusAfterOrientationChanges is impacted by this PR.

I tried reproducing the problem locally. but the test is always succeeding. I have also tried setting the MaxTestedVersion to different Windows versions but the test is still not failing. Am I missing something?

What is even stranger, the test expects the SettingsSelectionState text box's content to be 'True' but is finding 'False' however when you look at the screen shot at the time of the test it is displaying true.... I've run the test locally and stepped through the test manually and I can't find anything wrong, @licanhua @ojhad do either of you have an idea whats going on?

@licanhua
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@licanhua
Copy link
Contributor

@chingucoding , I don't know if it's merging issue. Could you please sync with master first, then create a new PR by merging the code with master to see what will happen?

From the screenshot, it should pass sometime but it's not. also I didn't see Line: 3861 match with your code.

Verify the left settings item is selected.
Error: Verify: AreEqual(False, True) [File: d:\a\1\s\dev\NavigationView\NavigationView_InteractionTests\NavigationViewTests.cs, Function: EnsureLeftSettingsRetainsFocusAfterOrientationChanges, Line: 3861]

@marcelwgn marcelwgn force-pushed the navview-displaymodechange-event-bug branch from 1a28c90 to d9d3bcc Compare October 15, 2019 21:07
@marcelwgn
Copy link
Collaborator Author

I think I correctly synced my branch with microsoft:master now. Should we try again now? 😅

@licanhua
Copy link
Contributor

just wait for the test report.
I already queued it on another branch https://dev.azure.com/ms/microsoft-ui-xaml/_build/results?buildId=42611

@licanhua
Copy link
Contributor

@chingucoding . I can repro the problem by manual step.

  1. In Settings|Display, disable animation.
    image

  2. Launch the test app, then resize it to make overflow for topnav and see scrollbar for left nav
    image

image

  1. Kill the app, relaunch it. then click NavigationView, and select NavigationViewTest, then click "Flip Orientation', then click 'Setting' on topnav, then click 'Flip' again, then click 'ReadSettingsSelected', you can see it's false.

@marcelwgn
Copy link
Collaborator Author

@chingucoding . I can repro the problem by manual step.

  1. In Settings|Display, disable animation.
    image
  2. Launch the test app, then resize it to make overflow for topnav and see scrollbar for left nav
    image

image

  1. Kill the app, relaunch it. then click NavigationView, and select NavigationViewTest, then click "Flip Orientation', then click 'Setting' on topnav, then click 'Flip' again, then click 'ReadSettingsSelected', you can see it's false.

I was able to reproduce the issue now with the steps you provided. I think this is something about not correctly animating selection changed. While testing this I also noticed with animations disabled, changing the selected item in DisplayMode = Top does not correctly change the "underline" of the items.

I fixed that with the latest commit.

And thank you so much @licanhua for finding a way to reproduce this locally! 😅


// Animate to be sure the selected item is visually higlighted!
// See #1395 for additional context
if (oldItem != newItem)
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't do it here. Some feature like NavigationRecommendedTransitionDirection, SelectionSuppressed and topnav animation may be broken which is implemented in ChangeSelection.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm I see. So should we set m_shouldRaiseInvokeItemInSelectionChange to false when before we call ChangeSelection in OnSelectedItemPropertyChanged? Or would it be better to move lines 1943/1944 inside CreateAndHookEventsToSettings ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have good suggestion on it. It's possible that add a flag like 'Hi, I'm switching from topnav to leftnav, please don't raise selection change event for settings'.
Most likely it's not a easy change because we don't have too much automation on this part and you have to manually verify all kind of scenarios.
I would like @YuliKl to re-evaluate the impact of the bug.

Copy link

Choose a reason for hiding this comment

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

I admit that I'm not quite following the code intricacies within NavigationView and dont' have a good grasp on what's complicating this fix. I do know there's a real problem outlined in #148 that was encountered by a customer (although at this point, I can't locate any record of who originally found this bug).

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be stalling out. @ojhad @licanhua @YuliKl @chingucoding any idea what the next steps are?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the least we should do, is to ensure that the selected item that gets passed to the event-handler/event-args is not null.

However not raising the event in that case seems to be quite difficult, as we apparently break animations with that. The question is how common it is for developers to change the orientation of the NavigationView during runtime. If this is an edge case that is not very common, we should maybe not try to prevent the raising of that event. After all, catching that "bug" is something that is definitely achievable.

@StephenLPeters
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ojhad
Copy link
Contributor

ojhad commented Oct 30, 2019

Hey @chingucoding
Thanks for your work on this fix! I am currently working on a refactor of NavigationView where the internal ListViews will be replaced with ItemsRepeater. There is a chance that this bug might become a non-issue as a result of the refactor. I think it makes most sense to hold off merging this fix until the refactor is in. We can revisit this if it is still an issue. I will close this PR for now while we wait and ping you once the refactor is done.

@ojhad ojhad closed this Oct 30, 2019
@marcelwgn
Copy link
Collaborator Author

Hey @chingucoding
Thanks for your work on this fix! I am currently working on a refactor of NavigationView where the internal ListViews will be replaced with ItemsRepeater. There is a chance that this bug might become a non-issue as a result of the refactor. I think it makes most sense to hold off merging this fix until the refactor is in. We can revisit this if it is still an issue. I will close this PR for now while we wait and ping you once the refactor is done.

Thanks for the update on that @ojhad. Looking forward to that! I assume it is better to not work on the NavigationView until the refactor is finished?

@ojhad
Copy link
Contributor

ojhad commented Oct 31, 2019

Hey @chingucoding
Thanks for your work on this fix! I am currently working on a refactor of NavigationView where the internal ListViews will be replaced with ItemsRepeater. There is a chance that this bug might become a non-issue as a result of the refactor. I think it makes most sense to hold off merging this fix until the refactor is in. We can revisit this if it is still an issue. I will close this PR for now while we wait and ping you once the refactor is done.

Thanks for the update on that @ojhad. Looking forward to that! I assume it is better to not work on the NavigationView until the refactor is finished?

I would say contributing bug fixes to the control should still be fine! I decided to defer this fix primarily because of the concerns raised in the discussion above and the difficulty of resolving them.

@ojhad
Copy link
Contributor

ojhad commented Feb 6, 2020

@chingucoding This can be revisited now that the refactor is in. It is still an issue, however now there is less complication regarding the selection changes. Let me know if there is anything I can help with!

@marcelwgn
Copy link
Collaborator Author

@chingucoding This can be revisited now that the refactor is in. It is still an issue, however now there is less complication regarding the selection changes. Let me know if there is anything I can help with!

@ojhad Thanks for the notice!
I will look into this once as soon as I have time.

marcelwgn added a commit to marcelwgn/microsoft-ui-xaml that referenced this pull request Feb 8, 2020
ranjeshj pushed a commit that referenced this pull request Mar 9, 2020
… change (#1956)

* Transfer changes from #1395

* Add appropriate check for shoudIgnoreNextSelectionChange

* CR feedback

* Add check for settings item

* Switch to custom settings only flag for selection change suppresion

* Fix CI failure
@marcelwgn marcelwgn deleted the navview-displaymodechange-event-bug branch April 16, 2021 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changing NavigationView's PaneDisplayMode also raises SelectionChanged event
6 participants