Skip to content

Clicking on the same element in the hamburger view should re-open that view, like the menu items do#447

Merged
danbelcher-MSFT merged 4 commits intomicrosoft:masterfrom
AbduAmeen1:hamburger_view_should_re-open_that_view_437
Apr 20, 2019
Merged

Clicking on the same element in the hamburger view should re-open that view, like the menu items do#447
danbelcher-MSFT merged 4 commits intomicrosoft:masterfrom
AbduAmeen1:hamburger_view_should_re-open_that_view_437

Conversation

@AbduAmeen1
Copy link
Copy Markdown
Contributor

@AbduAmeen1 AbduAmeen1 commented Apr 8, 2019

Fixes #437.

Clicking on the same element in the hamburger view should re-open that view, like the menu items do

Description of the changes:

-Fixed the bug that was listed

How changes were validated:

-manual

… should re-open that view, like the menu items do #437
@msftclas
Copy link
Copy Markdown

msftclas commented Apr 8, 2019

CLA assistant check
All CLA requirements met.

NarratorNotifier->Announce(announcement);
}

void MainPage::OnNavItemInvoked(_In_ Microsoft::UI::Xaml::Controls::NavigationView^ sender, _In_ Microsoft::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs^ e)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you remove Microsoft::UI::Xaml::Controls::?
(I would like Visual Studio to automatically check if using namespace Microsoft::UI::Xaml::Controls exists, but unfortunately, it's not the case :( )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was not able to remove Microsoft::UI::Xaml::Controls.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Because the namespace is already declared , you can write:

void MainPage::OnNavItemInvoked(_In_ NavigationView^ sender, _In_ NavigationViewItemInvokedEventArgs^ e)

Copy link
Copy Markdown
Contributor Author

@AbduAmeen1 AbduAmeen1 Apr 10, 2019

Choose a reason for hiding this comment

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

I tried that. For some reason I got errors.
Only changed the cpp parameters: Severity Code Description Project File Line Suppression State Error C2511 'void CalculatorApp::MainPage::OnNavItemInvoked(Windows::UI::Xaml::Controls::NavigationView ^,Windows::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs ^)': overloaded member function not found in 'CalculatorApp::MainPage' Calculator c:\users\kids\source\repos\calculator\src\calculator\views\mainpage.xaml.cpp 606 Error (active) E0147 declaration is incompatible with "void CalculatorApp::MainPage::OnNavItemInvoked(Microsoft::UI::Xaml::Controls::NavigationView ^sender, Microsoft::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs ^e)" (declared at line 55 of "C:\Users\Kids\source\repos\calculator\src\Calculator\Views\MainPage.xaml.h") Calculator C:\Users\Kids\source\repos\calculator\src\Calculator\Views\MainPage.xaml.cpp 605

Changed the header file and cpp file to void MainPage::OnNavItemInvoked(_In_ NavigationView^ sender, _In_ NavigationViewItemInvokedEventArgs^ e)

Here are the errors:Severity Code Description Project File Line Suppression State Error (active) E0147 declaration is incompatible with "void CalculatorApp::MainPage::OnNavItemInvoked(<error-type> ^sender, <error-type> ^e)" (declared at line 55 of "C:\Users\Kids\source\repos\calculator\src\Calculator\Views\MainPage.xaml.h") Calculator C:\Users\Kids\source\repos\calculator\src\Calculator\Views\MainPage.xaml.cpp 605 Error (active) E0020 identifier "NavigationView" is undefined Calculator C:\Users\Kids\source\repos\calculator\src\Calculator\Views\MainPage.xaml.h 55 Error (active) E0020 identifier "NavigationViewItemInvokedEventArgs" is undefined Calculator C:\Users\Kids\source\repos\calculator\src\Calculator\Views\MainPage.xaml.h 55 Error C2061 syntax error: identifier 'NavigationView' (compiling source file App.xaml.cpp) Calculator c:\users\kids\source\repos\calculator\src\calculator\views\mainpage.xaml.h 55 Error C2061 syntax error: identifier 'NavigationView' (compiling source file Views\MainPage.xaml.cpp) Calculator c:\users\kids\source\repos\calculator\src\calculator\views\mainpage.xaml.h 55 Error C2511 'void CalculatorApp::MainPage::OnNavItemInvoked(Windows::UI::Xaml::Controls::NavigationView ^,Windows::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs ^)': overloaded member function not found in 'CalculatorApp::MainPage' Calculator c:\users\kids\source\repos\calculator\src\calculator\views\mainpage.xaml.cpp 606

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
void MainPage::OnNavItemInvoked(_In_ Microsoft::UI::Xaml::Controls::NavigationView^ sender, _In_ Microsoft::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs^ e)
void MainPage::OnNavItemInvoked(MUXC::NavigationView^ /*sender*/, _In_ MUXC::NavigationViewItemInvokedEventArgs^ e)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actually, it was intentional. _In_opt_ describes a parameter that may or may not have a value for use by the function. We are explicitly discarding this parameter so I figured there's no point to decorating it with SAL (imo). _In_opt_ doesn't seem to be the right fit and there isn't any other SAL equivalent.

Copy link
Copy Markdown
Contributor

@rudyhuyn rudyhuyn Apr 17, 2019

Choose a reason for hiding this comment

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

This is a (very) tricky question and open to debate.

Imo, I don't think it's a best practice to comment/discard a parameter in a function declaration (but it's totally fine with function definition), it makes the development harder when using IntelliSense (because the parameter is not named):

image

and creates some issues with virtual methods, when the method is overridden, the developer have no idea if the parameter is In, Out, In/Out, optional, etc...

class TestBase
{
public:
    virtual int TestFunc(int * /*test*/, _In_ int * test2) noexcept;
};

class Test: public TestBase
{
public:
    virtual int TestFunc(_InOut_ int * test, _In_ int * test2) noexcept;
};

in this case, a developer will have no idea if the first parameter is in/out/inout when using a TestBase* object.

For these 2 reasons (and probably more), I think we should not comment/discard a argument in a function declaration, so we need to use SAL for this parameter in the declaration.

Visual Studio forcing SAL to be in the function definition when set in the declaration, we are also forced to do it in the function definition too.

So in our case:

.h

void OnNavItemInvoked(_In_opt_ Microsoft::UI::Xaml::Controls::NavigationView^ sender...)

.cpp

void MainPage::OnNavItemInvoked(_In_opt_ NavigationView^ /*sender.*/..)

 

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

On the other hand, if we're consistent about naming parameters that are used and not naming parameters that are unused, then seeing a function with an unnamed parameter is a clear indication that the parameter is not used by that function. In this case, I can simply supply nullptr. Given that SAL describes how a parameter is used, for an unnamed parameter there would be no need for SAL.

This doesn't feel like an appropriate place for a long discussion of the semantics (I can see arguments for both sides). In this case, let's let @cheezwhines resolve as they'd like and we revisit this elsewhere, if we have need.

Copy link
Copy Markdown
Contributor

@rudyhuyn rudyhuyn Apr 18, 2019

Choose a reason for hiding this comment

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

then seeing a function with an unnamed parameter is a clear indication that the parameter is not used by that function.

This isn't true with virtual methods, a unused parameter in a base class can be in reality used by a function overriding it in a child class.

class WaterParkBase
{
public:
    virtual int GetPrice(_In_ int * numberAdults, int * /*numberKids*/) noexcept
    {
          m_price = *numberAdults * 50;
    }
...
};

class SFWaterPark: public c
{
public:
    virtual int GetPrice(_In_ int * numberAdults, _In_ int * numberKids) noexcept
    {
          m_price = *numberAdults * 35 + *numberKids *10;
    }
};

in this case:

WaterParkBase * t = new SFWaterPark();
t->GetPrice(a, b);

Intellisense will show GetPrice(int * numberAdults, int *) even if numberKids will be used.

But it's off topic, let's chat about it somewhere else (if only GitHub had PM...)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey Rudy, I hear your perspective and I think I agree we should be consistent in naming parameters for declarations but remove them for definitions. For now I'm going to take the change as is, to prevent more work for the author. We'll endeavour to be consistent about this rule for future changes. Thanks for sharing the examples!


void MainPage::OnNavItemInvoked(_In_ Microsoft::UI::Xaml::Controls::NavigationView^ sender, _In_ Microsoft::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs^ e)
{
auto item = dynamic_cast<MUXC::NavigationViewItem^>(e->InvokedItemContainer);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it's safe to simplify this code and always call NavView->IsPaneOpen = false; without checking the value of Mode.

What's your opinion?

Copy link
Copy Markdown
Contributor Author

@AbduAmeen1 AbduAmeen1 Apr 9, 2019

Choose a reason for hiding this comment

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

I agree with this. Doesn't seem like it would affect the sidebar in any harmful way. I tested without the checking the value of Mode and it works the same.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great! The less we use DataContext in the code, the better!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agree with @rudyhuyn here. I made the change locally and I don't see any difference in behavior.

@rudyhuyn
Copy link
Copy Markdown
Contributor

rudyhuyn commented Apr 9, 2019

Congratulation on your first PR!

The PR description has some formatting issues, here is the fixed version:

## Fixes #437
Clicking on the same element in the hamburger view should re-open that view, like the menu items do. 
### Description of the changes:
-Fixed the bug that was listed 
### How changes were validated:
-manual

I also let some comments, don't hesitate to comment back if you have questions/feedback!

Good work!

@HowardWolosky HowardWolosky changed the title Fix to this issue: Clicking on the same element in the hamburger view should re-open that view, like the menu items do #437 Clicking on the same element in the hamburger view should re-open that view, like the menu items do Apr 12, 2019
@danbelcher-MSFT
Copy link
Copy Markdown

danbelcher-MSFT commented Apr 17, 2019

I think I'm considering this a bug in the NavigationView control. We can take the fix here and I'll pass on the bug to the controls team. Tracked internally with: 21232112

Copy link
Copy Markdown

@danbelcher-MSFT danbelcher-MSFT left a comment

Choose a reason for hiding this comment

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

Hey @cheezwhines, just a few small updates and we'll get this change merged. As I said on the main PR discussion area, right now I'm considering this behavior a bug with the NavigationView control and I've passed it on to the controls team. Thanks for the change!

NarratorNotifier->Announce(announcement);
}

void MainPage::OnNavItemInvoked(_In_ Microsoft::UI::Xaml::Controls::NavigationView^ sender, _In_ Microsoft::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs^ e)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
void MainPage::OnNavItemInvoked(_In_ Microsoft::UI::Xaml::Controls::NavigationView^ sender, _In_ Microsoft::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs^ e)
void MainPage::OnNavItemInvoked(MUXC::NavigationView^ /*sender*/, _In_ MUXC::NavigationViewItemInvokedEventArgs^ e)


void MainPage::OnNavItemInvoked(_In_ Microsoft::UI::Xaml::Controls::NavigationView^ sender, _In_ Microsoft::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs^ e)
{
auto item = dynamic_cast<MUXC::NavigationViewItem^>(e->InvokedItemContainer);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agree with @rudyhuyn here. I made the change locally and I don't see any difference in behavior.

void OnNavPaneOpened(_In_ Microsoft::UI::Xaml::Controls::NavigationView^ sender, _In_ Platform::Object^ args);
void OnNavPaneClosed(_In_ Microsoft::UI::Xaml::Controls::NavigationView^ sender, _In_ Platform::Object^ args);
void OnNavSelectionChanged(_In_ Platform::Object^ sender, _In_ Microsoft::UI::Xaml::Controls::NavigationViewSelectionChangedEventArgs^ e);
void OnNavItemInvoked(_In_ Microsoft::UI::Xaml::Controls::NavigationView^ sender, _In_ Microsoft::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs^ e);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
void OnNavItemInvoked(_In_ Microsoft::UI::Xaml::Controls::NavigationView^ sender, _In_ Microsoft::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs^ e);
void OnNavItemInvoked(Microsoft::UI::Xaml::Controls::NavigationView^ /*sender*/, _In_ Microsoft::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs^ e);

void OnNavPaneClosed(_In_ Microsoft::UI::Xaml::Controls::NavigationView^ sender, _In_ Platform::Object^ args);
void OnNavSelectionChanged(_In_ Platform::Object^ sender, _In_ Microsoft::UI::Xaml::Controls::NavigationViewSelectionChangedEventArgs^ e);
void OnNavItemInvoked(_In_ Microsoft::UI::Xaml::Controls::NavigationView^ sender, _In_ Microsoft::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs^ e);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: please remove this extra whitespace. We'll keep just one blank line separating blocks of functions.

@danbelcher-MSFT
Copy link
Copy Markdown

Controls bug is tracked by microsoft/microsoft-ui-xaml#573

@danbelcher-MSFT
Copy link
Copy Markdown

Hey @cheezwhines, can you address @rudyhuyn's simplification he suggested here? #447 (comment)

Copy link
Copy Markdown

@danbelcher-MSFT danbelcher-MSFT left a comment

Choose a reason for hiding this comment

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

Thanks for the fix, @cheezwhines!

@danbelcher-MSFT danbelcher-MSFT merged commit fab2119 into microsoft:master Apr 20, 2019
@AbduAmeen1 AbduAmeen1 deleted the hamburger_view_should_re-open_that_view_437 branch April 20, 2019 13:01
EriWong pushed a commit to EriWong/calculator that referenced this pull request Jun 5, 2019
…t view, like the menu items do (microsoft#447)

Fixes microsoft#437.
Clicking on the same element in the hamburger view should re-open that view, like the menu items do

Description of the changes:
-Fixed the bug that was listed

How changes were validated:
-manual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clicking on the same element in the hamburger view should re-open that view, like the menu items do

6 participants