0.1.7 • Published 1 year ago

expo-motion-detector v0.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

expo-motion-detector

BEAWARE: This package is still in development and not ready for production use

Package to detect when a user is performing a certain activity like driving. The module is compatible with the expo managed workflow, though not with Expo GO. You can create a development build to stay in the managed workflow.

Installation

npm install expo-motion-detector

Usage

First get the appropriate permissions using your favorite permission manager. For android you need:

android.permission.ACTIVITY_RECOGNITION

for IOS you need:

NSMotionUsageDescription (also known as ios.permission.MOTION)

Then register the event listener, you can add a listener for onStartMotion and onStopMotion:

import {
  DeviceEventEmitter,
} from 'react-native';

const onMotionDetected = async () => {
  // Do something when motion is detected
};
DeviceEventEmitter.addListener('onStartMotion', onMotionDetected);

Then import the package and use it like this:

import {
  startActivityRecognition,
  MotionConstants,
} from 'expo-motion-detector';

startActivityRecognition(MotionConstants.Android.WALKING).then((result) => {
    console.log(result);
  }
);

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library