Screen orientation
Allows tracking device screen orientation with Events and Stores.
INFO
Uses Screen Orientation API under the hood
Usage
All you need to do is to create an integration by calling trackScreenOrientation with an integration options:
setup: after this Event all listeners will be installed, and the integration will be ready to use; it is required because it is better to use explicit initialization Event in the application.teardown?: after this Event all listeners will be removed, and the integration will be ready to be destroyed.
ts
import { trackScreenOrientation } from '@withease/web-api';
const { $type, $angle, $portrait, $landscape } = trackScreenOrientation({
setup: appStarted,
});Returns an object with:
$type: Store with current orientation type, one of "portrait-primary", "portrait-secondary", "landscape-primary", or "landscape-secondary"$angle: Store with anumberwhich represents the current orientation angle in degrees$portrait: Store with abooleanwhich states if device is in portrait orientation$landscape: Store with abooleanwhich states if device is in landscape orientation
TIP
It supports @@trigger protocol. Since it allows firing only one Event trackScreenOrientation triggers any updates of $type as a fired in case of @@trigger protocol.
ts
import { trackScreenOrientation } from '@withease/web-api';
somethingExpectsTrigger(trackScreenOrientation);Live demo
Let us show you a live demo of how it works. The following demo displays $type, $angle, $portrait and $landscape values of the current screen orientation. Rotate your device to see how it works.