Coder Social home page Coder Social logo

react-native-sensors / react-native-sensors Goto Github PK

View Code? Open in Web Editor NEW
887.0 17.0 226.0 3.82 MB

A developer friendly approach for sensors in React Native

Home Page: https://react-native-sensors.github.io/

License: MIT License

Java 8.42% JavaScript 16.54% Objective-C 40.38% Ruby 0.76% Shell 0.71% CSS 0.78% C++ 32.39%
react-native sensor gyroscope acceleration rxjs magnetometer barometer

react-native-sensors's Introduction


React Native Sensors

NPM downloads NPM version Build Status semantic-release All Contributors .github/workflows/website.yml

Supported React Native Versions

React Native Version react-native-sensors Version
>= 0.60 >= 7.0
>= 0.40, < 0.60 >= 1.0, < 7.0
<= 0.39 < 1.0

Documentation

Please visit our website for the documentation.

Cool Projects using react-native-sensors

Do you want your project listed here? Just send a PR.

Changelog

Please see the changelog here

Credits

This project is inspired by the react-native-sensor-manager and by the react-native-motion-manager. Both have similar solutions with a non-uniform interface and this project aims to unify both.

Contributing

  • We use semantic-release for the deployment of new versions, so please stick to this format

Contributors

Thanks goes to these wonderful people (emoji key):

Daniel Schmidt
Daniel Schmidt

πŸ’»
Noitidart
Noitidart

πŸ“–
Christophe Lemonnier
Christophe Lemonnier

πŸ’»
Gennady
Gennady

πŸ“–
Jiaming Lu
Jiaming Lu

πŸ’»
Alex Wasner
Alex Wasner

πŸ’»
Nam Đàm
Nam Đàm

πŸ’»
Mike Knapp
Mike Knapp

πŸ’»
Kevin Gonnord
Kevin Gonnord

πŸ’»
ImAtome
ImAtome

πŸ’»
Lisa Huynh
Lisa Huynh

πŸ’»
Cory Smith
Cory Smith

πŸ’»
Esa-Matti Suuronen
Esa-Matti Suuronen

πŸ’»
Viet Nguyen
Viet Nguyen

πŸ’»
Simon Bengtsson
Simon Bengtsson

πŸ’»
maxkomarychev
maxkomarychev

πŸ’»
Alexander Baygeldin
Alexander Baygeldin

πŸ’»
Noane Dan
Noane Dan

πŸ’»
David Escalera
David Escalera

πŸ’¬ πŸ’»
Ethan Neff
Ethan Neff

πŸ’»
Manuel Alabor
Manuel Alabor

πŸ’»
Michael ElsdΓΆrfer
Michael ElsdΓΆrfer

πŸ’»
jmichalc
jmichalc

πŸ’»
Adrian Carolli
Adrian Carolli

πŸ› πŸ’»
Jesse Degger
Jesse Degger

πŸ’»
quoc1506
quoc1506

πŸ›
Joshua Jenkins
Joshua Jenkins

πŸ›
gonglowbat
gonglowbat

πŸ›
Daniel Banck
Daniel Banck

πŸ’» ⚠️
jan-happy
jan-happy

πŸ“–
Isaac Besora Vilardaga
Isaac Besora Vilardaga

πŸ“–
Roberto Wesley Overdijk
Roberto Wesley Overdijk

πŸ› πŸ’»
Markus Reiter
Markus Reiter

πŸ’»
wesdewitte
wesdewitte

πŸ’»
Jonathan Boellke
Jonathan Boellke

πŸ’»
Ehsan Hejazi
Ehsan Hejazi

πŸ’» πŸ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

react-native-sensors's People

Contributors

