Taro.onDeviceMotionChange(callback)
Listens on the device orientation change event. The frequency is based on the Taro.startDeviceMotionListening() interval parameter. You can use Taro.stopDeviceMotionListening() stop listening.
Type
(callback: Callback) => void
Parameters
Callback
The callback function for the device orientation change event.
(result: CallbackResult) => void
| Property | Type |
|---|---|
| result | CallbackResult |
CallbackResult
| Property | Type | Description |
|---|---|---|
| alpha | number | When the phone coordinate X/Y and the earth coordinate X/Y coincide, the angle of rotation around the Z axis is alpha. The range is [0, 2*PI). It is positive when the phone rotates counterclockwise. |
| beta | number | When the phone coordinate Y/Z and the earth coordinate Y/Z coincide, the angle of rotation around the X axis is beta. The range is [-1*PI, PI). It is positive when the phone rotates with its top toward the earth surface or the user. |
| gamma | number | When the phone coordinate X/Z and the earth coordinate X/Z coincide, the angle of rotation around the Y axis is gamma. The range is [-1*PI/2, PI/2). It is positive when the phone rotates with its right side toward the earth surface. |
API Support
| API | WeChat Mini-Program | H5 | React Native |
|---|---|---|---|
| Taro.onDeviceMotionChange | ✔️ | ✔️ | ✔️ |