feat: Add Screen Orientation API support to Page#24327
Open
Artur- wants to merge 9 commits into
Open
Conversation
Expose the browser Screen Orientation API through Page methods, providing a read-only signal for tracking orientation changes and methods to lock/unlock screen orientation for tablet and mobile apps.
Addresses three API gaps surfaced while building use cases against the screen orientation API: - Add ScreenOrientation.isLandscape() / isPortrait() so adaptive layouts do not have to spell out the two-value disjunction. - Add ScreenOrientation.UNSUPPORTED, distinct from UNKNOWN: the client now reports "unsupported" from the bootstrap when screen.orientation is absent, so callers can tell "no data yet" from "the platform will never produce data." - Replace lockOrientation's PendingJavaScriptResult return with the Geolocation.getPosition-style onSuccess/onError callbacks, plus a ScreenOrientationLockError record carrying the DOMException name and message. Rejected lock requests now surface reactively instead of vanishing unless the caller chained .then(...) themselves. A fire-and-forget single-arg overload logs failures at DEBUG.
…lback Adds ExtendedClientDetails#isScreenOrientationSupported() for a synchronous feature-detect (mirrors the Page screen-orientation signal) and a Page#unlockOrientation(SerializableRunnable) overload that fires once the unlock round-trip completes — symmetric with the lockOrientation callbacks.
caalador
reviewed
May 18, 2026
| * | ||
| * @return the read-only screen orientation signal | ||
| */ | ||
| public Signal<ScreenOrientationData> screenOrientationSignal() { |
Contributor
There was a problem hiding this comment.
Should it be getScreenOrientationSignal()
Also does the method name need the Signal at the end as the return type is Signal?
Member
Author
There was a problem hiding this comment.
That is the "standard" in use in Flow
…ation # Conflicts: # flow-client/src/main/frontend/Flow.ts # flow-server/src/main/java/com/vaadin/flow/component/page/ExtendedClientDetails.java
Align the screen orientation API with the WakeLock and Geolocation siblings: surface lock failures as a typed ScreenOrientationLockErrorCode (via ScreenOrientationLockError.errorCode()) so callers can switch on the reason instead of comparing the raw DOMException name string. Also funnel the DOM-event setScreenOrientation overload through the bootstrap one to remove duplicated parse/log logic, matching the single setter shape used by PageVisibility.
Move the screen orientation API off Page into a dedicated static facade in com.vaadin.flow.component.screenorientation, matching the action-bearing browser-API wrappers (Fullscreen, WakeLock, Geolocation) instead of the read-only PageVisibility precedent it previously followed. - ScreenOrientation: static facade (orientationSignal/lock/unlock), mirrors Fullscreen; per-UI state held in ScreenOrientationSupport via ComponentUtil - Rename the ScreenOrientation enum to ScreenOrientationType (matches the W3C OrientationType and frees the ScreenOrientation name for the facade) - New @NullMarked package-info for the package - ExtendedClientDetails seeds via ScreenOrientation.setStateFromClient and reads isScreenOrientationSupported() through the facade signal - Page no longer carries orientation signal/lock/unlock methods
Replace the ScreenOrientationSupport holder with the pattern WakeLock and Geolocation already use (and that DESIGN_GUIDELINES prescribes): keep the ValueSignal on UIInternals with a framework-only setter, and have the ScreenOrientation facade read/write it and wire the DOM listener once via an installed-flag guard. Removes the Fullscreen-style Support class, whose facade did nothing but forward to it.
Artur-
commented
Jun 10, 2026
Artur-
commented
Jun 10, 2026
Address PR review feedback on the screen-orientation lock error API: - The client now maps the DOMException name to a ScreenOrientationLockErrorCode constant before reporting the failure, so the raw browser error name never crosses the wire and Java code only sees terms meaningful to a Java developer. An unmapped exception keeps its name in the debug message so diagnostics are not lost. - ScreenOrientationLockError is now (errorCode, debugInfo), following the GeolocationError naming convention where debugInfo is free-form browser wording meant for logging only. The name() accessor and the enum's domExceptionName()/fromName() plumbing are removed from the public API. - The fire-and-forget unlock() delegates to unlock(callback) instead of duplicating the executeJs call.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Expose the browser Screen Orientation API through Page methods,
providing a read-only signal for tracking orientation changes and
methods to lock/unlock screen orientation for tablet and mobile apps.