Skip to content

Commit

Permalink
by default notifications should close when actions are performed
Browse files Browse the repository at this point in the history
  • Loading branch information
ianharrigan committed Dec 14, 2023
1 parent 032192e commit cc724d0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions haxe/ui/notifications/Notification.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ class Notification extends VBox {
super();

closeButton.onClick = function(_) {
NotificationManager.instance.removeNotification(this);
hide();
}
}

public override function hide() {
NotificationManager.instance.removeNotification(this);
}

private var _notificationData:NotificationData = null;
public var notificationData(get, set):NotificationData;
private function get_notificationData():NotificationData {
Expand Down Expand Up @@ -87,14 +91,26 @@ class Notification extends VBox {
}

private function onActionButton(event:MouseEvent) {
var closeNotification = true;

var notificationEvent = new NotificationEvent(NotificationEvent.ACTION);
notificationEvent.notification = this;
dispatch(notificationEvent);
if (notificationEvent.canceled) {
closeNotification = false;
}
NotificationManager.instance.dispatch(notificationEvent, this);
if (notificationEvent.canceled) {
closeNotification = false;
}

var actionData:NotificationActionData = event.target.userData;
if (actionData.callback != null) {
actionData.callback(actionData);
closeNotification = actionData.callback(actionData);
}

if (closeNotification) {
hide();
}
}
}
2 changes: 1 addition & 1 deletion haxe/ui/notifications/NotificationData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ typedef NotificationData = {
typedef NotificationActionData = {
@:optional var text:String;
@:optional var icon:Variant;
@:optional var callback:NotificationActionData->Void;
@:optional var callback:NotificationActionData->Bool;
}

0 comments on commit cc724d0

Please sign in to comment.