How to use the expo-sensors.DeviceMotion.addListener function in expo-sensors

To help you get started, we’ve selected a few expo-sensors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github byCedric / use-expo / packages / sensors / src / use-device-motion.ts View on Github external
useEffect(() => {
		if (availability) {
			DeviceMotion.isAvailableAsync().then(setAvailable);
		}

		if (options.interval !== undefined) {
			DeviceMotion.setUpdateInterval(options.interval);
		}

		return DeviceMotion.addListener(setData).remove;
	}, []);
github NervJS / taro / packages / taro-rn / src / api / device / deviceMotion.js View on Github external
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'})
}