From b8531098857e491b46d8f3a3b48df5cf34572e1a Mon Sep 17 00:00:00 2001 From: Canhua Li Date: Mon, 3 May 2021 12:02:58 -0700 Subject: [PATCH] Disable animation for rating control when ControlsResourcesVersion is Version2 (#4916) --- dev/RatingControl/RatingControl.cpp | 13 ++++++++++--- dev/RatingControl/RatingControl.h | 2 +- dev/dll/XamlControlsResources.cpp | 7 ++++++- dev/dll/XamlControlsResources.h | 1 + 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/dev/RatingControl/RatingControl.cpp b/dev/RatingControl/RatingControl.cpp index b7ed31efab..794c0d5722 100644 --- a/dev/RatingControl/RatingControl.cpp +++ b/dev/RatingControl/RatingControl.cpp @@ -6,6 +6,7 @@ #include "RatingControl.h" #include "RatingControlAutomationPeer.h" #include "RuntimeProfiler.h" +#include "XamlControlsResources.h" #include #include @@ -543,7 +544,7 @@ void RatingControl::SetRatingTo(double newRating, bool originatedFromMouse) Value(c_noValueSetSentinel); } - if (SharedHelpers::IsRS1OrHigher() && IsFocusEngaged() && SharedHelpers::IsAnimationsEnabled()) + if (SharedHelpers::IsRS1OrHigher() && IsFocusEngaged() && ShouldEnableAnimation()) { const double focalPoint = CalculateStarCenter((int)(ratingValue - 1.0)); m_sharedPointerPropertySet.InsertScalar(L"starsScaleFocalPoint", static_cast(focalPoint)); @@ -763,7 +764,7 @@ void RatingControl::OnPointerMovedOverBackgroundStackPanel(const winrt::IInspect { const auto point = args.GetCurrentPoint(m_backgroundStackPanel.get()); const float xPosition = point.Position().X; - if (SharedHelpers::IsAnimationsEnabled()) + if (ShouldEnableAnimation()) { m_sharedPointerPropertySet.InsertScalar(L"starsScaleFocalPoint", xPosition); auto deviceType = args.Pointer().PointerDeviceType(); @@ -1033,6 +1034,12 @@ void RatingControl::OnPreviewKeyUp(winrt::KeyRoutedEventArgs const& eventArgs) } } +bool RatingControl::ShouldEnableAnimation() +{ + // In ControlsResourceVersion2, animation is disabled. + return !XamlControlsResources::IsUsingControlsResourcesVersion2() && SharedHelpers::IsAnimationsEnabled(); +} + void RatingControl::OnFocusEngaged(const winrt::Control& /*sender*/, const winrt::FocusEngagedEventArgs& /*args*/) { if (!IsReadOnly()) @@ -1090,7 +1097,7 @@ void RatingControl::EnterGamepadEngagementMode() winrt::ElementSoundPlayer::Play(winrt::ElementSoundKind::Invoke); } - if (SharedHelpers::IsAnimationsEnabled()) + if (ShouldEnableAnimation()) { const double focalPoint = CalculateStarCenter((int)(currentValue - 1.0)); m_sharedPointerPropertySet.InsertScalar(L"starsScaleFocalPoint", static_cast(focalPoint)); diff --git a/dev/RatingControl/RatingControl.h b/dev/RatingControl/RatingControl.h index 5858fb1ecd..3911a856bc 100644 --- a/dev/RatingControl/RatingControl.h +++ b/dev/RatingControl/RatingControl.h @@ -112,7 +112,7 @@ class RatingControl : void OnPreviewKeyUp(winrt::KeyRoutedEventArgs const& e); private: - + bool ShouldEnableAnimation(); void OnFocusEngaged(const winrt::Control& sender, const winrt::FocusEngagedEventArgs& args); void OnFocusDisengaged(const winrt::Control& sender, const winrt::FocusDisengagedEventArgs& args); diff --git a/dev/dll/XamlControlsResources.cpp b/dev/dll/XamlControlsResources.cpp index b345b8c214..63241e6c11 100644 --- a/dev/dll/XamlControlsResources.cpp +++ b/dev/dll/XamlControlsResources.cpp @@ -21,7 +21,7 @@ static constexpr auto c_AccentAcrylicInAppFillColorBaseBrush = L"AccentAcrylicIn // Controls knows nothing about XamlControlsResources, but we need a way to pass the new visual flag from XamlControlsResources to Controls // Assume XamlControlsResources is one per Application resource, and application is per thread, // so it's OK to assume one instance of XamlControlsResources per thread. -thread_local bool s_tlsIsControlsResourcesVersion2 = true; +static thread_local bool s_tlsIsControlsResourcesVersion2 = true; XamlControlsResources::XamlControlsResources() { @@ -360,3 +360,8 @@ void XamlControlsResources::EnsureRevealLights(winrt::UIElement const& element) }); } } + +bool XamlControlsResources::IsUsingControlsResourcesVersion2() +{ + return s_tlsIsControlsResourcesVersion2; +} diff --git a/dev/dll/XamlControlsResources.h b/dev/dll/XamlControlsResources.h index 55f91cf5d4..882837e3f7 100644 --- a/dev/dll/XamlControlsResources.h +++ b/dev/dll/XamlControlsResources.h @@ -17,6 +17,7 @@ class XamlControlsResources : void UpdateAcrylicBrushesLightTheme(const winrt::IInspectable themeDictionary); void UpdateAcrylicBrushesDarkTheme(const winrt::IInspectable themeDictionary); static void EnsureRevealLights(winrt::UIElement const& element); + static bool IsUsingControlsResourcesVersion2(); private: void UpdateSource(); bool IsControlsResourcesVersion2();