Skip to content

Commit 84ff542

Browse files
committed
Splashscreen fadein and fadeout animation
1 parent 7f4563f commit 84ff542

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Lively/Lively/App.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public App()
156156
//On first run default assets are installed by UI to avoid slow startup times and better user experience.
157157
if (userSettings.Settings.IsUpdated || userSettings.Settings.IsFirstRun)
158158
{
159-
SplashWindow spl = userSettings.Settings.IsFirstRun ? new() : null; spl?.Show();
159+
SplashWindow spl = userSettings.Settings.IsFirstRun ? new(0, 500) : null; spl?.Show();
160160
var maxWallpaper = ZipExtract.ExtractAssetBundle(userSettings.Settings.WallpaperBundleVersion,
161161
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bundle", "wallpapers"),
162162
Path.Combine(userSettings.Settings.WallpaperDir, Constants.CommonPartialPaths.WallpaperInstallDir));

src/Lively/Lively/Views/SplashWindow.xaml.cs

+27
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Windows.Documents;
1010
using System.Windows.Input;
1111
using System.Windows.Media;
12+
using System.Windows.Media.Animation;
1213
using System.Windows.Media.Imaging;
1314
using System.Windows.Shapes;
1415

@@ -19,9 +20,35 @@ namespace Lively.Views
1920
/// </summary>
2021
public partial class SplashWindow : Window
2122
{
23+
private readonly double fadeInDuration = 200;
24+
private readonly double fadeOutDuration = 200;
25+
2226
public SplashWindow()
2327
{
2428
InitializeComponent();
2529
}
30+
31+
public SplashWindow(double fadeInDuration, double fadeOutDuration) : this()
32+
{
33+
this.fadeInDuration = fadeInDuration;
34+
this.fadeOutDuration = fadeOutDuration;
35+
this.Closing += Window_Closing;
36+
this.Loaded += Window_Loaded;
37+
}
38+
39+
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
40+
{
41+
this.Closing -= Window_Closing;
42+
e.Cancel = true;
43+
var anim = new DoubleAnimation(0, (Duration)TimeSpan.FromMilliseconds(fadeOutDuration));
44+
anim.Completed += (s, _) => this.Close();
45+
this.BeginAnimation(UIElement.OpacityProperty, anim);
46+
}
47+
48+
private void Window_Loaded(object sender, RoutedEventArgs e)
49+
{
50+
var anim = new DoubleAnimation(0, 1, (Duration)TimeSpan.FromMilliseconds(fadeInDuration));
51+
this.BeginAnimation(UIElement.OpacityProperty, anim);
52+
}
2653
}
2754
}

0 commit comments

Comments
 (0)