-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #316 from maxkatz6/rippleRework
Replace Ellipse-based Ripple with Composition API
- Loading branch information
Showing
5 changed files
with
177 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,9 @@ | ||
using System; | ||
using Avalonia; | ||
using Avalonia.Animation; | ||
using Avalonia.Animation.Easings; | ||
using Avalonia.Controls; | ||
using Avalonia.Controls.Shapes; | ||
using Avalonia.Input; | ||
using Avalonia.Layout; | ||
|
||
namespace Material.Ripple { | ||
public class Ripple : Ellipse { | ||
public static Transitions? RippleTransitions; | ||
|
||
private static Easing _easing = new CircularEaseOut(); | ||
private static TimeSpan _duration = new(0, 0, 0, 0, 500); | ||
|
||
private readonly double _endX; | ||
private readonly double _endY; | ||
|
||
|
||
|
||
private readonly double _maxDiam; | ||
|
||
static Ripple() { | ||
UpdateTransitions(); | ||
} | ||
|
||
public Ripple(double outerWidth, double outerHeight, bool transitions = true) { | ||
Width = 0; | ||
Height = 0; | ||
|
||
_maxDiam = Math.Sqrt(Math.Pow(outerWidth, 2) + Math.Pow(outerHeight, 2)); | ||
_endY = _maxDiam - outerHeight; | ||
_endX = _maxDiam - outerWidth; | ||
HorizontalAlignment = HorizontalAlignment.Left; | ||
VerticalAlignment = VerticalAlignment.Top; | ||
Opacity = 1; | ||
|
||
if (!transitions) | ||
return; | ||
|
||
Transitions = RippleTransitions; | ||
} | ||
|
||
public static Easing Easing { | ||
get => _easing; | ||
set { | ||
_easing = value; | ||
UpdateTransitions(); | ||
} | ||
} | ||
|
||
public static TimeSpan Duration { | ||
get => _duration; | ||
set { | ||
_duration = value; | ||
UpdateTransitions(); | ||
} | ||
} | ||
|
||
public void SetupInitialValues(PointerPressedEventArgs e, Control parent) { | ||
var pointer = e.GetPosition(parent); | ||
Margin = new Thickness(pointer.X, pointer.Y, 0, 0); | ||
} | ||
|
||
public void RunFirstStep() { | ||
Width = _maxDiam; | ||
Height = _maxDiam; | ||
Margin = new Thickness(-_endX / 2, -_endY / 2, 0, 0); | ||
} | ||
|
||
public void RunSecondStep() { | ||
Opacity = 0; | ||
} | ||
|
||
private static void UpdateTransitions() { | ||
RippleTransitions = new Transitions { | ||
new ThicknessTransition { | ||
Duration = Duration, | ||
Easing = Easing, | ||
Property = MarginProperty | ||
}, | ||
new DoubleTransition { | ||
Duration = Duration, | ||
Easing = Easing, | ||
Property = WidthProperty | ||
}, | ||
new DoubleTransition { | ||
Duration = Duration, | ||
Easing = Easing, | ||
Property = HeightProperty | ||
}, | ||
new DoubleTransition { | ||
Duration = Duration, | ||
Easing = Easing, | ||
Property = OpacityProperty | ||
} | ||
}; | ||
} | ||
public static class Ripple { | ||
public static Easing Easing { get; set; } = new CircularEaseOut(); | ||
public static TimeSpan Duration { get; set; } = new(0, 0, 0, 1, 200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.