Package org.vaadin.firitin.util
Class PageVisibility
java.lang.Object
org.vaadin.firitin.util.PageVisibility
Utility class to check the visibility state of the current page in a Vaadin application.
It provides methods to determine if the page is visible, focused, or hidden.
This class uses JavaScript to interact with the browser's visibility API and adds some helpful extra data via `document.hasFocus()` method. This allows it to determine not only hidden tabs, but also tabs that are visible but not focused (and thus often behind another browser window or application).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static enum
-
Method Summary
Modifier and TypeMethodDescriptioncom.vaadin.flow.shared.Registration
Adds a listener for visibility change events on the page.static PageVisibility
get()
static PageVisibility
get
(com.vaadin.flow.component.UI ui) Checks the visibility state of the current page.
-
Method Details
-
get
-
get
-
isVisible
Checks the visibility state of the current page.This method returns a CompletableFuture that resolves to one of the
PageVisibility.Visibility
enum values, indicating whether the page is visible, focused, or hidden.- Returns:
- a CompletableFuture containing the visibility state of the page
-
addVisibilityChangeListener
public com.vaadin.flow.shared.Registration addVisibilityChangeListener(PageVisibility.PageVisibilityListener listener) Adds a listener for visibility change events on the page. In the browser, this is uses both the `visibilitychange` event and the `blur` and `focus` events to determine the visibility and focusing state of the page.- Parameters:
listener
- the listener to be notified when the visibility state changes.- Returns:
- a DomListenerRegistration that can be used to remove the listener later.
-