Skip to content

Commit e4c5299

Browse files
committed
Unify slide wipes into SlideWipe
1 parent 26844ed commit e4c5299

File tree

4 files changed

+111
-88
lines changed

4 files changed

+111
-88
lines changed

MaterialDesignThemes.Wpf/MaterialDesignThemes.Wpf.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,8 @@
370370
<Compile Include="RippleAssist.cs" />
371371
<Compile Include="Ripple.cs" />
372372
<Compile Include="Transitions\IZIndexController.cs" />
373-
<Compile Include="Transitions\SlideLeftWipe.cs" />
373+
<Compile Include="Transitions\SlideWipe.cs" />
374374
<Compile Include="Transitions\SlideOutWipe.cs" />
375-
<Compile Include="Transitions\SlideRightWipe.cs" />
376375
<Compile Include="Transitions\TransitionAssist.cs" />
377376
<Compile Include="Transitions\TransitionEffect.cs" />
378377
<Compile Include="Transitions\TransitionEffectBase.cs" />

MaterialDesignThemes.Wpf/Transitions/SlideLeftWipe.cs

Lines changed: 0 additions & 43 deletions
This file was deleted.

MaterialDesignThemes.Wpf/Transitions/SlideRightWipe.cs

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
using System;
2+
using System.Windows;
3+
using System.Windows.Media;
4+
using System.Windows.Media.Animation;
5+
6+
namespace MaterialDesignThemes.Wpf.Transitions
7+
{
8+
public class SlideWipe : ITransitionWipe
9+
{
10+
public enum SlideDirection { Left, Right, Up, Down }
11+
12+
private readonly SineEase _sineEase = new SineEase();
13+
14+
/// <summary>
15+
/// Direction of the slide wipe
16+
/// </summary>
17+
public SlideDirection Direction { get; set; }
18+
19+
/// <summary>
20+
/// Duration of the animation
21+
/// </summary>
22+
public TimeSpan Duration { get; set; } = TimeSpan.FromSeconds(0.5);
23+
24+
public void Wipe(TransitionerSlide fromSlide, TransitionerSlide toSlide, Point origin, IZIndexController zIndexController)
25+
{
26+
if (fromSlide == null) throw new ArgumentNullException(nameof(fromSlide));
27+
if (toSlide == null) throw new ArgumentNullException(nameof(toSlide));
28+
if (zIndexController == null) throw new ArgumentNullException(nameof(zIndexController));
29+
30+
// Set up time points
31+
var zeroKeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero);
32+
var endKeyTime = KeyTime.FromTimeSpan(Duration);
33+
34+
// Set up coordinates
35+
double fromStartX, fromEndX, toStartX, toEndX;
36+
double fromStartY, fromEndY, toStartY, toEndY;
37+
38+
if (Direction == SlideDirection.Left)
39+
{
40+
fromStartX = 0;
41+
fromStartY = 0;
42+
fromEndX = -fromSlide.ActualWidth;
43+
fromEndY = 0;
44+
toStartX = toSlide.ActualWidth;
45+
toStartY = 0;
46+
toEndX = 0;
47+
toEndY = 0;
48+
}
49+
else if (Direction == SlideDirection.Right)
50+
{
51+
fromStartX = 0;
52+
fromStartY = 0;
53+
fromEndX = fromSlide.ActualWidth;
54+
fromEndY = 0;
55+
toStartX = -toSlide.ActualWidth;
56+
toStartY = 0;
57+
toEndX = 0;
58+
toEndY = 0;
59+
}
60+
else if (Direction == SlideDirection.Up)
61+
{
62+
fromStartX = 0;
63+
fromStartY = 0;
64+
fromEndX = 0;
65+
fromEndY = -fromSlide.ActualHeight;
66+
toStartX = 0;
67+
toStartY = toSlide.ActualHeight;
68+
toEndX = 0;
69+
toEndY = 0;
70+
}
71+
else // if (Direction == SlideDirection.Down)
72+
{
73+
fromStartX = 0;
74+
fromStartY = 0;
75+
fromEndX = 0;
76+
fromEndY = fromSlide.ActualHeight;
77+
toStartX = 0;
78+
toStartY = -toSlide.ActualHeight;
79+
toEndX = 0;
80+
toEndY = 0;
81+
}
82+
83+
// Old
84+
fromSlide.RenderTransform = new TranslateTransform(fromStartX, fromStartY);
85+
var fromXAnimation = new DoubleAnimationUsingKeyFrames();
86+
fromXAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(fromStartX, zeroKeyTime));
87+
fromXAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(fromEndX, endKeyTime, _sineEase));
88+
var fromYAnimation = new DoubleAnimationUsingKeyFrames();
89+
fromYAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(fromStartY, zeroKeyTime));
90+
fromYAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(fromEndY, endKeyTime, _sineEase));
91+
92+
// New
93+
toSlide.RenderTransform = new TranslateTransform(toStartX, toStartY);
94+
var toXAnimation = new DoubleAnimationUsingKeyFrames();
95+
toXAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(toStartX, zeroKeyTime));
96+
toXAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(toEndX, endKeyTime, _sineEase));
97+
var toYAnimation = new DoubleAnimationUsingKeyFrames();
98+
toYAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(toStartY, zeroKeyTime));
99+
toYAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(toEndY, endKeyTime, _sineEase));
100+
101+
// Animate
102+
fromSlide.RenderTransform.BeginAnimation(TranslateTransform.XProperty, fromXAnimation);
103+
fromSlide.RenderTransform.BeginAnimation(TranslateTransform.YProperty, fromYAnimation);
104+
toSlide.RenderTransform.BeginAnimation(TranslateTransform.XProperty, toXAnimation);
105+
toSlide.RenderTransform.BeginAnimation(TranslateTransform.YProperty, toYAnimation);
106+
107+
zIndexController.Stack(toSlide, fromSlide);
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)