How to use the expo-sensors.Accelerometer.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 expo / expo / apps / native-component-list / src / screens / AccelerometerScreen.tsx View on Github external
async componentDidMount() {
    if (!(await Accelerometer.isAvailableAsync())) {
      this.setState({
        error:
          'Cannot start demo!' +
          '\nEnable device orientation in Settings > Safari > Motion & Orientation Access' +
          '\nalso ensure that you are hosting with https as DeviceMotion is now a secure API on iOS Safari.',
        isSetup: false,
      });
      return;
    }

    Accelerometer.addListener(({ x, y }) => {
      this.state.items.forEach((_, index) => {
        // All that matters is that the values are the same on iOS, Android, Web, ect...

        const { perspective } = this.props;
        const nIndex = index + 1;

        Animated.spring(this.state.items[index].position, {
          toValue: {
            x: (Number(x.toFixed(1)) * perspective * nIndex) / COUNT,
            y: (-y.toFixed(1) * perspective * nIndex) / COUNT,
          },
          friction: 7,
        }).start();
      });
    });
github expo / expo / apps / storybook / stories / APIs / Accelerometer.stories.jsx View on Github external
_subscribe = () => {
    this._subscription = Accelerometer.addListener(accelerometerData => {
        this.setState({ accelerometerData });
    });
  };
github janaagaard75 / expo-and-typescript / src / AccelerometerScreen.tsx View on Github external
private subscribe() {
    this.subscription = Accelerometer.addListener(accelerometerData => {
      this.setState({ accelerometerData });
    });
  }
github byCedric / use-expo / packages / sensors / src / use-accelerometer.ts View on Github external
useEffect(() => {
		if (availability) {
			Accelerometer.isAvailableAsync().then(setAvailable);
		}

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

		return Accelerometer.addListener(setData).remove;
	}, []);
github digidem / mapeo-mobile / src / frontend / sharedComponents / CameraView.js View on Github external
Accelerometer.isAvailableAsync().then(motionAvailable => {
      if (
        !motionAvailable ||
        !this.mounted ||
        this.subscription ||
        AppState.currentState !== "active"
      )
        return;
      Accelerometer.setUpdateInterval(1000);
      this.subscription = Accelerometer.addListener(acc => {
        this.acceleration = acc;
      });
    });
  }
github NervJS / taro / packages / taro-rn / src / api / accelerometer / accelerometer.js View on Github external
function startAccelerometer (opts = {}) {
  const {interval = 'normal', success, fail, complete} = opts
  accCase.interval = interval
  try {
    accCase.listener = Accelerometer.addListener(accCase.callback)
    success && success()
    complete && complete()
  } catch (error) {
    fail && fail()
    complete && complete()
    const res = {errMsg: 'stopAccelerometer failed'}
    return Promise.reject(res)
  }
  Accelerometer.setUpdateInterval(intervalMap[interval])
  return Promise.resolve({errMsg: 'ok'})
}