Class ShareAction
- All Implemented Interfaces:
Serializable
navigator.share when the
bound trigger fires. Supports any combination of title, text,
and url payload slots; at least one slot must be set ? the Web Share
API rejects a call with an empty payload.
The Web Share API requires the call to happen inside a short-lived user
gesture (click, key press, ...). Bind this action to a trigger that fires
during such a gesture, typically a ClickTrigger. The share sheet
itself acts as the user-facing confirmation; the browser also rejects calls
made outside a gesture.
Outcome handling extends PromiseAction: use the no-callbacks
constructor for fire-and-forget, or the overload taking
onShared/onError. onShared fires after the user
dismisses the sheet by sharing; onError fires for both true failures
(no gesture, permissions policy block) and for the AbortError the
browser reports when the user dismisses the sheet without picking a target.
For internal use only. May be renamed or removed in a future release.
- Since:
- 25.2
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.trigger.internal.PromiseAction
PromiseAction.ErrorNested classes/interfaces inherited from class com.vaadin.flow.component.trigger.internal.Action
Action.Input<T> -
Constructor Summary
ConstructorsConstructorDescriptionShareAction(@Nullable Action.Input<String> titleInput, @Nullable Action.Input<String> textInput, @Nullable Action.Input<String> urlInput) Creates a fire-and-forget share action.ShareAction(@Nullable Action.Input<String> titleInput, @Nullable Action.Input<String> textInput, @Nullable Action.Input<String> urlInput, SerializableRunnable onShared, SerializableConsumer<PromiseAction.Error> onError) Creates a share action whose outcome is reported back to the server. -
Method Summary
Modifier and TypeMethodDescriptionprotected JsFunctiontoPromiseJs(Trigger trigger) Subclasses return aJsFunctionthat, when invoked with the trigger's event, evaluates to aPromise.Methods inherited from class com.vaadin.flow.component.trigger.internal.PromiseAction
toJsMethods inherited from class com.vaadin.flow.component.trigger.internal.Action
warnIfNotVisible
-
Constructor Details
-
ShareAction
public ShareAction(@Nullable Action.Input<String> titleInput, @Nullable Action.Input<String> textInput, @Nullable Action.Input<String> urlInput) Creates a fire-and-forget share action.- Parameters:
titleInput- input producing thetitlefield, ornullto omittextInput- input producing thetextfield, ornullto omiturlInput- input producing theurlfield, ornullto omit- Throws:
IllegalArgumentException- if all three inputs arenull
-
ShareAction
public ShareAction(@Nullable Action.Input<String> titleInput, @Nullable Action.Input<String> textInput, @Nullable Action.Input<String> urlInput, SerializableRunnable onShared, SerializableConsumer<PromiseAction.Error> onError) Creates a share action whose outcome is reported back to the server.- Parameters:
titleInput- input producing thetitlefield, ornullto omittextInput- input producing thetextfield, ornullto omiturlInput- input producing theurlfield, ornullto omitonShared- invoked on the UI thread after the client reports the share resolved, notnullonError- invoked on the UI thread with the browser's error after the client reports the share rejected ? typicallyAbortErrorwhen the user dismissed the sheet, notnull- Throws:
IllegalArgumentException- if all three inputs arenull
-
-
Method Details
-
toPromiseJs
Description copied from class:PromiseActionSubclasses return aJsFunctionthat, when invoked with the trigger's event, evaluates to aPromise. The value the promise resolves with is decoded toTon the server and handed toonSuccess. To deliver a typed value, subclasses can wrap their API call in an IIFE inside the function body ? for example, copying a string and resolving with it:return JsFunction.of( "return ((v) => navigator.clipboard.writeText(v).then(() => v))($0(event))", textInput.toJs(trigger)).withArguments("event");- Specified by:
toPromiseJsin classPromiseAction<Void>- Parameters:
trigger- the surrounding trigger this render is for, notnull- Returns:
- the promise-yielding JS function, not
null
-