Popup message using Notifications can't auto hide without user interaction?

Hi,

I used “Notifications” interface to pop some “tray” message:

@EventListener
public void onUserMessageEvent(UserMessageEvent event) {
    notifications.create().withCaption(event.message)
            .withType(Notifications.NotificationType.TRAY)
            .withHideDelayMs(3000)
            .show();
}

The code above is triggered by a device automatically, there are no any interaction(mouse click\key press etc.),
In this case,the pop-up message will not be hide automatically till i move the mouse.

Is this a bug?

Hello @lugreen

This is not a bug in the usual sense. The problem is that API confuses - in fact “hide delay” configures a delay after user interaction, but not after notification is shown.

But you can manually “hide” all notifications:

AppUI appUI = AppUI.getCurrent();
List<Notification> notifications = appUI.getExtensions()
        .stream()
        .filter(ext -> ext instanceof Notification)
        .map(ext -> (Notification) ext)
        .collect(Collectors.toList());

notifications.forEach(Notification::close);

Regards,
Daniil

Hi Daniil ,

Thanks very much, the explain is useful .

But ,how can i hide a notification after some delay?
I think i need to get a notification instance’s reference,and use a timer to hide it manually,how can i get the notification instance that i created? If the Notifications interface can return the Notification instance ,it will be simple.

Or you have better approach?

Ray.Lv
Regards.

I’ve shared a snippet above to hide all notifications.

You can add some custom logic if you need.

Hi Daniil,

Thanks.