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

Delay load NavigationView's heirarchical chevron #6141

Merged
merged 3 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 30 additions & 22 deletions dev/AnimatedIcon/AnimatedIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<winrt::Panel>();
m_rootPanel.set(panel);
m_currentState = GetState(*this);
Expand All @@ -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();
}
Expand Down Expand Up @@ -464,7 +471,8 @@ void AnimatedIcon::PlaySegment(float from, float to, const std::function<void()>

void AnimatedIcon::OnSourcePropertyChanged(const winrt::DependencyPropertyChangedEventArgs&)
{
if(!ConstructAndInsertVisual())
auto const visual = ConstructVisual();
if(!InsertVisual(visual))
{
SetRootPanelChildToFallbackIcon();
}
Expand Down Expand Up @@ -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<winrt::Visual>(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<winrt::Visual>(nullptr);
}
}

bool AnimatedIcon::InsertVisual(winrt::Visual visual)
{
if (auto const rootPanel = m_rootPanel.get())
{
winrt::ElementCompositionPreview::SetElementChildVisual(rootPanel, visual);
Expand Down
3 changes: 2 additions & 1 deletion dev/AnimatedIcon/AnimatedIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<void()>& cleanupAction, float playtbackMultiplier = 1.0f);
void PlaySegment(float from, float to, const std::function<void()>& cleanupAction = nullptr, float playbackMultiplier = 1.0f);
Expand Down
2 changes: 1 addition & 1 deletion dev/Materials/Backdrop/MicaController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we saving this if we are not using the value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, I believe the answer is there is a cppguidelines checker static analysis has a rule that functions with a return value should be stored.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, yeah makes sense. This won't make a big difference but should we then rename the variable to ignored to indicate that this is intentional?

}

// If we are going away and we own the backdrop, clear it.
Expand Down
24 changes: 14 additions & 10 deletions dev/NavigationView/NavigationView_rs1_themeresources.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -654,12 +654,14 @@
<VisualState x:Name="ChevronVisibleOpen">
<VisualState.Setters>
<Setter Target="ExpandCollapseChevron.Visibility" Value="Visible" />
<Setter Target="ExpandCollapseChevronIcon.Visibility" Value="Visible" />
<contract7NotPresent:Setter Target="ExpandCollapseChevronRotateTransform.Angle" Value="180"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="ChevronVisibleClosed">
<VisualState.Setters>
<Setter Target="ExpandCollapseChevron.Visibility" Value="Visible" />
<Setter Target="ExpandCollapseChevronIcon.Visibility" Value="Visible" />
<contract7NotPresent:Setter Target="ExpandCollapseChevronRotateTransform.Angle" Value="0"/>
</VisualState.Setters>
</VisualState>
Expand All @@ -668,42 +670,42 @@
<VisualState x:Name="NormalChevronHidden"/>
<VisualState x:Name="NormalChevronVisibleOpen">
<VisualState.Setters>
<Setter Target="ExpandCollapseChevronIcon.(local:AnimatedIcon.State)" Value="NormalOn"/>
<Setter Target="ExpandCollapseChevron.(local:AnimatedIcon.State)" Value="NormalOn"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="NormalChevronVisibleClosed">
<VisualState.Setters>
<Setter Target="ExpandCollapseChevronIcon.(local:AnimatedIcon.State)" Value="NormalOff"/>
<Setter Target="ExpandCollapseChevron.(local:AnimatedIcon.State)" Value="NormalOff"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="PointerOverChevronHidden">
<VisualState.Setters>
<Setter Target="ExpandCollapseChevronIcon.(local:AnimatedIcon.State)" Value="PointerOverOff"/>
<Setter Target="ExpandCollapseChevron.(local:AnimatedIcon.State)" Value="PointerOverOff"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="PointerOverChevronVisibleOpen">
<VisualState.Setters>
<Setter Target="ExpandCollapseChevronIcon.(local:AnimatedIcon.State)" Value="PointerOverOn"/>
<Setter Target="ExpandCollapseChevron.(local:AnimatedIcon.State)" Value="PointerOverOn"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="PointerOverChevronVisibleClosed">
<VisualState.Setters>
<Setter Target="ExpandCollapseChevronIcon.(local:AnimatedIcon.State)" Value="PointerOverOff"/>
<Setter Target="ExpandCollapseChevron.(local:AnimatedIcon.State)" Value="PointerOverOff"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="PressedChevronHidden">
<VisualState.Setters>
<Setter Target="ExpandCollapseChevronIcon.(local:AnimatedIcon.State)" Value="PressedOff"/>
<Setter Target="ExpandCollapseChevron.(local:AnimatedIcon.State)" Value="PressedOff"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="PressedChevronVisibleOpen">
<VisualState.Setters>
<Setter Target="ExpandCollapseChevronIcon.(local:AnimatedIcon.State)" Value="PressedOn"/>
<Setter Target="ExpandCollapseChevron.(local:AnimatedIcon.State)" Value="PressedOn"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="PressedChevronVisibleClosed">
<VisualState.Setters>
<Setter Target="ExpandCollapseChevronIcon.(local:AnimatedIcon.State)" Value="PressedOff"/>
<Setter Target="ExpandCollapseChevron.(local:AnimatedIcon.State)" Value="PressedOff"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
Expand Down Expand Up @@ -787,16 +789,18 @@
HorizontalAlignment="Right"
Width="40"
Margin="{ThemeResource NavigationViewItemExpandChevronMargin}"
Background="Transparent">
Background="Transparent"
local:AnimatedIcon.State="NormalOff">
<local:AnimatedIcon
Width="12"
Height="12"
RenderTransformOrigin="0.5, 0.5"
x:Name="ExpandCollapseChevronIcon"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Visibility="Collapsed"
AutomationProperties.AccessibilityView="Raw"
local:AnimatedIcon.State="NormalOff">
x:DeferLoadStrategy="Lazy">
<animatedvisuals:AnimatedChevronUpDownSmallVisualSource/>
<local:AnimatedIcon.FallbackIconSource>
<local:FontIconSource
Expand Down
36 changes: 0 additions & 36 deletions test/MUXControlsTestApp/verification/NavigationViewAuto-4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1090,18 +1090,6 @@
RenderSize=0,0
Visibility=Collapsed
Width=40
[Microsoft.UI.Xaml.Controls.AnimatedIcon]
FocusVisualPrimaryBrush=#E4000000
FocusVisualPrimaryThickness=2,2,2,2
FocusVisualSecondaryBrush=#B3FFFFFF
FocusVisualSecondaryThickness=1,1,1,1
Foreground=#E4000000
Height=12
Margin=0,0,0,0
Name=ExpandCollapseChevronIcon
RenderSize=0,0
Visibility=Visible
Width=12
[Windows.UI.Xaml.Controls.ContentPresenter]
Background=[NULL]
BorderBrush=[NULL]
Expand Down Expand Up @@ -1362,18 +1350,6 @@
RenderSize=0,0
Visibility=Collapsed
Width=40
[Microsoft.UI.Xaml.Controls.AnimatedIcon]
FocusVisualPrimaryBrush=#E4000000
FocusVisualPrimaryThickness=2,2,2,2
FocusVisualSecondaryBrush=#B3FFFFFF
FocusVisualSecondaryThickness=1,1,1,1
Foreground=#E4000000
Height=12
Margin=0,0,0,0
Name=ExpandCollapseChevronIcon
RenderSize=0,0
Visibility=Visible
Width=12
[Windows.UI.Xaml.Controls.ContentPresenter]
Background=[NULL]
BorderBrush=[NULL]
Expand Down Expand Up @@ -1868,18 +1844,6 @@
RenderSize=0,0
Visibility=Collapsed
Width=40
[Microsoft.UI.Xaml.Controls.AnimatedIcon]
FocusVisualPrimaryBrush=#E4000000
FocusVisualPrimaryThickness=2,2,2,2
FocusVisualSecondaryBrush=#B3FFFFFF
FocusVisualSecondaryThickness=1,1,1,1
Foreground=#E4000000
Height=12
Margin=0,0,0,0
Name=ExpandCollapseChevronIcon
RenderSize=0,0
Visibility=Visible
Width=12
[Windows.UI.Xaml.Controls.ContentPresenter]
Background=[NULL]
BorderBrush=[NULL]
Expand Down
36 changes: 0 additions & 36 deletions test/MUXControlsTestApp/verification/NavigationViewAuto-7.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1046,18 +1046,6 @@
RenderSize=0,0
Visibility=Collapsed
Width=40
[Microsoft.UI.Xaml.Controls.AnimatedIcon]
FocusVisualPrimaryBrush=#E4000000
FocusVisualPrimaryThickness=2,2,2,2
FocusVisualSecondaryBrush=#B3FFFFFF
FocusVisualSecondaryThickness=1,1,1,1
Foreground=#E4000000
Height=12
Margin=0,0,0,0
Name=ExpandCollapseChevronIcon
RenderSize=0,0
Visibility=Visible
Width=12
[Windows.UI.Xaml.Controls.ContentPresenter]
Background=[NULL]
BorderBrush=[NULL]
Expand Down Expand Up @@ -1320,18 +1308,6 @@
RenderSize=0,0
Visibility=Collapsed
Width=40
[Microsoft.UI.Xaml.Controls.AnimatedIcon]
FocusVisualPrimaryBrush=#E4000000
FocusVisualPrimaryThickness=2,2,2,2
FocusVisualSecondaryBrush=#B3FFFFFF
FocusVisualSecondaryThickness=1,1,1,1
Foreground=#E4000000
Height=12
Margin=0,0,0,0
Name=ExpandCollapseChevronIcon
RenderSize=0,0
Visibility=Visible
Width=12
[Windows.UI.Xaml.Controls.ContentPresenter]
Background=[NULL]
BorderBrush=[NULL]
Expand Down Expand Up @@ -1801,18 +1777,6 @@
RenderSize=0,0
Visibility=Collapsed
Width=40
[Microsoft.UI.Xaml.Controls.AnimatedIcon]
FocusVisualPrimaryBrush=#E4000000
FocusVisualPrimaryThickness=2,2,2,2
FocusVisualSecondaryBrush=#B3FFFFFF
FocusVisualSecondaryThickness=1,1,1,1
Foreground=#E4000000
Height=12
Margin=0,0,0,0
Name=ExpandCollapseChevronIcon
RenderSize=0,0
Visibility=Visible
Width=12
[Windows.UI.Xaml.Controls.ContentPresenter]
Background=[NULL]
BorderBrush=[NULL]
Expand Down
Loading