1.1.0 • Published 6 years ago

asq-react-native-sensors v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

React Native Sensors

React Native bridge to access device sensors.

Installation

Minimum Requirements

react-nativeiOS
0.5010.3

NPM package

npm install asq-react-native-sensors

Getting started

  1. Add node-modules/asq-react-native-sensors/ios/ASQSensors.xcodeproj to your Libraries

  2. Add libASQSensors.a under Link Binary With Libraries in Build Phases

  3. Add $(SRCROOT)/../node_modules/asq-react-native-sensors/ios/ASQSensors to your Header Search Paths in Build Settings

Usage - Gyroscope

import { Gyroscope } from "asq-react-native-sensors";

Gyroscope.isActive

Asynchroneous function to check if Gyroscope is avaliable or already active, resolves promise if Gyroscope is already active, otherwise errors if its not avaliable or is not active.

try {
    await Gyroscope.isActive();
} catch (e) {
    if (e.message === 'Error: NOT_ACTIVE') {
        // If gyroscope is avaliable but not active subscribe
        Gyroscope.setInterval(300)
        Gyroscope.subscribe(callback);
    } else {
        // gyroscope is not avaliable, your logic here
    }
}

Gyroscope.setInterval

Set interval to specify refresh rate of data flow from Gyroscope in ms

Gyroscope.setInterval(100);

Gyroscope.subscribe

Subscribe to gyroscope events, expects callback that handles gyroscope data

Gyroscope.subscribe(callback);

function callback(data) {
  console.log(
    `x: ${data.x}, y: ${data.y}, z: ${data.z}, timestamp: ${data.timestamp}`
  );
}

Gyroscope.unsubscribe

Always unsubscribe from Gyroscope events when they are not needed i.e. in componentWillUnmount

Gyroscope.unsubscribe();
1.1.0

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago