Mikael Romanus
Mikael Romanus

Reputation: 51

Detecting a shake device event with react-native-sensors?

I'm looking for a way to detect when the user shakes their device to trigger a function in my react-native app. There's an "accelerator" sensor in react-native-sensors which I could probably use. Does anyone have experience with building such a thing? Any guidance would be appreciated.

https://react-native-sensors.github.io/docs/API.html

import { accelerometer } from "react-native-sensors";

const subscription = accelerometer.subscribe(({ x, y, z, timestamp }) =>
  console.log({ x, y, z, timestamp })
);

Upvotes: 2

Views: 9565

Answers (1)

Aureo Beck
Aureo Beck

Reputation: 749

There are a few options, checkout react-native-shake for example.

Upvotes: 3

Related Questions