Skip to content

Commit

Permalink
Update HNav based on API Review (#2196)
Browse files Browse the repository at this point in the history
* changed api, added tests, fixed bugs

* fixed test

* addressed comments

* fixed test failure

* fixed test issue (leftclick on wrong point)

Co-authored-by: Keith Mahoney <keith.mahoney@microsoft.com>
  • Loading branch information
ojhad and Keith Mahoney authored Apr 4, 2020
1 parent b62ab97 commit 5ebf958
Show file tree
Hide file tree
Showing 18 changed files with 311 additions and 178 deletions.
4 changes: 2 additions & 2 deletions dev/Generated/NavigationView.properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ void NavigationViewProperties::BackRequested(winrt::event_token const& token)
m_backRequestedEventSource.remove(token);
}

winrt::event_token NavigationViewProperties::Collapsed(winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewCollapsedEventArgs> const& value)
winrt::event_token NavigationViewProperties::Collapsed(winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewItemCollapsedEventArgs> const& value)
{
return m_collapsedEventSource.add(value);
}
Expand All @@ -1168,7 +1168,7 @@ void NavigationViewProperties::DisplayModeChanged(winrt::event_token const& toke
m_displayModeChangedEventSource.remove(token);
}

winrt::event_token NavigationViewProperties::Expanding(winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewExpandingEventArgs> const& value)
winrt::event_token NavigationViewProperties::Expanding(winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewItemExpandingEventArgs> const& value)
{
return m_expandingEventSource.add(value);
}
Expand Down
8 changes: 4 additions & 4 deletions dev/Generated/NavigationView.properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ class NavigationViewProperties

winrt::event_token BackRequested(winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewBackRequestedEventArgs> const& value);
void BackRequested(winrt::event_token const& token);
winrt::event_token Collapsed(winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewCollapsedEventArgs> const& value);
winrt::event_token Collapsed(winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewItemCollapsedEventArgs> const& value);
void Collapsed(winrt::event_token const& token);
winrt::event_token DisplayModeChanged(winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewDisplayModeChangedEventArgs> const& value);
void DisplayModeChanged(winrt::event_token const& token);
winrt::event_token Expanding(winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewExpandingEventArgs> const& value);
winrt::event_token Expanding(winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewItemExpandingEventArgs> const& value);
void Expanding(winrt::event_token const& token);
winrt::event_token ItemInvoked(winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewItemInvokedEventArgs> const& value);
void ItemInvoked(winrt::event_token const& token);
Expand All @@ -208,9 +208,9 @@ class NavigationViewProperties
void SelectionChanged(winrt::event_token const& token);

event_source<winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewBackRequestedEventArgs>> m_backRequestedEventSource;
event_source<winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewCollapsedEventArgs>> m_collapsedEventSource;
event_source<winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewItemCollapsedEventArgs>> m_collapsedEventSource;
event_source<winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewDisplayModeChangedEventArgs>> m_displayModeChangedEventSource;
event_source<winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewExpandingEventArgs>> m_expandingEventSource;
event_source<winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewItemExpandingEventArgs>> m_expandingEventSource;
event_source<winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewItemInvokedEventArgs>> m_itemInvokedEventSource;
event_source<winrt::TypedEventHandler<winrt::NavigationView, winrt::IInspectable>> m_paneClosedEventSource;
event_source<winrt::TypedEventHandler<winrt::NavigationView, winrt::NavigationViewPaneClosingEventArgs>> m_paneClosingEventSource;
Expand Down
53 changes: 10 additions & 43 deletions dev/NavigationView/NavigationView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include "ElementFactoryGetArgs.h"
#include "ElementFactoryRecycleArgs.h"
#include <ItemsRepeater.common.h>
#include "NavigationViewExpandingEventArgs.h"
#include "NavigationViewCollapsedEventArgs.h"
#include "NavigationViewItemExpandingEventArgs.h"
#include "NavigationViewItemCollapsedEventArgs.h"

