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

0.1.2 • Public • Published

react-native-all-sensors

This package provides users access to all the 13 different sensors available in android mobile phones and also provides realtime sensor data.

Why this package?

Because there is no other package that provides access to all the sensors in react native.


(Fingerprint and time delay for sensor parameter will be added in next update, Ios support will be added soon.)


Installation

npm i react-native-all-sensors

Usage

import {start,
        stop,
        isSensorAvailable,
        onSensorChanged,
        removeSensorListener,
        startNow,
        stopNow,
        } 
from 'react-native-all-sensors'

Easy mode

startNow('proximity', (data) => {
  //do something with data
})
//after work is done
stopNow('proximity')//stops sensor


/* ['proximity', 'light', 'accelerometer',
 'magneticField', 'gyroscope',  'gravity',
   'linearAcceleration', 'rotationVector', 
   'ambientTemperature', 'relativeHumidity', 
   'ambientTemperature', 'pressure', 'temperature',
    'orientaion']*/
    

Detailed mode

isSensorAvailable('proximity').then((available) => {
      if (available) {
        start('proximity').then(() => {
            //Do something after sensor started
          onSensorChanged('ProximityData', (data) => {
            //Handle promise with data
          })
        }
        )
      }
    })

    //after work is done 
    removeSensorListener('ProximityData')//stops listening
    stop('proximity')//sensor stops


Available Sensors


"proximity", "light", "accelerometer", "magneticField", "gyroscope", "gravity", "linearAcceleration", "rotationVector", "ambientTemperature", "relativeHumidity", "ambientTemperature", "pressure", "temperature", "orientaion"

Data


"ProximityData", "LightData", "AccelerometerData", "MagneticFieldData", "GyroscopeData", "GravityData", "LinearAccelerationData", "RotationVectorData", "AmbientTemperatureData", "RelativeHumidityData", "AmbientTemperatureData", "PressureData", "TemperatureData", "OrientaionData"

Sample Code

import {startNow,
        stopNow}from 'react-native-all-sensors'

const App = () => {
const [accelerometer, setAccelerometer] = useState({x:0,y:0,z:0})

  return (
    <View>
      <Text>Accelerometer: {accelerometer.x} {accelerometer.y} {accelerometer.z}</Text>
      <TouchableOpacity style={styles.stop} 
      onPress={() =>
        stopNow('accelerometer')
        }>
        <Text>STOP </Text>
        </TouchableOpacity>
      <TouchableOpacity style={styles.start} 
      onPress={() =>
        startNow('accelerometer', (data) => {
          setAccelerometer(data)
        })
        }>
        <Text>Start</Text>
        </TouchableOpacity>
    </View>
  )
}

Sample Demo App Could be found Here: https://github.com/Saboten758/allsenz

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

Package Sidebar

Install

npm i react-native-all-sensors

Weekly Downloads

1

Version

0.1.2

License

MIT

Unpacked Size

72.8 kB

Total Files

21

Last publish

Collaborators

  • rishavmukherjeee