Skip to content

Commit

Permalink
if notification gets destroyed dont continue to hold references
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Jun 11, 2024
1 parent f61da3c commit 5dc4c93
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions haxe/ui/notifications/NotificationManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class NotificationManager extends EventDispatcher<NotificationEvent> {
}

var notification = new Notification();
notification.registerEvent(UIEvent.DESTROY, onNotificationDestroyed);
notification.notificationData = notificationData;
if (!_isAnimating) {
pushNotification(notification);
Expand All @@ -102,6 +103,15 @@ class NotificationManager extends EventDispatcher<NotificationEvent> {
popNotification(notification);
}

private function onNotificationDestroyed(event:UIEvent) {
// notifications could actually be destroyed in a variety of ways (like removing directly from Screen)
// if that is the case, lets clean up after ourselves and reset our internal state (if required)
_currentNotifications.remove(cast event.target);
if (_currentNotifications.length == 0) {
_isAnimating = false;
}
}

public function clearNotifications():Void {
for (notification in _currentNotifications) {
removeNotification(notification);
Expand Down

0 comments on commit 5dc4c93

Please sign in to comment.