Skip to content

Commit

Permalink
Disable animation for rating control when ControlsResourcesVersion is…
Browse files Browse the repository at this point in the history
… Version2 (#4916)
  • Loading branch information
licanhua authored May 3, 2021
1 parent 7ef70d1 commit b853109
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
13 changes: 10 additions & 3 deletions dev/RatingControl/RatingControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "RatingControl.h"
#include "RatingControlAutomationPeer.h"
#include "RuntimeProfiler.h"
#include "XamlControlsResources.h"

#include <RatingItemFontInfo.h>
#include <RatingItemImageInfo.h>
Expand Down Expand Up @@ -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<float>(focalPoint));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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<float>(focalPoint));
Expand Down
2 changes: 1 addition & 1 deletion dev/RatingControl/RatingControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 6 additions & 1 deletion dev/dll/XamlControlsResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -360,3 +360,8 @@ void XamlControlsResources::EnsureRevealLights(winrt::UIElement const& element)
});
}
}

bool XamlControlsResources::IsUsingControlsResourcesVersion2()
{
return s_tlsIsControlsResourcesVersion2;
}
1 change: 1 addition & 0 deletions dev/dll/XamlControlsResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b853109

Please sign in to comment.