Class WebShare
java.lang.Object
com.vaadin.flow.component.webshare.WebShare
- All Implemented Interfaces:
Serializable
Entry point for the browser's
Web
Share API (
navigator.share). Two entry points:
onClick(Component)— bind a share action to a click gesture. The Web Share API requires a transient user gesture, so the trigger pattern is the only reliable way to invoke it.supportSignal()— feature detection: read whether the current browser exposesnavigator.share, useful for deciding whether to show a share affordance at all.
Button share = new Button("Share");
if (WebShare.supportSignal().peek() == WebShareSupport.SUPPORTED) {
WebShare.onClick(share).share(
ShareContent.create().title("Vaadin").url("https://vaadin.com"));
}
The Web Share API requires a fresh user gesture for each call, so actions
only run during the DOM event that fires the underlying trigger.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Component & ClickNotifier<?>>
WebShareBindingonClick(T component) Registers the given component as a clickable trigger for a share action — the common shape for "Share" buttons.static Signal<WebShareSupport> Returns a read-only signal hinting at whether the Web Share API is available in the current browser for the current UI.static Signal<WebShareSupport> supportSignal(UI ui) Returns a read-only signal hinting at whether the Web Share API is available in the current browser for the given UI.
-
Method Details
-
onClick
Registers the given component as a clickable trigger for a share action — the common shape for "Share" buttons. Equivalent tonew ClickTrigger(component), without making callers reach for the trigger framework's internal types.- Type Parameters:
T- the component type, must implementClickNotifier- Parameters:
component- the component to listen for clicks on, notnull- Returns:
- a new binding that can chain actions to this trigger
-
supportSignal
Returns a read-only signal hinting at whether the Web Share API is available in the current browser for the current UI. The value is seeded from the bootstrap handshake, so user code observes a real value before any view code runs.Web Share support is established at page load and does not change during the session, so the signal effectively transitions
UNKNOWN→SUPPORTED/UNSUPPORTEDonce and then remains stable.Use this to decide whether to show a share affordance at all — calling a share action when the value is
WebShareSupport.UNSUPPORTEDsilently rejects in the browser.- Returns:
- the read-only support signal
- Throws:
IllegalStateException- if there is no current UI
-
supportSignal
Returns a read-only signal hinting at whether the Web Share API is available in the current browser for the given UI. Same semantics assupportSignal(); use this overload from background threads or anywhereUI.getCurrent()is unreliable.- Parameters:
ui- the UI to read the hint from, notnull- Returns:
- the read-only support signal
- Throws:
NullPointerException- ifuiisnull
-