react-native-sensor-ambient-light
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

react-native-sensor-ambient-light

React Native Module for android only to read ambient light sensors value

Installation

npm install react-native-sensor-ambient-light

Usage

import { DeviceEventEmitter, Platform } from 'react-native';
import {
  startUpdateLightSensor,
  stopUpdateLightSensor,
} from 'react-native-sensor-ambient-light';

// ...

useEffect(() => {
    if (Platform.OS === 'android') {
      startUpdateLightSensor();

      const subscription = DeviceEventEmitter.addListener(
        'AmbientLightSensor',
        (data: { lightValue: number; maxRange: number }) => {
          console.log('light', data.lightValue);
          console.log('maxRange', data.maxRange);
        },
      );

      return () => {
        stopUpdateLightSensor();
        subscription?.remove();
      };
    }
  }, []);

License

MIT


Made with create-react-native-library

Package Sidebar

Install

npm i react-native-sensor-ambient-light

Weekly Downloads

4

Version

0.1.2

License

MIT

Unpacked Size

28.3 kB

Total Files

28

Last publish

Collaborators

  • timok06