Fix incorrect count tracking when notification is manually disposed

This commit is contained in:
Dean Herbert
2022-09-05 19:20:01 +09:00
parent 229e1a8ef7
commit 0514c96191
2 changed files with 25 additions and 1 deletions

View File

@ -57,6 +57,19 @@ namespace osu.Game.Tests.Visual.UserInterface
AddUntilStep("wait overlay not present", () => !notificationOverlay.IsPresent); AddUntilStep("wait overlay not present", () => !notificationOverlay.IsPresent);
} }
[Test]
public void TestPresenceWithManualDismiss()
{
AddAssert("tray not present", () => !notificationOverlay.ChildrenOfType<NotificationOverlayToastTray>().Single().IsPresent);
AddAssert("overlay not present", () => !notificationOverlay.IsPresent);
AddStep(@"post notification", sendBackgroundNotification);
AddStep("click notification", () => notificationOverlay.ChildrenOfType<Notification>().Single().TriggerClick());
AddUntilStep("wait tray not present", () => !notificationOverlay.ChildrenOfType<NotificationOverlayToastTray>().Single().IsPresent);
AddUntilStep("wait overlay not present", () => !notificationOverlay.IsPresent);
}
[Test] [Test]
public void TestCompleteProgress() public void TestCompleteProgress()
{ {

View File

@ -97,6 +97,8 @@ namespace osu.Game.Overlays
public void Post(Notification notification) public void Post(Notification notification)
{ {
notification.Closed += stopTrackingNotification;
++runningDepth; ++runningDepth;
displayedCount++; displayedCount++;
@ -139,14 +141,23 @@ namespace osu.Game.Overlays
notification.MoveToOffset(new Vector2(400, 0), NotificationOverlay.TRANSITION_LENGTH, Easing.OutQuint); notification.MoveToOffset(new Vector2(400, 0), NotificationOverlay.TRANSITION_LENGTH, Easing.OutQuint);
notification.FadeOut(NotificationOverlay.TRANSITION_LENGTH, Easing.OutQuint).OnComplete(_ => notification.FadeOut(NotificationOverlay.TRANSITION_LENGTH, Easing.OutQuint).OnComplete(_ =>
{ {
notification.Closed -= stopTrackingNotification;
if (!notification.WasClosed)
stopTrackingNotification();
RemoveInternal(notification, false); RemoveInternal(notification, false);
displayedCount--;
ForwardNotificationToPermanentStore?.Invoke(notification); ForwardNotificationToPermanentStore?.Invoke(notification);
notification.FadeIn(300, Easing.OutQuint); notification.FadeIn(300, Easing.OutQuint);
}); });
} }
private void stopTrackingNotification()
{
Debug.Assert(displayedCount > 0);
displayedCount--;
}
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();