Skip to content

Commit

Permalink
Fixes #73
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMisiukevich committed Oct 28, 2020
1 parent eb3f002 commit 74c9b42
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion TouchEffect/TouchEff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ public VisualElement Control
if (_control != null)
{
IsUsed = false;
_visualManager.SetCustomAnimationTask(null);
_visualManager.Reset();
SetChildrenInputTransparent(false);
}
_visualManager.AbortAnimations(this);
Expand Down
28 changes: 23 additions & 5 deletions TouchEffect/TouchVisualManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ internal sealed class TouchVisualManager

private const int AnimationProgressDelay = 10;

private Color _defaultBackgroundColor;

private CancellationTokenSource _longPressTokenSource;

private CancellationTokenSource _animationTokenSource;
Expand Down Expand Up @@ -198,6 +200,12 @@ internal void HandleLongPress(TouchEff sender)
internal void SetCustomAnimationTask(Func<TouchEff, TouchState, HoverState, int, CancellationToken, Task> animationTaskGetter)
=> _customAnimationTaskGetter = animationTaskGetter;

internal void Reset()
{
SetCustomAnimationTask(null);
_defaultBackgroundColor = default;
}

internal void OnTapped(TouchEff sender)
{
if (!sender.CanExecute || (sender.LongPressCommand != null && sender.UserInteractionState == UserInteractionState.Idle))
Expand Down Expand Up @@ -255,21 +263,24 @@ private async Task SetBackgroundColorAsync(TouchEff sender, TouchState touchStat
return;
}

var color = regularBackgroundColor;
var control = sender.Control;
if (_defaultBackgroundColor == default)
_defaultBackgroundColor = control.BackgroundColor;

var color = GetBackgroundColor(regularBackgroundColor);
var easing = sender.RegularAnimationEasing;

if (touchState == TouchState.Pressed)
{
color = pressedBackgroundColor;
color = GetBackgroundColor(pressedBackgroundColor);
easing = sender.PressedAnimationEasing;
}
else if (hoverState == HoverState.Hovering)
{
color = hoveredBackgroundColor;
color = GetBackgroundColor(hoveredBackgroundColor);
easing = sender.HoveredAnimationEasing;
}

var control = sender.Control;
if (duration <= 0)
{
control.BackgroundColor = color;
Expand Down Expand Up @@ -486,6 +497,11 @@ private async Task SetRotationYAsync(TouchEff sender, TouchState touchState, Hov
await sender.Control.RotateYTo(rotationY, (uint)Abs(duration), easing);
}

private Color GetBackgroundColor(Color color)
=> color != Color.Default
? color
: _defaultBackgroundColor;

private Task GetAnimationTask(TouchEff sender, TouchState touchState, HoverState hoverState, double? durationMultiplier = null)
{
if (sender.Control == null)
Expand All @@ -505,7 +521,9 @@ private Task GetAnimationTask(TouchEff sender, TouchState touchState, HoverState
}
duration = duration.AdjustDurationMultiplier(durationMultiplier);

if (duration <= 0 && (Device.RuntimePlatform == Device.Android || Device.RuntimePlatform == Device.UWP))
if (duration <= 0 &&
Device.RuntimePlatform != Device.iOS &&
Device.RuntimePlatform != Device.macOS)
{
duration = 1;
}
Expand Down

0 comments on commit 74c9b42

Please sign in to comment.