Skip to content

Commit

Permalink
sheets: Avoid calling Hiding while already Hiding
Browse files Browse the repository at this point in the history
  • Loading branch information
WamWooWam committed Dec 3, 2024
1 parent b5fdbd3 commit 9fab5b8
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions UniSky/Controls/Sheet/SheetRootControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.Toolkit.Uwp.UI;
Expand Down Expand Up @@ -52,6 +53,8 @@ public double TotalHeight
public static readonly DependencyProperty TotalHeightProperty =
DependencyProperty.Register("TotalHeight", typeof(double), typeof(SheetRootControl), new PropertyMetadata(0.0));

private SemaphoreSlim _hideSemaphore = new SemaphoreSlim(1, 1);

public SheetRootControl()
{
this.InitializeComponent();
Expand Down Expand Up @@ -98,22 +101,32 @@ private async void OnBackRequested(object sender, BackRequestedEventArgs e)

internal async Task<bool> HideSheetAsync()
{
// TODO: allow deferrals
if (SheetRoot.Child is SheetControl control)
if (!await _hideSemaphore.WaitAsync(100))
return false;

try
{
if (!await control.InvokeHidingAsync())
return false;
}
// TODO: allow deferrals
if (SheetRoot.Child is SheetControl control)
{
if (!await control.InvokeHidingAsync())
return false;
}

VisualStateManager.GoToState(this, "Closed", true);
VisualStateManager.GoToState(this, "Closed", true);

var safeAreaService = Ioc.Default.GetRequiredService<ISafeAreaService>();
safeAreaService.SafeAreaUpdated -= OnSafeAreaUpdated;
var safeAreaService = Ioc.Default.GetRequiredService<ISafeAreaService>();
safeAreaService.SafeAreaUpdated -= OnSafeAreaUpdated;

var systemNavigationManager = SystemNavigationManager.GetForCurrentView();
systemNavigationManager.BackRequested -= OnBackRequested;
var systemNavigationManager = SystemNavigationManager.GetForCurrentView();
systemNavigationManager.BackRequested -= OnBackRequested;

return true;
return true;
}
finally
{
_hideSemaphore.Release();
}
}

private void OnSafeAreaUpdated(object sender, SafeAreaUpdatedEventArgs e)
Expand Down

0 comments on commit 9fab5b8

Please sign in to comment.