static constexpr auto c_togglePaneButtonName = L"TogglePaneButton"sv;
static constexpr auto c_paneTitleHolderFrameworkElement = L"PaneTitleHolder"sv;
Expand Down Expand Up @@ -2434,44 +2434,14 @@ winrt::IInspectable NavigationView::MenuItemFromContainer(winrt::DependencyObjec
{
if (container)
{
if (IsTopNavigationView())
if (auto const nvib = container.try_as<winrt::NavigationViewItemBase>())
{
// Search topnav first, if not found, search overflow
if (auto ir = m_topNavRepeater.get())
{
if (auto element = container.try_as<winrt::UIElement>())
{
auto index = ir.GetElementIndex(element);
if (index != -1)
{
return GetItemFromIndex(ir, index);
}
}
}

if (auto ir = m_topNavRepeaterOverflowView.get())
if (auto const parentRepeater = GetParentItemsRepeaterForContainer(nvib))
{
if (auto element = container.try_as<winrt::UIElement>())
auto const containerIndex = parentRepeater.GetElementIndex(nvib);
if (containerIndex >= 0)
{
auto index = ir.GetElementIndex(element);
if (index != -1)
{
return GetItemFromIndex(ir, index);
}
}
}
}
else
{
if (auto ir = m_leftNavRepeater.get())
{
if (auto element = container.try_as<winrt::UIElement>())
{
int index = ir.GetElementIndex(element);
if (index != -1)
{
return GetItemFromIndex(ir, index);
}
return GetItemFromIndex(parentRepeater, containerIndex);
}
}
}
Expand Down Expand Up @@ -2941,10 +2911,7 @@ void NavigationView::SelectOverflowItem(winrt::IInspectable const& item, winrt::
{
if (ip.GetSize() > 1)
{
auto indexOfParentInOverflow = m_topDataProvider.ConvertOriginalIndexToIndex(ip.GetAt(0));
// We want to make sure that container is collapsed before movement
CollapseAllMenuItemsUnderRepeater(m_topNavRepeaterOverflowView.get());
return GetItemFromIndex(m_topNavRepeaterOverflowView.get(), indexOfParentInOverflow);
return GetItemFromIndex(m_topNavRepeaterOverflowView.get(), m_topDataProvider.ConvertOriginalIndexToIndex(ip.GetAt(0)));
}
return item;
}();
Expand Down Expand Up @@ -4840,14 +4807,14 @@ void NavigationView::CollapseAllMenuItemsUnderRepeater(const winrt::ItemsRepeate

void NavigationView::RaiseExpandingEvent(const winrt::NavigationViewItemBase& container)
{
auto eventArgs = winrt::make_self<NavigationViewExpandingEventArgs>();
auto eventArgs = winrt::make_self<NavigationViewItemExpandingEventArgs>(*this);
eventArgs->ExpandingItemContainer(container);
m_expandingEventSource(*this, *eventArgs);
}

void NavigationView::RaiseCollapsedEvent(const winrt::NavigationViewItemBase& container)
{
auto eventArgs = winrt::make_self<NavigationViewCollapsedEventArgs>();
auto eventArgs = winrt::make_self<NavigationViewItemCollapsedEventArgs>(*this);
eventArgs->CollapsedItemContainer(container);
m_collapsedEventSource(*this, *eventArgs);
}
Expand Down
22 changes: 12 additions & 10 deletions dev/NavigationView/NavigationView.idl
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,20 @@ runtimeclass NavigationViewBackRequestedEventArgs
{
}

[WUXC_VERSION_PREVIEW]
[WUXC_VERSION_MUXONLY]
[webhosthidden]
runtimeclass NavigationViewExpandingEventArgs
runtimeclass NavigationViewItemExpandingEventArgs
{
NavigationViewItemBase ExpandingItemContainer { get; };
Object ExpandingItem{ get; };
}

[WUXC_VERSION_PREVIEW]
[WUXC_VERSION_MUXONLY]
[webhosthidden]
runtimeclass NavigationViewCollapsedEventArgs
runtimeclass NavigationViewItemCollapsedEventArgs
{
NavigationViewItemBase CollapsedItemContainer { get; };
Object CollapsedItem{ get; };
}

[WUXC_VERSION_RS5]
Expand Down Expand Up @@ -284,11 +286,11 @@ unsealed runtimeclass NavigationView : Windows.UI.Xaml.Controls.ContentControl
Boolean IsTitleBarAutoPaddingEnabled { get; set; };

static Windows.UI.Xaml.DependencyProperty IsTitleBarAutoPaddingEnabledProperty { get; };

[WUXC_VERSION_PREVIEW]
[WUXC_VERSION_MUXONLY]
{
event Windows.Foundation.TypedEventHandler<NavigationView, NavigationViewExpandingEventArgs> Expanding;
event Windows.Foundation.TypedEventHandler<NavigationView, NavigationViewCollapsedEventArgs> Collapsed;
event Windows.Foundation.TypedEventHandler<NavigationView, NavigationViewItemExpandingEventArgs> Expanding;
event Windows.Foundation.TypedEventHandler<NavigationView, NavigationViewItemCollapsedEventArgs> Collapsed;

void Expand(NavigationViewItem item);
void Collapse(NavigationViewItem item);
Expand All @@ -302,7 +304,7 @@ unsealed runtimeclass NavigationView : Windows.UI.Xaml.Controls.ContentControl
[default_interface]
unsealed runtimeclass NavigationViewItemBase : Windows.UI.Xaml.Controls.ContentControl
{
[WUXC_VERSION_PREVIEW]
[WUXC_VERSION_MUXONLY]
{
Boolean IsSelected{ get; set; };
static Windows.UI.Xaml.DependencyProperty IsSelectedProperty { get; };
Expand Down Expand Up @@ -334,7 +336,7 @@ unsealed runtimeclass NavigationViewItem : NavigationViewItemBase
static Windows.UI.Xaml.DependencyProperty SelectsOnInvokedProperty { get; };
}

[WUXC_VERSION_PREVIEW]
[WUXC_VERSION_MUXONLY]
{
[MUX_DEFAULT_VALUE("false")]
Boolean IsExpanded{ get; set; };
Expand Down
8 changes: 4 additions & 4 deletions dev/NavigationView/NavigationView.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<ClCompile Include="$(MSBuildThisFileDirectory)..\Generated\NavigationViewItemPresenter.properties.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\Generated\NavigationViewTemplateSettings.properties.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)NavigationViewAutomationPeer.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)NavigationViewCollapsedEventArgs.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)NavigationViewExpandingEventArgs.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)NavigationViewItemCollapsedEventArgs.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)NavigationViewItemExpandingEventArgs.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)NavigationViewItemsFactory.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)NavigationViewItemPresenter.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)NavigationViewTemplateSettings.cpp" />
Expand All @@ -42,8 +42,8 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)NavigationViewAutomationPeer.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)NavigationViewCollapsedEventArgs.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)NavigationViewExpandingEventArgs.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)NavigationViewItemCollapsedEventArgs.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)NavigationViewItemExpandingEventArgs.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)NavigationViewHelper.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)NavigationViewItemRevokers.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)NavigationViewItemsFactory.h" />
Expand Down
16 changes: 0 additions & 16 deletions dev/NavigationView/NavigationViewCollapsedEventArgs.cpp

