The mobile device orientation. include request permission and return 3 axis value.
npm install lesca-sensor-orientation






full steps for get mobile 3 axis value of mobile orientation.
See
#### Live Demo
``sh`
npm install lesca-sensor-orientation --save
As a Node module:
`JSX
import { useState, useEffect, useMemo } from 'react';
import Orientation from 'lesca-sensor-orientation';
// (1) waiting for permission => Must be user-triggered event and SSL required
// (2) add addEventListener
const Components = () => {
const [state, setState] = useState(false);
const orientation = useMemo(() => new Orientation(), []);
const require_permission = () => {
orientation
.permission()
.then(() => {
// permission granted
setState(true);
})
.catch(() => {
// permission deined
});
};
useEffect(() => {
if (state) {
orientation.addEventListener((e) => {
alert(e);
});
}
return () => {
orientation.destory();
};
}, [state]);
return ;
};
``
| method | description | return |
| :---------------------------------------- | :------------------------: | -----: |
| .permission() | ask user permission | void |
| addEventListener(callback:_function_) | get 3 axis value each time | void |
| .destory() | destory event | void |
| Properties | description | default |
| :---------------------- | :--------------------------: | --------------: |
| disable:_boolean_ | stop / continue event listen | true |
| isSuppord:_boolean_ | permission granted or deined | (read only) |
- TypeScript
- maintain if necessary