Skip to content

Commit

Permalink
change show and hide animation of overlay page
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Dec 29, 2023
1 parent 4faf70d commit 685dab7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Starward/MyWindows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<sp:MainPage Name="mainPage" />
<sp:MainPage x:Name="mainPage" />

<Frame Name="Frame_Overlay"
IsNavigationStackEnabled="False"
Expand Down
62 changes: 52 additions & 10 deletions src/Starward/MyWindows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Animation;
using Starward.Pages;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Vanara.PInvoke;
using Windows.Graphics;
Expand Down Expand Up @@ -103,22 +105,62 @@ private void MainWindow_Closed(object sender, WindowEventArgs args)
}


public void OverlayFrameNavigateTo(Type page, object? parameter, NavigationTransitionInfo infoOverride)

private CancellationTokenSource overlayCancelTokenSource;


public void OverlayFrameNavigateTo(Type page, object? parameter)
{
MainPage.Current?.PauseVideo();
Frame_Overlay.Visibility = Visibility.Visible;
Frame_Overlay.Navigate(page, parameter!, infoOverride);
var len = (int)(48 * UIScale);
SetDragRectangles(new RectInt32(0, 0, 100000, len));
try
{
overlayCancelTokenSource?.Cancel();
overlayCancelTokenSource = new CancellationTokenSource();
MainPage.Current?.PauseVideo();
Frame_Overlay.Visibility = Visibility.Visible;
Frame_Overlay.Navigate(page, parameter!, new SuppressNavigationTransitionInfo());
if (Frame_Overlay.Content is UIElement element)
{
element.Transitions = [new EntranceThemeTransition { FromVerticalOffset = 600 }];
}
SetDragRectangles(new RectInt32(0, 0, 100000, (int)(48 * UIScale)));
}
catch { }
}


public void CloseOverlayPage()
{
MainPage.Current?.PlayVideo();
Frame_Overlay.Visibility = Visibility.Collapsed;
Frame_Overlay.Content = null;
MainPage.Current?.UpdateDragRectangles();
try
{
if (Frame_Overlay.Content is UIElement element)
{
var token = overlayCancelTokenSource?.Token ?? CancellationToken.None;
var tt = new TranslateTransform();
element.RenderTransform = tt;
var da = new DoubleAnimation
{
To = Frame_Overlay.ActualHeight,
Duration = new Duration(TimeSpan.FromMilliseconds(600)),
EasingFunction = new BackEase(),
};
Storyboard.SetTarget(da, tt);
Storyboard.SetTargetProperty(da, nameof(tt.Y));
var sb = new Storyboard { Duration = new Duration(TimeSpan.FromMilliseconds(600)) };
sb.Children.Add(da);
sb.Completed += (_, _) =>
{
if (token.IsCancellationRequested)
{
return;
}
Frame_Overlay.Visibility = Visibility.Collapsed;
Frame_Overlay.Content = null;
MainPage.Current?.UpdateDragRectangles();
};
sb.Begin();
}
}
catch { }
}


Expand Down
6 changes: 3 additions & 3 deletions src/Starward/Pages/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private async Task CheckUpdateAsync()
var release = await _updateService.CheckUpdateAsync(false);
if (release != null)
{
MainWindow.Current.OverlayFrameNavigateTo(typeof(UpdatePage), release, new DrillInNavigationTransitionInfo());
MainWindow.Current.OverlayFrameNavigateTo(typeof(UpdatePage), release);
}
}
catch (HttpRequestException ex)
Expand Down Expand Up @@ -779,7 +779,7 @@ private async void NavigationView_ItemInvoked(NavigationView sender, NavigationV
}
if (item.Tag is nameof(SettingPage))
{
MainWindow.Current.OverlayFrameNavigateTo(typeof(Setting.SettingPage), null, new SuppressNavigationTransitionInfo());
MainWindow.Current.OverlayFrameNavigateTo(typeof(SettingPage), null);
await Task.Delay(1);
sender.SelectedItem = null;
return;
Expand Down Expand Up @@ -959,7 +959,7 @@ private void ShortcutNavigate(int num)
{
if (num == 0)
{
MainWindow.Current.OverlayFrameNavigateTo(typeof(Setting.SettingPage), null, new SuppressNavigationTransitionInfo());
MainWindow.Current.OverlayFrameNavigateTo(typeof(SettingPage), null);
}
if (CurrentGameBiz.ToGame() == GameBiz.None)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Starward/Pages/ScreenshotPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private void GridView_Images_ItemClick(object sender, ItemClickEventArgs e)
if (e.ClickedItem is ScreenshotItem item && Watcher is not null)
{
var list = Watcher.ImageList.ToList();
MainWindow.Current.OverlayFrameNavigateTo(typeof(ImageViewPage), (item, list), new DrillInNavigationTransitionInfo());
MainWindow.Current.OverlayFrameNavigateTo(typeof(ImageViewPage), (item, list));
}
}
catch { }
Expand Down
2 changes: 1 addition & 1 deletion src/Starward/Pages/Setting/AboutSettingPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private async Task CheckUpdateAsync()
var release = await _updateService.CheckUpdateAsync(true);
if (release != null)
{
MainWindow.Current.OverlayFrameNavigateTo(typeof(UpdatePage), release, new SlideNavigationTransitionInfo());
MainWindow.Current.OverlayFrameNavigateTo(typeof(UpdatePage), release);
}
else
{
Expand Down

0 comments on commit 685dab7

Please sign in to comment.