bqrichards avatar charlesmangwa avatar danielmschmidt avatar dannoane avatar dbanck avatar ehsan0hejazi avatar ethanneff avatar gramotei avatar iijoshjenkins avatar jfkm69 avatar jorgengranseth avatar junhoyeo avatar kasinskas avatar lisaah avatar lleios avatar mikeknapp avatar miracle2k avatar nam-dam avatar noitidart avatar organom avatar reitermarkus avatar renovate-bot avatar renovate[bot] avatar rubina-shakhkyan avatar rwoverdijk avatar simonbengtsson avatar stylejs-bot avatar swissmanu avatar wesdewitte avatar xploseof avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-sensors's Issues

Sensor fusion sensor

What is the purpose of this sensor?
Working with raw sensor data from compass, accelerometer, tilt sensors is notoriously bad :)

Rather than having users have to create their own sensor fusion for driftless attitude provide a pre-baked sensor written in Native code for speed. Here's an example in javascript but there's plenty around for java/obj-c

https://github.com/borismus/sensor-fusion

Is it supported on both iOS and Android?
Yes - fusion of other sensors.

Is there a way to test this sensor without a real device?
Yes - simulator/emulator

Would you be willing to respond to issues / PRs for this sensor?
Unsure - I'm unlikely to be able to implement it. This is a request

iOS and Android results decimal

The X and Y axis doesn't share the same decimals on Android and iOS. This is fairly simple to handle outside of the plugin but I feel like this should be handled by the plugin.

Also the Z axis doesn't return the same values on Android and iOS, but I don't think this is an issue with this plugin.

Android

Object {x: -0.1454315185546875, y: -0.1233978271484375, z: 9.813604736328125}
Object {x: -0.1454315185546875, y: -0.1233978271484375, z: 9.813604736328125}
Object {x: -0.14489898681640626, y: -0.12292327880859374, z: 9.813818359375}

iOS

Object {x: 0.00493927001953125, y: 0.01236572265625, z: -1.0119964599609375}
Object {x: 0.00518798828125, y: 0.01222076416015625, z: -1.01226806640625}
Object {x: 0.0051116943359375, y: 0.0124603271484375, z: -1.0126296997070312}

Thank you!

then is undefined

Hello,

I will assume there is something small I'm missing but I can't get my accelerometer to work.

import React, {Component} from 'react';
import {
    Platform,
    StyleSheet,
    Text,
    View
} from 'react-native';
import {StackNavigator} from 'react-navigation';
import {Accelerometer} from 'react-native-sensors';
import {Button} from 'react-native-elements';

export default class HomeScreen extends React.Component {


    constructor() {

        super();

    }

    componentDidMount() {
        let accelerationObservable;

        new Accelerometer({updateInterval: 200,})
            .then((observable) => {
            console.log("Yep");
        });
    }

    render() {
        return (
            <View>

                <Text>Benjamin!</Text>
            </View>
        )
    }
}

My error is 'new _reactNativeSensors.Accelerometer({updateInterval:200}).then is undefined'

Thanks

background tasks support

Hey there !

I don't know how it works for android & ios, but for the uwp, I already developed it for windows and it seems to work.

Any plan to support background tasks ?

Subscribe to Sensor while app is closed

To begin with: the accelerometer from the react-native-sensors repo works like a charm when the app is running in the foreground or when the app is still open in the background. However, based on the documentation I am not able to figure out whether a certain feature is available, namely persistently subscribe to the accelerometer-sensor when the app is closed. Is it possible to subscribe to a sensor such that it continues to measure when an app is closed?

Sensor options overwrite existing ones

Describe the bug
Newer instances of Sensor update intervals change the intervals of existing sensors on Java (maybe also on iOS)

To Reproduce
Steps to reproduce the behavior:

const a = new Accelerometer({updateInterval: 1000});
const b = new Gyroscope({updateInterval: 42});

Both a and b will emit every 42ms because we are talking to one underlying API.

Expected behavior

First resolution step: Document the current behavior in the README
Second step: Expose a global function to set the interval and remove the option from the sensors,

Desktop (please complete the following information):

  • React Native Version: -
  • Device [e.g. real iOS device, android simu]: -
  • Version [e.g. 3.0.0-rc.2]: All

Additional context

Please Help Error= Declare Accelerometer at componentDidMount()

componentDidMount() {
    let accelerationObservable;

    new Accelerometer({
      updateInterval: 100, // defaults to 100ms
    }).then((result) => {
      accelerationObservable = result;
      accelerationObservable
          .map(({ x, y, z }) => x + y + z)
          .filter(speed => speed > 20)
          .subscribe(({x,y,z})=>(this.state.vx.setValue(this.getOffset(x))));
    });
}
ERROR:
TypeError: undefined is not a constructor(evaluating 'new _3.Accelerometer({updateInterval: 100})')

Please Help

[ios] Too much logging

Accelerometer updates are being logged several times a second, making the console entirely useless for anything else. Could we make this logging optional please? Thanks a lot!

iOS flash back

when i use
new Accelerometer({
updateInterval: 400
})

Gyroscope is undefined at first render

Hello,

It seems that this.props.Gyroscope is undefined at first render maybe because its initialization happens some ms after render, however I would like to know how should I correctly handle this behavior, something like that maybe ?

render() {
   if(this.props.Gyroscope)
     return (<Foo/>);
   else
     return null;
}

Thanks,

Use sensorEvent.timestamp instead of system time in Android

Currently the implementation in Android for both Gyroscope and Accelerometer uses a call to System.currentTimeMillis() to get the timstamp for the sensor data.

Instead the more accurate timestamp from the sensorEvent should be used. This data can be retrieved from sensorEvent.timestamp This is also in accordance with the implementation for iOS.

Do note that the timestamp retrieved from the sensorEvent is given in ns instead of ms, to keep current timestamp format this value needs to be divided by 1 000 000.

See:
https://developer.android.com/reference/android/hardware/SensorEvent.html#timestamp

Do you support Light Sensor ?

I need a library that include light sensor component for iOS and Android. Can you give me a hand for this issue ?

Error when build iOS

Describe the bug
I have error when build on Xcode

/node_modules/react-native-sensors/ios/Magnetometer.m:41:27: error: too many arguments to block call, expected 1, have 3
            reject(@"-1", @"Magnetometer is not active", [[NSError alloc] init]);
            ~~~~~~        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/node_modules/react-native-sensors/ios/Magnetometer.m:46:23: error: too many arguments to block call, expected 1, have 3
        reject(@"-1", @"Magnetometer is not available", [[NSError alloc] init]);
        ~~~~~~        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.

To Reproduce
Steps to reproduce the behavior:
I install library and link, and add code like example

$ npm install react-native-sensors --save
$ react-native link react-native-sensors
pod 'RNSensors', :path => '../node_modules/react-native-sensors'

  • React Native Version: 55.4
  • Mac OS X: 10.12.6
  • XCode: 9.2
  • Device iPhone 6

Please help me fix/show me how to fix this error.

Thanks

Set up prettier

We currently use styleJS which is a nice addition but leads to a lot of breaking PRs and frustration. Let's include prettier somehow else πŸ‘

Accelerometer / Gyroscope are reversed

Everything is in the title !
iOS, Xcode, 0.44 react native, automatic link

import RNSensors from 'react-native-sensors';
import {WidthPercent} from '../utils/SizeManager';
const { Accelerometer, Gyroscope } = RNSensors;

export default class Game extends Component {
	static navigationOptions = {
		header: null,
	}

	constructor(props) {
		super(props);
		this.state = ({anim: new Animated.Value(ViewWidth / 2)});
	}

	componentDidMount () {
		this.Gyro = new Accelerometer({
  			updateInterval: 5,
		});
		this.Gyro.subscribe(({x,y,z})=>(this.state.anim.setValue(this.getOffset(x))));
	}

Thanks !

Version 3

Hey there,

I would like to release version 3 with a whole lot of bug fixes and new features. These are the PRs that went into it:

First of all, I would like to thank you a lot for the effort you put into this and for keeping up with my change requests and slow review times. This is my game plan for this release, feel free to give me some feedback on this:

  1. Publish version 3.0.0-1 and get feedback from you
  2. Wait for Magnetometer to be in master
  3. Publish version 3.0.0-2 and get feedback from you
  4. Publish version 3.0.0

I will start releasing the first new version right now. I am a bit dependant on you to give me feedback, please comment here, so that we can get it shipped together πŸ‘

Cannot run: Getting a TransformError relating to rxjs

I am trying to run this library by following the sample:

import { decorator as sensors } from 'react-native-sensors';

Project doesn't run at all and I get a "TransformError: rxjs/symbol/iterator.js: Property left of AssignmentExpression expected node to be of a type ["LVal"] but instead got a "ConditionalExpression"

Running React Native 0.48

Thanks.

Ambient light sensors

The react-native-sensor-manager project supports the LightSensor api, but it's outdated, so that would be a much needed add on to this project

Tilt calculation with accelerometer data

Hi there,

From just the accelerometer data (because my devices dont have a gyro) I was trying to get the tilt. I was hoping to run this by you all here.

So my goal is to get the pitch and the roll.

At least for portrait orientation I think this is correct:

    const { x, y, z } = Accelerometer;
    const roll = Math.atan2(y, z) * 57.3
    const pitch = Math.atan2((-1*x) , Math.pow((y * y) + (z * z), 0.5)) * 57.3;

As you folks have experience with sensors I am thinking you must have came across this question some point in time. Does my calculation look correct? I based it off of here https://www.dfrobot.com/wiki/index.php/How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing

Thank you

Documentation lacking which sensors are supported

Your examples talk only of the accelerometer and the gyroscope. But the code has the magnometer which I assume is the compass (correct?).

What else is supported?

IOS has the following sensors listed (for different versions)

  1. Proximity sensor
  2. Ambient light sensor (not in 3G)
  3. Camera
  4. Accelerometer
  5. Compass aka Magnetometer or Magnetic Field Sensor (After 3GS)
  6. Gyroscope (Since 4)

Android phones have some or all of the above and some also support:

  1. Thermometer aka Ambient Temperature Sensor
  2. Heart rate
  3. Pressure
  4. Relative humidity.

Are any/all of these supported?

If you answer here I will be glad to suggest a pull request to the README.MD that would clarify this.

Thank you.

Streamline API by removing promises

Is your feature request related to a problem? Please describe.
Returning a promise from a constructor makes the API harder to use, we can remove this layer of abstraction easily.

Describe the solution you'd like

const observable = new Accelerometer(options);
observable.catch(err => {
	// Sensor not available
})

Additional context
This should be a rather small improvement on the JS side of things

Ability to as animation driver with useNativeDriver

Thanks for this awesome module.

I was using it to drive an animation but it is hurting performance. Is there anyway to use it as we use Animation event drivers - https://medium.com/xebia/linking-animations-to-scroll-position-in-react-native-5c55995f5a6e

This connects to scroll of a scroll view:

    const xOffset = new Animated.Value(0);

    const onScroll = Animated.event([{ nativeEvent: { contentOffset: { x: xOffset } } }], { useNativeDriver: true });

