---
name: "onDeviceMotionChange"
mode: "kit"
versionRequirements:
  - { name: "BaseKit", version: "2.3.2" }
  - { name: "@ray-js/ray", version: "0.3.23" }
platform:
  - "iOS"
  - "Android"
async: true
---

## onDeviceMotionChange

> [VERSION] BaseKit >= 2.3.2 | @ray-js/ray >= 0.3.23

> [PLATFORM] iOS, Android

> ⚡ **Supports Promise** — Returns a Promise when success / fail / complete callbacks are omitted.

### Description

Listen for device orientation changes (data is returned by the system; accuracy may differ between iOS and Android)

### Parameters

`(listener: Function)`

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `listener` | `(params: Object) => void` | Yes | - |  |

##### onDeviceMotionChange.listener(params) properties

| Property | Type | Required | Default | Since | Description |
| --- | --- | --- | --- | --- | --- |
| `alpha` | `number` | Yes | - | `2.3.2` | When the phone’s X/Y axes align with the Earth’s X/Y axes, the rotation angle around the Z axis is alpha, in the range [0, 2*PI). Counterclockwise is positive. |
| `beta` | `number` | Yes | - | `2.3.2` | When the phone’s Y/Z axes align with the Earth’s Y/Z axes, the rotation angle around the X axis is beta, in the range [-1*PI, PI). The top rotating toward the Earth’s surface is positive; in some cases, rotating toward the user may also be positive. |
| `gamma` | `number` | Yes | - | `2.3.2` | When the phone’s X/Z axes align with the Earth’s X/Z axes, the rotation angle around the Y axis is gamma, in the range [-1*PI/2, PI/2). The right side rotating toward the Earth’s surface is positive. |
| `isParamCorrection` | `boolean` | Yes | - | `3.36.0` | iOS only; whether to correct the alpha value |


### Examples

#### Demo

```tsx
import { startDeviceMotionListening, onDeviceMotionChange } from '@ray-js/ray'

// Device motion events require enabling listening first; start then register.
startDeviceMotionListening({ interval: "normal" });

onDeviceMotionChange(e => {
  console.log(e);
});
```
