DeviceMotion
from expo-sensors
provides access to the device motion and orientation sensors. All data is presented in terms of three axes that run through a device. According to portrait orientation: X runs from left to right, Y from bottom to top and Z perpendicularly through the screen from back to front.Android Device | Android Emulator | iOS Device | iOS Simulator | Web |
---|---|---|---|---|
expo install expo-sensors
If you're installing this in a bare React Native app, you should also follow these additional installation instructions.
import { DeviceMotion } from 'expo-sensors';
You should always check the sensor availability before attempting to use it.
DeviceMotion
API is enabled on the device.Settings > Safari > Motion & Orientation Access
. Some devices will also not fire if the site isn't hosted with HTTPS as DeviceMotion
is now considered a secure API. There is no formal API for detecting the status of DeviceMotion
so this API can sometimes be unreliable on web.boolean
denoting the availability of the sensor.0
(portrait), 90
(right landscape), 180
(upside down), -90
(left landscape).remove()
on when you
would like to unsubscribe the listener.