    <ScrollView scrollEventThrottle={16} onScroll={onScroll}>
        // ...
    </ScrollView>

Magnetometer not supported

Hello,

I'd like to point out that the Magnetometer is not supported. Using it as a decorator will have no effect, and using it explicitly will throw the following error when instanciated:

undefined is not an object (evaluating 'api.setUpdateInterval')

I tried to fix it, but it appears that the native implementation is still to be coded.

My suggestion for now is to remove the Magnetometer from the exposed API and the README.md in order to avoid leading users into believing it supported. I'd be happy to make a PR for this.

iOS: Simulator crash on Initialization

Describe the bug
On the iOS simulator, there is no support for sensors. When the API is activated via either method, the entire app crashes with no red box.

After debugging in XCode, I have found the error to be due to this line in Accelerometer.m (it is also in the other 2 sensor module files):

- (void) isAvailableWithResolver:(RCTPromiseResolveBlock) resolve
                        rejecter:(RCTPromiseRejectBlock) reject {
    if([self->_motionManager isAccelerometerAvailable])
    {
        /* Start the accelerometer if it is not active already */
        if([self->_motionManager isAccelerometerActive] == NO)
        {
            resolve(@YES);
        } else {
            reject(@"-1", @"Acceletometer is not active", [[NSError alloc] init]);
        }
    }
    else
    {
        reject(@"-1", @"Acceletometer is not available", [[NSError alloc] init]);
    }
}

The crashes are caused by the construction of error via [[NSError alloc] init]. If we change the value to nil, the crash is resolved.

@DanielMSchmidt: I can create a PR to resolve this issue, but I am not confident enough of my Obj-C ability - do you think changing the error call to nil is a sufficient fix?

To Reproduce

  1. Import and copy the sample code (observable or decorator method does not matter)
  2. Run in iOS simulator

Expected behavior
App should not crash when sensor is not found.

Desktop:

  • React Native Version: 0.55.4
  • Device: iOS Simulator
  • Version: 3.0.0

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Preset name not found within published preset config (monorepo:angularmaterial). Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Demo GryoscopeImage does not work

Describe the bug
The demo GryoscopeImage does not work on my real iPhone SE (iOS 11.2.1).
The image does not follow the gyroscope movements.

To Reproduce
Steps to reproduce the behavior:

  1. Launch the demo on a real device
  2. Move your phone around you

Expected behavior
The image has to move

Desktop (please complete the following information):

  • React Native Version: 0.55.4
  • Device iPhone SE (iOS 11.2.1)
  • Version 3.0.0

Additional context
May be instead of using the setState method, we could use an Animated.Value (with Animated.Value.setValue) and interpolate the result to get better performances ?

How to handle different react version?

My react-native version is 0.43.4 which is newer than the required dependency, 0.40. Is there a proper way to handle this situation other than manually installing the older react?

npm install react-native-sensors --save
npm WARN peerDependencies The peer dependency react-native@^0.40.0 included from react-native-sensors will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency 
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.
npm ERR! Linux 4.5.5-300.fc24.x86_64
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "react-native-sensors" "--save"
npm ERR! node v4.7.3
npm ERR! npm  v2.15.11
npm ERR! code EPEERINVALID

npm ERR! peerinvalid The package [email protected] does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants react-native@^0.40.0

Licensing

I was wondering what the licensing is on this repo? I don't see a LICENSE file nor do I see a specification in the package.json, which essentially limits the ability to fork or modify. Please advise. Thanks!

Home page missing in package.json

Because of the lacking home page attribute in the package.json of react native sensors the pod install command fails. Simply going into node_modules/react-native-sensors/package.json and adding one solves this problem.

Heading Compass support

Anyone know how to get the heading compass ?

I try a lot of code to convert accelerometer, but nothing work for the moment.

Any idea on that would be very appreciated.

Thanks !

Docs outdated?

It seems that new Accelerometer() returns a promise of an observable and not the observable directly which the README indicates.

Check device sensors

Hi ! there is a way to check if the device has some sensors? My phone dont have gyroscope and I get a error but my app will be use some features with gyro and other without it, react-native-sensors let me check sensors before start?

Documentation on examples/GyroscopeImage missing

Describe the bug
There is no documentation in examples/GyroscopeImage, which makes it hard to checkout.

Expected behavior

There should be something like this:

  1. Run npm install on the main repo (/ from this project)
  2. Run npm install on the example (/examples/GyroscopeImage)
  3. Start the app like any other react native app (react-native run-ios or react-native run-android)

Additional context
Add any other context about the problem here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.