Class Fullscreen

java.lang.Object
com.vaadin.flow.component.fullscreen.Fullscreen
All Implemented Interfaces:
Serializable

public final class Fullscreen extends Object implements Serializable
Entry point for the browser Fullscreen API.

To enter fullscreen, bind a request to a user gesture via onClick(Component) — the browser requires transient user activation for each request, so the call only runs during the DOM event that fires the underlying trigger:


 Button fullscreenButton = new Button("Fullscreen");
 Fullscreen.onClick(fullscreenButton).enter(); // whole page
 Fullscreen.onClick(fullscreenButton).enter(videoPanel); // single component
 
To leave fullscreen, call exit(); to observe the current state, subscribe to stateSignal(). Neither needs a user gesture.
See Also:
  • Method Details

    • onClick

      public static <T extends Component & ClickNotifier<?>> FullscreenBinding onClick(T component)
      Registers the given component as a clickable trigger for a fullscreen request — the common shape for fullscreen buttons. Equivalent to new ClickTrigger(component), without making callers reach for the trigger framework's internal types.
      Type Parameters:
      T - the component type, must implement ClickNotifier
      Parameters:
      component - the component to listen for clicks on, not null
      Returns:
      a new binding that can chain a fullscreen request to this trigger
    • stateSignal

      public static Signal<FullscreenState> stateSignal()
      Returns a read-only signal that tracks the browser's fullscreen state for the current UI.

      The signal distinguishes between FULLSCREEN (the page is currently in fullscreen), NOT_FULLSCREEN (fullscreen is supported but the page is not in it), UNSUPPORTED (the browser does not support fullscreen or the document is not permitted to enter it), and UNKNOWN (the initial value, replaced with a real one before any user code observes the signal).

      The signal value is seeded from the initial client bootstrap, so user code always sees a real value. Subscribe with Signal.effect(owner, ...) to react to changes; call stateSignal().peek() for a snapshot outside a reactive context, and .get() inside one.

      Example: toggle a CSS class while fullscreen

      
       viewLayout.bindClassName("is-fullscreen",
               Fullscreen.stateSignal().map(s -> s == FullscreenState.FULLSCREEN));
       
      Example: react to state changes with a side effect
      
       Signal.effect(this, () -> {
           if (Fullscreen.stateSignal().get() == FullscreenState.UNSUPPORTED) {
               fullscreenButton.setVisible(false);
           }
       });
       
      Returns:
      the read-only fullscreen signal for the current UI
      Throws:
      IllegalStateException - if there is no current UI
    • exit

      public static void exit()
      Exits fullscreen mode for the current UI if the page is currently in fullscreen; otherwise a no-op. The current state can be observed via stateSignal().

      If a component was previously fullscreened via FullscreenBinding.enter(Component), it is automatically restored to its original position in the DOM.

      Throws:
      IllegalStateException - if there is no current UI
    • setStateFromClient

      public static void setStateFromClient(UI ui, String value)
      Sets the fullscreen state of the given UI from a raw client-side value (e.g. from the initial bootstrap parameters). null and unknown values are ignored.

      Called from the bootstrap path in ExtendedClientDetails that seeds the signal before any user code observes it. Not intended for application code.

      Parameters:
      ui - the UI whose fullscreen state to seed, not null
      value - the raw value, or null