JSPM

expo-orientation-sensor

2.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q18432F
  • License ISC

Virtual Orientation sensor

Package Exports

  • expo-orientation-sensor

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (expo-orientation-sensor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Expo orientation sensor

Licence Downloads Version GitHub code size

Expo orientation sensor is a javascript library for react native applications managed with expo.
The purpose of this library is to keep track of the phone orientation by providing access to the three Euler Angles:

  • pitch
  • roll
  • yaw

(Look at Orientation)

This virtual sensor uses data form Accelerometer, Magnetometer and Gyroscope fused together by AHRS (using Madgwick algorithm) to calculate the exact orientation

Installation

npm install expo-orientation-sensor

Usage

The usage of this package is very similar to the way you use expo-sensors, with some extra functionalities

import { Orientation } from 'expo-orientation-sensor'
  const [angles, setAngles] = useState({
    yaw: 0,
    pitch: 0,
    roll: 0,
  })
  useEffect(() => {
    const subscriber = Orientation.addListener(data => {
      setAngles(data)
    })
    return () => {
      subscriber.remove()
    }
  }, [])

This code should update state angles every time new measurements are available

Note

You don't have to keep track of all updates, you can call Orientation.getEulerAngles and it will return the latest angles measured.
Keep in mind that if there are no listeners added by Orientation.addListener, or all listeners have been removed The angles will NOT be updated

Demo

snack.expo.dev

Orientation

The image below the pitch, roll and yaw axis and their positive direction

axis

The three axis are fix to the phone reference

Documentation

Orientation.eulerAngles

Returns the latest angles measured.

Note: the angles returned might outdated if no listeners are set.

Orientation.isAvailableAsync()

Returns whether this sensor is available on the device.
Should be true if Accelerometer, Magnetometer and Gyroscope are available.

Orientation.addListener()

Subscribe for updates to the orientation.

Arguments:

  • listener (function): A callback that is invoked when an orientation update is available. When invoked, the listener is provided with the current euler angles.

Returns:

  • A subscription that you can call remove() on when you would like to unsubscribe the listener.

Orientation.removeAllListeners()

Remove all listeners.

Orientation.setUpdateInterval()

Subscribe for updates to the orientation.
Arguments

  • intervalMs (number): Desired interval in milliseconds between gyroscope updates.

Orientation.hasListener

Return a boolean indicating whether there is at least a listener.

Orientation.listenerCount

Returns how many listeners are subscribed.