This file was deleted.

18 changes: 0 additions & 18 deletions dev/NavigationView/NavigationViewCollapsedEventArgs.h

This file was deleted.

16 changes: 0 additions & 16 deletions dev/NavigationView/NavigationViewExpandingEventArgs.cpp

This file was deleted.

17 changes: 0 additions & 17 deletions dev/NavigationView/NavigationViewExpandingEventArgs.h

This file was deleted.

37 changes: 37 additions & 0 deletions dev/NavigationView/NavigationViewItemCollapsedEventArgs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#include "pch.h"
#include "common.h"
#include "NavigationViewItemCollapsedEventArgs.h"

NavigationViewItemCollapsedEventArgs::NavigationViewItemCollapsedEventArgs(const winrt::NavigationView& navigationView)
{
m_navigationView.set(navigationView);
}

winrt::NavigationViewItemBase NavigationViewItemCollapsedEventArgs::CollapsedItemContainer()
{
return m_collapsedItemContainer.get();
}

void NavigationViewItemCollapsedEventArgs::CollapsedItemContainer(winrt::NavigationViewItemBase const& value)
{
m_collapsedItemContainer.set(value);
}

winrt::IInspectable NavigationViewItemCollapsedEventArgs::CollapsedItem()
{
if (auto const collapsedItem = m_collapsedItem.get())
{
return collapsedItem;
}

if (auto const nv = m_navigationView.get())
{
m_collapsedItem.set(nv.MenuItemFromContainer(m_collapsedItemContainer.get()));
return m_collapsedItem.get();
}

return nullptr;
}
23 changes: 23 additions & 0 deletions dev/NavigationView/NavigationViewItemCollapsedEventArgs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#pragma once

#include "NavigationViewItemCollapsedEventArgs.g.h"

class NavigationViewItemCollapsedEventArgs :
public ReferenceTracker<NavigationViewItemCollapsedEventArgs, winrt::implementation::NavigationViewItemCollapsedEventArgsT, winrt::composing, winrt::composable>
{
public:
NavigationViewItemCollapsedEventArgs(const winrt::NavigationView& navigationView);

winrt::NavigationViewItemBase CollapsedItemContainer();
void CollapsedItemContainer(winrt::NavigationViewItemBase const& value);

winrt::IInspectable CollapsedItem();

private:
tracker_ref<winrt::NavigationViewItemBase> m_collapsedItemContainer{ this };
tracker_ref<winrt::IInspectable> m_collapsedItem{ this };
tracker_ref<winrt::NavigationView> m_navigationView{ this };
};
37 changes: 37 additions & 0 deletions dev/NavigationView/NavigationViewItemExpandingEventArgs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#include "pch.h"
#include "common.h"
#include "NavigationViewItemExpandingEventArgs.h"

NavigationViewItemExpandingEventArgs::NavigationViewItemExpandingEventArgs(const winrt::NavigationView& navigationView)
{
m_navigationView.set(navigationView);
}

winrt::NavigationViewItemBase NavigationViewItemExpandingEventArgs::ExpandingItemContainer()
{
return m_expandingItemContainer.get();
}

void NavigationViewItemExpandingEventArgs::ExpandingItemContainer(winrt::NavigationViewItemBase const& value)
{
m_expandingItemContainer.set(value);
}

winrt::IInspectable NavigationViewItemExpandingEventArgs::ExpandingItem()
{
if (auto const expandingItem = m_expandingItem.get())
{
return expandingItem;
}

if (auto const nv = m_navigationView.get())
{
m_expandingItem.set(nv.MenuItemFromContainer(m_expandingItemContainer.get()));
return m_expandingItem.get();
}

return nullptr;
}
Loading

0 comments on commit 5ebf958

Please sign in to comment.