From 7ec5fb5b8c85ebe04d8498ee89f26d1b5259d948 Mon Sep 17 00:00:00 2001 From: Stephen L Peters Date: Fri, 29 Oct 2021 12:14:24 -0700 Subject: [PATCH] Delay load NavigationView's heirarchical chevron (#6141) * Delay load NavigationView's heirarchical chevron until actually needed. Fix a bug in AnimatedIcon where the AnimatedVisuals would be created twice on initial load. * Fix release mode build breaks. * Update Visual Verification files --- dev/AnimatedIcon/AnimatedIcon.cpp | 52 ++++--- dev/AnimatedIcon/AnimatedIcon.h | 3 +- dev/Materials/Backdrop/MicaController.cpp | 2 +- .../NavigationView_rs1_themeresources.xaml | 24 +-- .../verification/NavigationViewAuto-4.xml | 36 ----- .../verification/NavigationViewAuto-7.xml | 36 ----- .../verification/NavigationViewAuto-8.xml | 36 ----- .../NavigationViewLeftCompact-4.xml | 36 ----- .../NavigationViewLeftCompact-5.xml | 36 ----- .../NavigationViewLeftCompact-7.xml | 36 ----- .../NavigationViewLeftCompact-8.xml | 36 ----- .../NavigationViewLeftMinimal-4.xml | 36 ----- .../NavigationViewLeftMinimal-7.xml | 36 ----- .../NavigationViewLeftMinimal-8.xml | 36 ----- .../NavigationViewLeftPaneContent-4.xml | 36 ----- .../NavigationViewLeftPaneContent-7.xml | 36 ----- .../NavigationViewLeftPaneContent-8.xml | 36 ----- .../NavigationViewScrolling-4.xml | 144 ------------------ .../NavigationViewScrolling-7.xml | 144 ------------------ .../NavigationViewScrolling-8.xml | 144 ------------------ 20 files changed, 47 insertions(+), 934 deletions(-) diff --git a/dev/AnimatedIcon/AnimatedIcon.cpp b/dev/AnimatedIcon/AnimatedIcon.cpp index 82130f8708..960e56b286 100644 --- a/dev/AnimatedIcon/AnimatedIcon.cpp +++ b/dev/AnimatedIcon/AnimatedIcon.cpp @@ -31,7 +31,16 @@ void AnimatedIcon::OnApplyTemplate() __super::OnApplyTemplate(); // Construct the visual from the Source property in on apply template so that it participates // in the initial measure for the object. - ConstructAndInsertVisual(); + auto const visual = [animatedVisual = m_animatedVisual.get(), this]() + { + if (animatedVisual) + { + return animatedVisual.RootVisual(); + } + return ConstructVisual(); + }(); + InsertVisual(visual); + auto const panel = winrt::VisualTreeHelper::GetChild(*this, 0).as(); m_rootPanel.set(panel); m_currentState = GetState(*this); @@ -50,10 +59,8 @@ void AnimatedIcon::OnApplyTemplate() path.Visibility(winrt::Visibility::Collapsed); } } - if (auto const visual = m_animatedVisual.get()) - { - winrt::ElementCompositionPreview::SetElementChildVisual(panel, visual.RootVisual()); - } + + winrt::ElementCompositionPreview::SetElementChildVisual(panel, visual); TrySetForegroundProperty(); } @@ -464,7 +471,8 @@ void AnimatedIcon::PlaySegment(float from, float to, const std::function void AnimatedIcon::OnSourcePropertyChanged(const winrt::DependencyPropertyChangedEventArgs&) { - if(!ConstructAndInsertVisual()) + auto const visual = ConstructVisual(); + if(!InsertVisual(visual)) { SetRootPanelChildToFallbackIcon(); } @@ -497,26 +505,26 @@ void AnimatedIcon::OnMirroredWhenRightToLeftPropertyChanged(const winrt::Depende UpdateMirrorTransform(); } -bool AnimatedIcon::ConstructAndInsertVisual() +winrt::Visual AnimatedIcon::ConstructVisual() { - auto const visual = [this]() + if (auto const source = Source()) { - if (auto const source = Source()) - { - TrySetForegroundProperty(source); + TrySetForegroundProperty(source); - winrt::IInspectable diagnostics{}; - auto const visual = source.TryCreateAnimatedVisual(winrt::Window::Current().Compositor(), diagnostics); - m_animatedVisual.set(visual); - return visual ? visual.RootVisual() : nullptr; - } - else - { - m_animatedVisual.set(nullptr); - return static_cast(nullptr); - } - }(); + winrt::IInspectable diagnostics{}; + auto const visual = source.TryCreateAnimatedVisual(winrt::Window::Current().Compositor(), diagnostics); + m_animatedVisual.set(visual); + return visual ? visual.RootVisual() : nullptr; + } + else + { + m_animatedVisual.set(nullptr); + return static_cast(nullptr); + } +} +bool AnimatedIcon::InsertVisual(winrt::Visual visual) +{ if (auto const rootPanel = m_rootPanel.get()) { winrt::ElementCompositionPreview::SetElementChildVisual(rootPanel, visual); diff --git a/dev/AnimatedIcon/AnimatedIcon.h b/dev/AnimatedIcon/AnimatedIcon.h index 01112f5697..355bb55f93 100644 --- a/dev/AnimatedIcon/AnimatedIcon.h +++ b/dev/AnimatedIcon/AnimatedIcon.h @@ -50,7 +50,8 @@ class AnimatedIcon : winrt::hstring GetLastAnimationSegmentStart(); winrt::hstring GetLastAnimationSegmentEnd(); private: - bool ConstructAndInsertVisual(); + winrt::Visual ConstructVisual(); + bool InsertVisual(winrt::Visual visual); void TransitionAndUpdateStates(const winrt::hstring& fromState, const winrt::hstring& toState, float playbackMultiplier = 1.0f); void TransitionStates(const winrt::hstring& fromState, const winrt::hstring& toState, const std::function& cleanupAction, float playtbackMultiplier = 1.0f); void PlaySegment(float from, float to, const std::function& cleanupAction = nullptr, float playbackMultiplier = 1.0f); diff --git a/dev/Materials/Backdrop/MicaController.cpp b/dev/Materials/Backdrop/MicaController.cpp index 2c02bdb61d..ed577b8e11 100644 --- a/dev/Materials/Backdrop/MicaController.cpp +++ b/dev/Materials/Backdrop/MicaController.cpp @@ -17,7 +17,7 @@ MicaController::~MicaController() // Workaround for null ref exception in Window::get_SystemBackdrop when the Window is shutting down. // GenerateRawElementProviderRuntimeId will trigger an exception caught below and thus prevent the // crashing target.SystemBackdrop() call. - auto runtimeId = winrt::Automation::Peers::AutomationPeer::GenerateRawElementProviderRuntimeId(); + auto const runtimeId = winrt::Automation::Peers::AutomationPeer::GenerateRawElementProviderRuntimeId(); } // If we are going away and we own the backdrop, clear it. diff --git a/dev/NavigationView/NavigationView_rs1_themeresources.xaml b/dev/NavigationView/NavigationView_rs1_themeresources.xaml index 94f360adb5..39240069fb 100755 --- a/dev/NavigationView/NavigationView_rs1_themeresources.xaml +++ b/dev/NavigationView/NavigationView_rs1_themeresources.xaml @@ -654,12 +654,14 @@ + + @@ -668,42 +670,42 @@ - + - + - + - + - + - + - + - + @@ -787,7 +789,8 @@ HorizontalAlignment="Right" Width="40" Margin="{ThemeResource NavigationViewItemExpandChevronMargin}" - Background="Transparent"> + Background="Transparent" + local:AnimatedIcon.State="NormalOff"> + x:DeferLoadStrategy="Lazy">