-
Notifications
You must be signed in to change notification settings - Fork 698
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
Layout Cycle Crash + Misc Fixes for NavigationView #5084
Changes from 16 commits
275cdc9
e36718c
06f90d7
18b686a
026ab45
1ee640f
4c7ed20
c0ae763
24a3ad8
24c4ed4
4b91172
74d03fe
642124d
c3c4811
db5b373
81ab023
2b6a3ea
35bd4b0
34a930a
30a4f0c
c273364
c89a7a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,7 @@ static constexpr auto c_paneHeaderContentBorderRow = L"PaneHeaderContentBorderRo | |
|
||
static constexpr auto c_separatorVisibleStateName = L"SeparatorVisible"; | ||
static constexpr auto c_separatorCollapsedStateName = L"SeparatorCollapsed"; | ||
static constexpr auto c_visualItemsSeparator = L"VisualItemsSeparator"sv; | ||
|
||
static constexpr int c_backButtonHeight = 40; | ||
static constexpr int c_backButtonWidth = 40; | ||
|
@@ -93,7 +94,6 @@ static constexpr int c_paneToggleButtonWidth = 40; | |
static constexpr int c_toggleButtonHeightWhenShouldPreserveNavigationViewRS3Behavior = 56; | ||
static constexpr int c_backButtonRowDefinition = 1; | ||
static constexpr float c_paneElevationTranslationZ = 32; | ||
static constexpr int c_paneItemsSeparatorHeight = 9; | ||
|
||
static constexpr int c_mainMenuBlockIndex = 0; | ||
static constexpr int c_footerMenuBlockIndex = 1; | ||
|
@@ -658,6 +658,8 @@ void NavigationView::OnApplyTemplate() | |
m_itemsContainerRow.set(GetTemplateChildT<winrt::RowDefinition>(c_itemsContainerRow, controlProtected)); | ||
m_menuItemsScrollViewer.set(GetTemplateChildT<winrt::FrameworkElement>(c_menuItemsScrollViewer, controlProtected)); | ||
m_footerItemsScrollViewer.set(GetTemplateChildT<winrt::FrameworkElement>(c_footerItemsScrollViewer, controlProtected)); | ||
m_visualItemsSeparator.set(GetTemplateChildT<winrt::NavigationViewItemSeparator>(c_visualItemsSeparator, controlProtected)); | ||
|
||
|
||
m_itemsContainerSizeChangedRevoker.revoke(); | ||
if (const auto itemsContainer = GetTemplateChildT<winrt::FrameworkElement>(c_itemsContainer, controlProtected)) | ||
|
@@ -1491,27 +1493,7 @@ void NavigationView::UpdatePaneLayout() | |
} | ||
return 0.0; | ||
}(); | ||
auto availableHeight = paneContentRow.ActualHeight() - itemsContainerMargin; | ||
|
||
// The c_paneItemsSeparatorHeight is to account for the 9px separator height that we need to subtract. | ||
if (PaneFooter()) | ||
{ | ||
availableHeight -= c_paneItemsSeparatorHeight; | ||
if (const auto& paneFooter = m_leftNavFooterContentBorder.get()) | ||
{ | ||
availableHeight -= paneFooter.ActualHeight(); | ||
} | ||
} | ||
else if (IsSettingsVisible()) | ||
{ | ||
availableHeight -= c_paneItemsSeparatorHeight; | ||
} | ||
else if (m_footerItemsSource && m_menuItemsSource && m_footerItemsSource.Count() * m_menuItemsSource.Count() > 0) | ||
{ | ||
availableHeight -= c_paneItemsSeparatorHeight; | ||
} | ||
|
||
return availableHeight; | ||
return paneContentRow.ActualHeight() - itemsContainerMargin; | ||
} | ||
return 0.0; | ||
}(); | ||
|
@@ -1530,8 +1512,36 @@ void NavigationView::UpdatePaneLayout() | |
// We know the actual height of footer items, so use that to determine how to split pane. | ||
if (const auto& menuItems = m_leftNavRepeater.get()) | ||
{ | ||
const auto footersActualHeight = footerItemsRepeater.ActualHeight(); | ||
const auto menuItemsActualHeight = menuItems.ActualHeight(); | ||
const auto footersActualHeight = [this, footerItemsRepeater]() { | ||
const auto footerItemsRepeaterMargin = footerItemsRepeater.Margin(); | ||
return footerItemsRepeater.ActualHeight() + footerItemsRepeaterMargin.Top + footerItemsRepeaterMargin.Bottom; | ||
}(); | ||
|
||
const auto menuItemsActualHeight = [this, menuItems]() { | ||
const auto menuItemsMargin = menuItems.Margin(); | ||
return menuItems.ActualHeight() + menuItemsMargin.Top + menuItemsMargin.Bottom; | ||
}(); | ||
|
||
const auto paneFooterActualHeight = [this]() { | ||
if (const auto& paneFooter = m_leftNavFooterContentBorder.get()) | ||
{ | ||
const auto paneFooterMargin = paneFooter.Margin(); | ||
return paneFooter.ActualHeight() + paneFooterMargin.Top + paneFooterMargin.Bottom; | ||
} | ||
return 0.0; | ||
}(); | ||
|
||
const auto visualItemsSeparatorHeight = [this]() { | ||
if (const auto& visualItemsSeparator = m_visualItemsSeparator.get()) | ||
{ | ||
const auto visualItemsSeparatorMargin = visualItemsSeparator.Margin(); | ||
return visualItemsSeparator.ActualHeight() + visualItemsSeparatorMargin.Top + visualItemsSeparatorMargin.Bottom; | ||
} | ||
return 0.0; | ||
}(); | ||
|
||
// Footer, PaneFooter, and VisualItemsSeparator are included in the footerGroup to calculate available height for menu items. | ||
const auto footerGroupActualHeight = footersActualHeight + paneFooterActualHeight + visualItemsSeparatorHeight; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding the visualItemsSeparatorHeight feels incorrect to me: you don't want the separator to be shown because of a lack of space due to the separator being shown. You know what I mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about that too... but it was part of the calculation before so I simply included it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed offline, will remove. |
||
|
||
if (m_footerItemsSource.Count() == 0 && !IsSettingsVisible()) | ||
{ | ||
|
@@ -1544,12 +1554,12 @@ void NavigationView::UpdatePaneLayout() | |
winrt::VisualStateManager::GoToState(*this, c_separatorCollapsedStateName, false); | ||
return 0.0; | ||
} | ||
else if (totalAvailableHeight > menuItemsActualHeight + footersActualHeight) | ||
else if (totalAvailableHeight > menuItemsActualHeight + footerGroupActualHeight) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that MUXControlsTestPage first NavigationView test page, totalAvailableHeight happens to be menuItemsActualHeight + footerGroupActualHeight + 4.0 The 4.0 comes from the missing paneFooter.Margin.Bottom mentioned above. Once that is fixed, you will end up with I believe this is because instead of: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is being incorrectly skipped. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed offline. You're right, it would make more sense to add the >= |
||
{ | ||
// We have enough space for two so let everyone get as much as they need. | ||
footerItemsScrollViewer.MaxHeight(footersActualHeight); | ||
winrt::VisualStateManager::GoToState(*this, c_separatorCollapsedStateName, false); | ||
return totalAvailableHeight - footersActualHeight; | ||
return totalAvailableHeight - footerGroupActualHeight; | ||
} | ||
else if (menuItemsActualHeight <= totalAvailableHeightHalf) | ||
{ | ||
|
@@ -1558,12 +1568,12 @@ void NavigationView::UpdatePaneLayout() | |
winrt::VisualStateManager::GoToState(*this, c_separatorVisibleStateName,false); | ||
return menuItemsActualHeight; | ||
} | ||
else if (footersActualHeight <= totalAvailableHeightHalf) | ||
else if (footerGroupActualHeight <= totalAvailableHeightHalf) | ||
{ | ||
// Menu items exceed over the half, so let's limit them. | ||
footerItemsScrollViewer.MaxHeight(footersActualHeight); | ||
winrt::VisualStateManager::GoToState(*this, c_separatorVisibleStateName, false); | ||
return totalAvailableHeight - footersActualHeight; | ||
return totalAvailableHeight - footerGroupActualHeight; | ||
} | ||
else | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -361,6 +361,7 @@ class NavigationView : | |
tracker_ref<winrt::Border> m_topNavContentOverlayAreaGrid{ this }; | ||
tracker_ref<winrt::Grid> m_shadowCaster{ this }; | ||
tracker_ref<winrt::Storyboard> m_shadowCasterEaseOutStoryboard{ this }; | ||
tracker_ref<winrt::NavigationViewItemSeparator> m_visualItemsSeparator{ this }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does not look like you use this anymore. |
||
|
||
// Indicator animations | ||
tracker_ref<winrt::UIElement> m_prevIndicator{ this }; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,11 @@ | |
</VisualState.Setters> | ||
</VisualState> | ||
|
||
<VisualState x:Name="TopNavigationMinimal" /> | ||
<VisualState x:Name="TopNavigationMinimal"> | ||
<VisualState.Setters> | ||
<Setter Target="ContentGrid.BorderThickness" Value="{ThemeResource TopNavigationViewContentGridBorderThickness}" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
|
||
<VisualState x:Name="MinimalWithBackButton"> | ||
<VisualState.Setters> | ||
|
@@ -181,10 +185,10 @@ | |
</VisualStateGroup> | ||
|
||
<VisualStateGroup x:Name="PaneSeparatorStates"> | ||
<VisualState x:Name="SeparatorCollapsed"/> | ||
<VisualState x:Name="SeparatorVisible"> | ||
<VisualState x:Name="SeparatorVisible"/> | ||
<VisualState x:Name="SeparatorCollapsed"> | ||
<VisualState.Setters> | ||
<Setter Target="VisualItemsSeparator.Visibility" Value="Visible"/> | ||
<Setter Target="VisualItemsSeparator.Visibility" Value="Collapsed"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, why is this switched now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh oops. I was previously getting the separator ActualHeight from codebehind, and for it to evaluate to a non-zero value, it needed to be visible by default. The separator is no longer used for pane layout calculations, so I should revert this. |
||
</VisualState.Setters> | ||
</VisualState> | ||
</VisualStateGroup> | ||
|
@@ -585,7 +589,7 @@ | |
x:Name="VisualItemsSeparator" | ||
Grid.Row="1" | ||
Margin="0,0,0,2" | ||
Visibility="Collapsed" | ||
Visibility="Visible" | ||
VerticalAlignment="Center" | ||
HorizontalAlignment="Stretch"/> | ||
|
||
|
@@ -614,8 +618,11 @@ | |
<SplitView.Content> | ||
<Grid | ||
x:Name="ContentGrid" | ||
BorderBrush="{ThemeResource NavigationViewContentGridBorderBrush}" | ||
BorderThickness="{ThemeResource NavigationViewContentGridBorderThickness}" | ||
Background="{ThemeResource NavigationViewContentBackground}" | ||
Margin="{ThemeResource NavigationViewContentMargin}"> | ||
Margin="{ThemeResource NavigationViewContentMargin}" | ||
contract7Present:CornerRadius="{ThemeResource NavigationViewContentGridCornerRadius}"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
|
@@ -646,6 +653,7 @@ | |
Style="{StaticResource NavigationViewTitleHeaderContentControlTextStyle}"/> | ||
|
||
<ContentPresenter | ||
x:Name="ContentPresenter" | ||
AutomationProperties.LandmarkType="Main" | ||
Grid.Row="2" | ||
Grid.ColumnSpan="2" | ||
|
@@ -899,7 +907,6 @@ | |
<Setter Property="IsEnabled" Value="False" /> | ||
<Setter Property="IsTabStop" Value="False" /> | ||
<Setter Property="MinHeight" Value="0" /> | ||
<Setter Property="Margin" Value="{ThemeResource NavigationViewItemSeparatorMargin}" /> | ||
<Setter Property="AutomationProperties.AccessibilityView" Value="Raw" /> | ||
<Setter Property="Template"> | ||
<Setter.Value> | ||
|
@@ -928,7 +935,7 @@ | |
x:Name="SeparatorLine" | ||
Height="{ThemeResource NavigationViewItemSeparatorHeight}" | ||
Fill="{ThemeResource NavigationViewItemSeparatorForeground}" | ||
Margin="{TemplateBinding Margin}"/> | ||
Margin="{ThemeResource NavigationViewItemSeparatorMargin}"/> | ||
beervoley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Grid> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not look like you use this anymore.