Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
useEffect(() => {
if (availability) {
DeviceMotion.isAvailableAsync().then(setAvailable);
}
if (options.interval !== undefined) {
DeviceMotion.setUpdateInterval(options.interval);
}
return DeviceMotion.addListener(setData).remove;
}, []);
function startDeviceMotionListening (object = {}) {
const {interval = 'normal', success, fail, complete} = object
devMotionCase.interval = interval
try {
devMotionCase.listener = DeviceMotion.addListener((res) => {
const {rotation} = res
devMotionCase.callback && devMotionCase.callback(rotation)
})
success && success()
complete && complete()
} catch (error) {
fail && fail()
complete && complete()
const res = {errMsg: 'startDeviceMotionListening failed'}
return Promise.reject(res)
}
DeviceMotion.setUpdateInterval(intervalMap[interval] || intervalMap.normal)
return Promise.resolve({errMsg: 'ok'})
}