asq-react-native-sensors
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

React Native Sensors

React Native bridge to access device sensors.

Installation

Minimum Requirements

react-native iOS
0.50 10.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();

Package Sidebar

Install

npm i asq-react-native-sensors

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

17.8 kB

Total Files

8

Last publish

Collaborators

  • iljaasimetriq